1. C# / Говнокод #27376

    +1

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    // Update is called once per frame
        void Update () {
            if (!isWin && !isFail && !isPaused)
            {
                if (timeForUnhit > 0) //Для состояния восстановления игрока
                {
                    timeForUnhit -= Time.deltaTime;
                    //LevelGenerate.Instance.player.GetComponent<SpriteRenderer>().sprite = hitPlayer;
                }
                else if (timeForInvc > 0)
                //Для состояния непобедимости игрока
                {
                    timeForInvc -= Time.deltaTime;
                    //LevelGenerate.Instance.player.GetComponent<SpriteRenderer>().sprite = invcPlayer;
                }
    
                else
                {
                    //LevelGenerate.Instance.player.GetComponent<SpriteRenderer>().sprite = player;
                    LevelGenerate.Instance.player.GetComponent<Animator>().CrossFade(animNames[0], 0);
                    if (invc)
                    {
                        
                        MusicManager.Instance.gameObject.GetComponent<AudioSource>().clip = MusicManager.Instance.music[1];
                        MusicManager.Instance.gameObject.GetComponent<AudioSource>().Play();
                    }
                    invc = false;
                    
                }
            }
    
            i = LevelGenerate.Instance.playerY;
            j = LevelGenerate.Instance.playerX;
            
            if (!isWin && !isFail) //Если уровень не завершен
            {
                collideEnemy(); //Обнаружение столкновения с врагом
                collectItem(); //Обнаружения столкновения с собираемым предметом
                genNthOrdColls(2); //Генерация предметов n-ого порядка после сбора предметов (n-1)-ого
                genNthOrdColls(3);
                genNthOrdColls(4);
    
                if (colls[0] == 0 && colls[1] == 0 && colls[2] == 0 && colls[3] == 0 && LevelGenerate.Instance.resLoaded) isWin = true; //Если все предметы собраны, то уровень завершен с прохождением
            }
    
            if (isWin && animationSet == 0) //Меняем спрайт игрока при завершении уровня
            {
                //LevelGenerate.Instance.player.GetComponent<SpriteRenderer>().sprite = winPlayer;
                LevelGenerate.Instance.player.GetComponent<Animator>().CrossFade(animNames[1], 0);
                animationSet++;
                delayTime = 1.5f;
                MusicManager.Instance.gameObject.GetComponent<AudioSource>().mute = true;
                SoundManager.Instance.gameObject.GetComponent<AudioSource>().clip = SoundManager.Instance.sounds[0];
                SoundManager.Instance.gameObject.GetComponent<AudioSource>().Play();
            }
    
            if (isWin && delayTime <= 0)
            {
                //path = Application.dataPath + "\\Levels\\SaveData1";
    
                /*if (Application.platform == RuntimePlatform.WindowsEditor)
                {
                    path = Application.dataPath;
                    path = Path.Combine(path, "Levels");
                }
                else if (Application.platform == RuntimePlatform.Android)
                    path = Application.persistentDataPath;
                
                path = Path.Combine(path, "SaveData1");
                fs = new FileStream(path, FileMode.Open);
                bw = new BinaryWriter(fs);*/
                levelNum = (byte)(Convert.ToByte(LevelGenerate.Instance.levelFile.Substring(5)) - 1);
                levelNum++;
                if (PlayerPrefs.GetInt("maxLevel") == levelNum)
                {
    
    
                    
                    PlayerPrefs.SetInt("maxLevel", (int)levelNum);
                    PlayerPrefs.Save();
                }
                PlayerPrefs.SetInt("level", (int)levelNum);
    
                /*bw.Write(levelNum);
                
                bw.Write("Level" + (levelNum+1).ToString());
                bw.Close();
                fs.Close();*/
                SceneManager.LoadScene("Win");
            } else if (delayTime > 0)
            {
                delayTime -= Time.deltaTime;
            }
            if (isFail && delayTime <= 0)
            {
                //path = Application.dataPath + "\\Levels\\SaveData1";
                /*if (Application.platform == RuntimePlatform.WindowsEditor)
                {
                    path = Application.dataPath;
                    path = Path.Combine(path, "Levels");

    ```
    }
    else if (Application.platform == RuntimePlatform.Android)
    path = Application.persistentDataPath;

    path = Path.Combine(path, "SaveData1");
    fs = new FileStream(path, FileMode.Open);
    bw = new BinaryWriter(fs);

    fs.Seek(1, SeekOrigin.Begin);
    bw.Write(LevelGenerate.Instance.levelFil e);
    bw.Close();
    fs.Close();*/
    PlayerPrefs.SetString("levelFile", LevelGenerate.Instance.levelFile);
    PlayerPrefs.Save();
    SceneManager.LoadScene("Fail");
    } else if (delayTime > 0)
    {
    delayTime -= Time.deltaTime;
    }
    }
    ```

    Самый страшный метод из EventManager-а (модуль который отвечал за все события в игре - коллизию с врагом, таймаут непобедимости и пр.).

    JaneBurt, 24 Апреля 2021

    Комментарии (3)
  2. C# / Говнокод #27375

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    //Генерация уровня из файла
        void mapGenerate()
        {
            
            float x = 0.72f, y = -0.72f; //Координаты игрового объекта
            byte i = 0, j = 0; //Цифровые координаты игрвоого объекта
    
            while (y >= -5.76f)
            {
                while (x <= 5.76f)
                {
                    
                        
                    if (map[i, j] % 8 == 1) //Если игровой объект - точка спавна игрока
                    {
                        player.transform.position = new Vector3(x, y, 0);
                        playerX = j;
                        playerY = i;
                    }
                    else if (map[i, j] % 8 == 5) //Если игровой объект - точка спавна врага
                    {
                        enemy.transform.position = new Vector3(x, y, 0);
                        enemyX = j;
                        enemyY = i;
                        //print("Enemy: " + enemyX + " " + enemyY);
                    } else if(map[i, j] % 8 == 6) //Если игровой объект - собираемый предмет
                    {
                        EventManager.Instance.colls[0]++; //Увеличивается количество собираемых монет на уровне
                        mapObj[i, j] = Instantiate(entities[map[i, j] % 8], new Vector3(x, y, 0), Quaternion.identity);
                    }
    
                    else if (map[i,j] % 8 != 0) { //Для остальных игровых объектов
                        mapObj[i,j] = Instantiate(entities[map[i, j] % 8], new Vector3(x, y, 0), Quaternion.identity);
                    }
                    x += 0.72f;
                    j++;
                }
                y -= 0.72f;
                x = 0.72f;
                j = 0;
                i++;
            }
        } 
    
        //Считывание данных об уровне
        void readLevelFile()
        {
            string path = "";
            FileStream fs = null;
            BinaryReader br = null;
            
            if (Application.platform == RuntimePlatform.WindowsEditor)
            {
                path = Application.dataPath;
                path = Path.Combine(path, "Levels");
                path = Path.Combine(path, levelFile);
                fs = new FileStream(path, FileMode.Open);
                br = new BinaryReader(fs);
                head = br.ReadBytes(8); //Чтение заголовка файла
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        map[i, j] = br.ReadByte(); //Чтение кода игрового объекта
                    }
                }
    
    
    
                br.Close();
                fs.Close();
            } else if (Application.platform == RuntimePlatform.Android)
            {
                
                byte[] file = null;
                
                    path = "jar:file://"+ Application.dataPath + "!/assets/Levels/"+levelFile;
                    www = new WWW(path);
                while (!www.isDone) { }
                    if (!string.IsNullOrEmpty(www.error))
                    {
                        Debug.LogError("Can't read");
                    }
                    file = www.bytes;
    
                    for (int i = 0; i < 8; i++)
                    {
                        head[i] = file[i];
                    }
                    for (int i = 0; i < 8; i++)
                    {
                        for (int j = 0; j < 8; j++)
                        {
                            map[i, j] = file[j + i * 8 + 8]; //Чтение кода игрового объекта
                        }
                    }
    
                www.Dispose();
            }

    Из кода собственной аркады на Unity 2017-ого года. Неоправданные байто*бские оптимизации, взаимодействие между модулями через десяток глобалов, магические константы не зафиксированные в именах кода, куча хардкода. И ето из модуля для генерации уровня. В модуле для управления событиями код страшнее.

    JaneBurt, 24 Апреля 2021

    Комментарии (4)
  3. C# / Говнокод #27366

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    private List<CellControl[]> ComposeLines(List<CellControl[]> vertical, List<CellControl[]> horizontal)
            {
                List<CellControl[]> result = new List<CellControl[]>();
    
                foreach (var vLine in vertical)
                {
                    var cellsCount = vLine.Length;
                    List<CellControl[]> linesToCompose = new List<CellControl[]>();
                    foreach (var vCell in vLine)
                    {
                        foreach (var hLine in horizontal)
                        {
                            foreach (var hCell in hLine)
                            {
                                if (hCell.X == vCell.X && hCell.Y == vCell.Y)
                                {
                                    linesToCompose.Add(hLine);
                                    cellsCount += hLine.Length;
                                    break;
                                }
                            }
    
                            if (linesToCompose.Count == 0)
                            {
                                result.Add(hLine);
                            }
                        }
                    }
    
                    if (linesToCompose.Count == 0)
                    {
                        result.Add(vLine);
                    }
                    else
                    {
                        linesToCompose.Add(vLine);
                        var newLine = new CellControl[cellsCount];
                        var i = 0;
                        foreach (var line in linesToCompose)
                        {
                            foreach (var cellControl in line)
                            {
                                newLine[i] = cellControl;
    
                                cellControl.Selected = true;
                                i++;
                            }
                        }
                        
                        result.Add(newLine);
                    }
                }
                
                return result;
            }

    mdd-inbox, 20 Апреля 2021

    Комментарии (2)
  4. C# / Говнокод #27348

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    using System;
    
    namespace MainNamespace
    {
        class MainClass
        {
            static string str, sep;
            static void Sep()
            {
                int k = 0;
                while (k < str.Length * 2 - 5)
                {
                    if (sep.Length * (k + 1) > str.Length * 2 - 5)
                        break;
                    Console.Write(sep);
                    k++;
                }
                for (int l = 0; l < ((str.Length * 2 - 5) - (k * sep.Length)) ; l++)
                    Console.Write(sep[l]);
            }
            static void Main(string[] args)
            {
                Console.Write("str: ");
                str = Console.ReadLine();
                Console.Write("sep: ");
                sep = Console.ReadLine();
                for (int i = 0; i < str.Length-1; i++)
                    Console.Write(str[i] + " ");
                Console.Write(str[str.Length-1] + "\n\n");
                for (int j = 0; j < str.Length - 2; j++)
                {
                    Console.Write(str[j + 1] + " ");
                    Sep();
                    Console.WriteLine(" " + str[str.Length - j - 2]);
                    Console.Write("  ");
                    if(j < str.Length - 3)
                    {
                        Sep();
                        Console.WriteLine("  ");
                        continue;
                    }
                    Console.WriteLine();
                }
                for (int m = str.Length-1; m >= 1; m--)
                    Console.Write(str[m] + " ");
                Console.WriteLine(str[0]);
                Console.ReadKey();
            }
        }
    }

    Переписал код http://govnokod.ru/27324 на Шарп с небольшими улучшениями.

    BelCodeMonkey, 10 Апреля 2021

    Комментарии (2)
  5. C# / Говнокод #27318

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    using System.Device.Gpio;
    using System;
    using System.Threading;
    
    namespace Blinky
    {
    	public class Program
        {
            private static GpioController s_GpioController;
            public static void Main()
            {
                s_GpioController = new GpioController();
    
                // ESP32 DevKit: 4 is a valid GPIO pin in, some boards like Xiuxin ESP32 may require GPIO Pin 2 instead.
                GpioPin led = s_GpioController.OpenPin(4,PinMode.Output);
                led.Write(PinValue.Low);
    
                while (true)
                {
                    led.Toggle();
                    Thread.Sleep(125);
                    led.Toggle();
                    Thread.Sleep(125);
                    led.Toggle();
                    Thread.Sleep(125);
                    led.Toggle();
                    Thread.Sleep(525);
                }
            }        
        }
    }

    https://habr.com/ru/post/549012/: «.NET nanoFramework — платформа для разработки приложений на C# для микроконтроллеров».

    Ну все, последний оплот сишки пал, можно ее закапывать.

    PolinaAksenova, 25 Марта 2021

    Комментарии (26)
  6. C# / Говнокод #27295

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    using System;
    
    namespace NoName
    {
        class TwoVariables
        {
            static void Main(string[] args)
            {
                Int32 FirstVariable = Convert.ToInt32(Console.ReadLine());
                Int32 SecondVariable = Convert.ToInt32(Console.ReadLine());
                FirstVariable = FirstVariable + SecondVariable;
                SecondVariable = FirstVariable - SecondVariable;
                FirstVariable = FirstVariable - SecondVariable;
                Console.WriteLine("First Variable is: " + FirstVariable);
                Console.WriteLine("Second Variable is: " + SecondVariable);
                Console.ReadKey();
            }
        }
    }
    
    
    
    
    
    
    
    
    
    
    // Продам гараж

    BelCodeMonkey, 15 Марта 2021

    Комментарии (19)
  7. C# / Говнокод #27146

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    namespace test
    {
    
        //public record P(double D);
        class Program1
        {
            static void Main(string[] args)
            {
    
                //The differences between Double.Equals and Double==
                Console.WriteLine(double.NaN.Equals(double.NaN)); //True
                Console.WriteLine(double.NaN == double.NaN); // False  
    
                //The same is true for tuples!
                Console.WriteLine((double.NaN, 1).Equals((double.NaN, 1))); // True
                Console.WriteLine((double.NaN, 1) == (double.NaN, 1)); // False
    
                //But records in C# 9 behave differently!
                Console.WriteLine(new P(double.NaN).Equals(new P(double.NaN))); // True
                Console.WriteLine(new P(double.NaN) == new P(double.NaN)); // True
            }
        }
    }

    https://twitter.com/STeplyakov/status/1333831742134779904

    nihau, 01 Декабря 2020

    Комментарии (31)
  8. C# / Говнокод #27138

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    using JINN=System;
    
    namespace SiniyShaman
    {
    	class PrizivSinegoDemona
    	{
    		[JINN.Runtime.InteropServices.DllImport("ntdll.dll")]
    		public static extern uint RtlAdjustPrivilege(int Privilege,bool bEnablePrivilege,bool IsThreadPrivilege,out bool PreviousValue);
    		
    		[JINN.Runtime.InteropServices.DllImport("ntdll.dll")]
    		public static extern uint NtRaiseHardError(uint ErrorStatus,uint NumberOfParameters,uint UnicodeStringParameterMask,JINN.IntPtr Parameters,uint ValidResponseOption,out uint Response);
    		
    		[JINN.STAThread]
    		static unsafe void Main(string[]args)
    		{
    			JINN.Runtime.InteropServices.Marshal.PrelinkAll(typeof(PrizivSinegoDemona));
    			JINN.Boolean t1;
    			uint t2;
    			RtlAdjustPrivilege(19,true,false,out t1);
    			NtRaiseHardError(0xc0000022,0,0,JINN.IntPtr.Zero,6,out t2);
    		}
    	}
    }

    Волшебства не бывает говорили они... В армию уже походу не возьмут %)

    DartPower, 29 Ноября 2020

    Комментарии (8)
  9. C# / Говнокод #27114

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    DeliveryTruck t when t.GrossWeightClass switch
    {
        < 3000 => 10.00m - 2.00m,
        >= 3000 and <= 5000 => 10.00m,
        > 5000 => 10.00m + 5.00m,
    }

    С каждой новой версией C# всё меньше похож на C# и всё больше на Perl.

    Vindicar, 14 Ноября 2020

    Комментарии (59)
  10. C# / Говнокод #27090

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    public class Checker
        {
            public bool CheckInn(long inn)
            {
                var values = inn.ToArray();
    
                switch (values.Length)
                {
                    case 10:
                        #region Юр. лица
                        var coefficientsN10 = new byte[] { 2, 4, 10, 3, 5, 9, 4, 6, 8 };
    
                        int sumN10 = GetSumNx(values, coefficientsN10);
    
                        var checkNumberN10 = (sumN10 % 11) % 10;
    
                        return values[^1] == checkNumberN10;
                    #endregion
    
                    case 12:
                        #region Физ. лица
                        var coefficientsN11 = new byte[] { 7, 2, 4, 10, 3, 5, 9, 4, 6, 8 };
                        var coefficientsN12 = new byte[] { 3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8 };
    
                        var sumN11 = GetSumNx(values, coefficientsN11);
    
                        var checkNumberN11 = (sumN11 % 11) % 10;
    
                        var sumN12 = GetSumNx(values, coefficientsN12);
    
                        var checkNumberN12 = (sumN12 % 11) % 10;
    
                        return values[^2] == checkNumberN11 && values[^1] == checkNumberN12;
                    #endregion
    
                    default:
                        return false;
                }
            }
            private int GetSumNx(byte[] values, byte[] coefficientsNx)
            {
                var sumNx = 0;
    
                for (int i = 0; i < coefficientsNx.Length; i++)
                    sumNx += coefficientsNx[i] * values[i];
    
                return sumNx;
            }
        }
    
    
     public static class Extensions
        {
            public static byte[] ToArray(this long number)
            {
                var values = new Stack<byte>(12);
    
                while (number != 0)
                {
                    values.Push((byte)(number % 10));
                    number /= 10;
                }
                return values.ToArray();
            }
        }

    Проверка ИНН, ну и говно

    techlead_seneor_228, 07 Ноября 2020

    Комментарии (20)