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

    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
    /// <summary>
    /// перобразуем DateTime? в DateTime, если не получается, то возвращаем текущую дату
    /// </summary>
    /// <param name="date"></param>
    /// <returns></returns>
    private DateTime DateTimeHelper(DateTime? date)
    {
        try
        {
            return (DateTime)date;
        }
        catch
        {
            return DateTime.Now;
        }
    }

    reemind, 03 Мая 2024

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

    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
    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
    string[] words = line.Split(' ');
    foreach (var word in words)
    {
        Console.Write(word);
        switch (word)
        {
            case "11":
                Console.WriteLine($"{tableEng[0, 0]}");
                break;
            case "12":
                Console.WriteLine($"{tableEng[0, 1]}");
                break;
            case "13":
                Console.WriteLine($"{tableEng[0, 2]}");
                break;
            case "14":
                Console.WriteLine($"{tableEng[0, 3]}");
                break;
            case "15":
                Console.WriteLine($"{tableEng[0, 4]}");
                break;
            case "21":
                Console.WriteLine($"{tableEng[1, 0]}");//
                break;
            case "22":
                Console.WriteLine($"{tableEng[1, 1]}");
                break;
            case "23":
                Console.WriteLine($"{tableEng[1, 2]}");
                break;
            case "24":
                Console.WriteLine($"{tableEng[1, 3]}");
                break;
            case "25":
                Console.WriteLine($"{tableEng[1, 4]}");
                break;
            case "31":
                Console.WriteLine($"{tableEng[2, 0]}");
                break;
            case "32":
                Console.WriteLine($"{tableEng[2, 1]}");
                break;
            case "33":
                Console.WriteLine($"{tableEng[2, 2]}");
                break;
            case "34":
                Console.WriteLine($"{tableEng[2, 3]}");
                break;
            case "35":
                Console.WriteLine($"{tableEng[2, 4]}");
                break;
            case "41":
                Console.WriteLine($"{tableEng[3, 0]}");
                break;
            case "42":
                Console.WriteLine($"{tableEng[3, 1]}");
                break;
            case "43":
                Console.WriteLine($"{tableEng[3, 2]}");
                break;
            case "44":
                Console.WriteLine($"{tableEng[3, 3]}");
                break;
            case "45":
                Console.WriteLine($"{tableEng[3, 4]}");
                break;
            case "51":
                Console.WriteLine($"{tableEng[4, 0]}");
                break;
            case "52":
                Console.WriteLine($"{tableEng[4, 1]}");
                break;
            case "53":
                Console.WriteLine($"{tableEng[4, 2]}");
                break;
            case "54":
                Console.WriteLine($"{tableEng[4, 3]}");
                break;
            case "55":
                Console.WriteLine($"{tableEng[4, 4]}");
                break;
        }
        
    }
    }
    Console.ReadLine();

    Дело IsBukva живёт.

    https://habr.com/ru/articles/771530/

    ISO, 03 Ноября 2023

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

    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
    public readonly struct Int64 : IComparable<long>, IConvertible, 
    IEquatable<long>, IParsable<long>, ISpanParsable<long>, 
    System.Numerics.IAdditionOperators<long,long,long>, 
    System.Numerics.IAdditiveIdentity<long,long>, 
    System.Numerics.IBinaryInteger<long>, System.Numerics.IBinaryNumber<long>, 
    System.Numerics.IBitwiseOperators<long,long,long>, 
    System.Numerics.IComparisonOperators<long,long,bool>, 
    System.Numerics.IDecrementOperators<long>, 
    System.Numerics.IDivisionOperators<long,long,long>, 
    System.Numerics.IEqualityOperators<long,long,bool>, 
    System.Numerics.IIncrementOperators<long>, 
    System.Numerics.IMinMaxValue<long>, 
    System.Numerics.IModulusOperators<long,long,long>, 
    System.Numerics.IMultiplicativeIdentity<long,long>, 
    System.Numerics.IMultiplyOperators<long,long,long>, 
    System.Numerics.INumber<long>, System.Numerics.INumberBase<long>, 
    System.Numerics.IShiftOperators<long,int,long>, 
    System.Numerics.ISignedNumber<long>, 
    System.Numerics.ISubtractionOperators<long,long,long>, 
    System.Numerics.IUnaryNegationOperators<long,long>, 
    System.Numerics.IUnaryPlusOperators<long,long>

    https://learn.microsoft.com/en-us/dotnet/api/system.int64?view=net-7.0

    ISO, 18 Сентября 2023

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

    0

    1. 1
    2. 2
    public ArgumentException (string? message, string? paramName);
    public ArgumentNullException (string? paramName, string? message);

    https://learn.microsoft.com/en-us/dotnet/api/system.argumentexception.-ctor?view=net-7.0#system-argumentexception-ctor(system-string-system-string)
    https://learn.microsoft.com/en-us/dotnet/api/system.argumentnullexception.-ctor?view=net-7.0#system-argumentnullexception-ctor(system-string-system-string)

    ISO, 15 Сентября 2023

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

    +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
    using System;
    using System.Linq;
    
    namespace TheBestGenerator
    {
       
        class Symbols
        {
            protected const string Letters = "abcdefghijklmnopqrstuvwxyz";
            protected const string Numbers = "0123456789";
            protected const string DefaultSpecialSymbols = @"!#$%&*@\";
            protected static Random rand = new Random();     
        }
        
        class Program
        {
            static void Main(string[] args)
            {
                while (true)
                {
                    Console.WriteLine("Введите длину пароля:");
                    int Len = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine(Generator.Password(Len));
                }
            }     
        }
       
        class Generator: Symbols
        {
           
            static char[] Array_()
            {
                return (Numbers+Letters+Letters.ToUpper()+DefaultSpecialSymbols).ToCharArray();
            }
    
             static char[] Password_Symbols()
            {
                return Array_().OrderBy(Symbol => rand.Next()).ToArray();
            }
    
            public static string Password(int Len )
            {
                char[] password = Password_Symbols();
                Array.Resize(ref password, Len);
                return (string.Join("", password));
            }
        }
    }

    Генератор паролей. Говнокод с наследованием. Почти ничего не понимаю в нем, но "прогу" с ним написал.

    utsutsbabyj, 22 Июля 2023

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

    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
    public class Archvile:Actor{public Archvile(){Health=700;Radius=20;Height=56;Mass=500;Speed=15;PainChance=10;Monster=true;MaxTargetRange=896;SetFlag(Flags.QUICKTORETALIATE,true);SetFlag(Flags.FLOORCLIP,true);SetFlag(Flags.NOTARGET,true);SeeSound="vile/sight";PainSound="vile/pain";DeathSound="vile/death";ActiveSound="vile/active";MeleeSound="vile/stop";Obituary="$OB_VILE";Tag="$FN_ARCH";}
    public override void BeginPlay(){base.BeginPlay();SetState("Spawn");}
    void Spawn(){SetState("See");}
    void See(){A_Chase();}
    void Missile(){A_VileStart();A_FaceTarget();A_VileTarget();A_FaceTarget();A_VileAttack();Delay(20);SetState("See");}
    void Heal(){Delay(10);SetState("See");}
    void Pain(){A_Pain();SetState("See");}
    void Death(){A_Scream();A_NoBlocking();Delay(7);SetState("Death   1");}
    void Death1(){Delay(7);SetState("Death   2");}
    void Death2(){Delay(7);SetState("Death   3");}
    void Death3(){Delay(7);SetState("Death   4");}
    void Death4(){Delay(7);SetState("Death   5");}
    void Death5(){Delay(7);SetState("Death   6");}
    void Death6(){Delay(7);SetState("Death   7");}
    void Death7(){Delay(1);Destroy();}
    void A_VileStart(){StartSound("vile/start",CHAN_VOICE);}
    void A_VileTarget(){if(target!=null){A_FaceTarget();Actor fog=Spawn<Actor>("ArchvileFire",target.Pos,SpawnFlags.ALLOW_REPLACE);if(fog!=null){tracer=fog;fog.target=self;fog.tracer=self.target;fog.A_Fire(0);}}}
    void A_VileAttack(){Actor targ=target;if(targ!=null){A_FaceTarget();if(!CheckSight(targ,0))return;StartSound("vile/stop",CHAN_WEAPON);int newdam=targ.DamageMobj(self,self,20,DamageType.none);if(newdam>0)targ.TraceBleed(newdam,self);Actor fire=tracer;if(fire!=null){fire.SetOrigin(targ.Vec3Angle(-24.0,angle,0),true);fire.A_Explode(70,70,ExplosionFlags.XF_NOSPLASH,false,0,0,0,"BulletPuff",DamageType.Fire);}
    if(!targ.bDontThrust){targ.Vel.z=1000.0*thrust/Math.Max(1,targ.Mass);}}}
    void A_StartFire(){StartSound("vile/firestrt",CHAN_BODY);A_Fire();}
    void A_Fire(){Actor dest=tracer;if(dest==null||target==null)return;if(!target.CheckSight(dest,0))return;SetOrigin(dest.Vec3Angle(24,dest.angle,0),true);}
    void A_FireCrackle(){StartSound("vile/firecrkl",CHAN_BODY);A_Fire();}}
    public static class ActorExtensions{public static void A_VileStart(this Actor self){self.StartSound("vile/start",CHAN_VOICE);}
    public static void A_VileTarget(this Actor self,string fire="ArchvileFire"){if(self.target!=null){self.A_FaceTarget();Actor fog=self.Spawn<Actor>(fire,self.target.Pos,SpawnFlags.ALLOW_REPLACE);if(fog!=null){self.tracer=fog;fog.target=self;fog.tracer=self.target;fog.A_Fire(0);}}}
    public static void A_VileAttack(this Actor self,string snd="vile/stop",int initialdmg=20,int blastdmg=70,int blastradius=70,double thrust=1.0,string damagetype="Fire",int flags=0){Actor targ=self.target;if(targ!=null){self.A_FaceTarget();if(!self.CheckSight(targ,0))return;self.StartSound(snd,CHAN_WEAPON);int newdam=targ.DamageMobj(self,self,initialdmg,(flags

    Арчвайл из ZDooM на C#

    DartPower, 07 Июня 2023

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

    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
    protected override Detail GetDetailPage(
                aggregate aggregate, 
                int cashbackRate,
                BannerResponse bannerInfo,
                List<MediaShortResponse> mediaInfo,
                EntityFavourites likeCountInfo, 
                List<FavouriteEntity> likeInfo)
            {
                var announcementDetail = new Detail
                (
                    aggregate.Details.Id,
                    aggregate.Details.Alias,
                    aggregate.Details.Title,
                    aggregate.Details.Description,
                    aggregate.Details.DescriptionShortcut,
                    aggregate.Details.Age,
                    aggregate.ExtendedDetails.DataSourceId,
                    aggregate.ExtendedDetails.DataSourceItemId,
                    cashbackRate,
                    null,
                    aggregate.ExtendedDetails.LastEventDateTime,
                    aggregate.ExtendedDetails.EventClosestDateTime,
                    aggregate.ExtendedDetails.Url,
                    aggregate.ExtendedDetails.Category != null
                        ? new AnnouncementCategory(aggregate.ExtendedDetails.Category.Id, 
                            aggregate.ExtendedDetails.Category.Title,
                            aggregate.ExtendedDetails.Category.Url)
                        : null,
                    aggregate.ExtendedDetails.Tags?.Select(ss =>
                        new Tag(ss.Title, HttpUtility.UrlPathEncode(ss.Url))
                    ).ToList(),
                    aggregate.Details.Privileges?.Select(ss => new Privilege()
                    {
                        Description = ss.Description,
                        Id = ss.Id,
                        ImageUrl = ss.ImageUrl.ToString(),
                        Title = ss.Title
                    }).ToList(),
                    mediaInfo.Select(m => new Media
                    {
                        Type = m.Type,
                        Url = m.Url
                    }).ToList(),
                    aggregate.ExtendedDetails.EventMinPrice,
                    likeInfo.FirstOrDefault(x => x.EntityId == aggregate.Details.Id)?.IsSet ?? false,
                    likeCountInfo?.TotalCount,
                    aggregate.ExtendedDetails.Promotext,
                    bannerInfo != null ? new Banner { Url = bannerInfo.Url, ImageUrl = bannerInfo.ImageUrl } : null,
                    aggregate.Details.Venue != null
                        ? new ShortVenue(aggregate.Details.Venue.Id,
                            aggregate.Details.Venue.Title,
                            aggregate.Details.Venue.Url.Replace(_liveBaseAddress, ""),
                            aggregate.Details.Venue.Address)
                        : null,
                    (AnnouncementStatus)aggregate.Details.Status,
                    aggregate.ExtendedDetails.PremiumRule,
                    aggregate.Details.HasPrivilegeEnabled,
                );
    
                return announcementDetail;
     }

    tfnbupsc, 24 Марта 2023

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

    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
    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
    class StargateSimulator
    {
        static bool shieldEnabled = false;
    
        static void Main()
        {
            Console.WriteLine("Stargate Simulator");
            Console.WriteLine("------------------");
    
            // Check for zero point module
            Console.Write("Zero Point Module detected. Proceed with simulation? (y/n) ");
            string response = Console.ReadLine();
            if (response.ToLower() != "y")
            {
                Console.WriteLine("Simulation cancelled.");
                return;
            }
    
            // Enable shield
            Console.Write("Enable gate shield? (y/n) ");
            response = Console.ReadLine();
            if (response.ToLower() == "y")
            {
                EnableShield();
            }
    
            // Enter gate address
            Console.Write("Enter gate address: ");
            string address = Console.ReadLine();
            if (address.Length != 6 && address.Length != 8)
            {
                Console.WriteLine("Invalid address length.");
                return;
            }
    
            // Dial gate
            Dial(address);
    
            Console.WriteLine("Simulation complete.");
        }
    
        static void Dial(string address)
        {
            // Check for valid address
            if (address.Length != 6 && address.Length != 8)
            {
                Console.WriteLine("Invalid address length.");
                return;
            }
    
            // Check for energy source
            Console.Write("Energy source detected. Proceed with dialing? (y/n) ");
            string response = Console.ReadLine();
            if (response.ToLower() != "y")
            {
                Console.WriteLine("Dialing cancelled.");
                return;
            }
    
            // Dial gate
            Console.WriteLine("Dialing gate...");
            if (shieldEnabled)
            {
                Console.WriteLine("Gate shield is active.");
            }
            Console.WriteLine("Chevron 1 encoded.");
            Console.WriteLine("Chevron 2 encoded.");
            Console.WriteLine("Chevron 3 encoded.");
            Console.WriteLine("Chevron 4 encoded.");
            Console.WriteLine("Chevron 5 encoded.");
            Console.WriteLine("Chevron 6 encoded.");
            if (address.Length == 8)
            {
                Console.WriteLine("Chevron 7 encoded.");
                Console.WriteLine("Gate engaged.");
            }
            else
            {
                Console.WriteLine("Gate engaged.");
            }
        }
    
        static void EnableShield()
        {
            // Check for available power
            Console.Write("Power levels stable. Activate gate shield? (y/n) ");
            string response = Console.ReadLine();
            if (response.ToLower() != "y")
            {
                Console.WriteLine("Shield activation cancelled.");
                return;
            }
    
            // Activate shield
            Console.WriteLine("Shield activated.");
            shieldEnabled = true;
        }
    }

    Симулятор наборного устройства звездных врат.

    P.S. За Канон-френдли не отвечаю, т.к. фанат серии но любитель немножко поизвращаться над ЛОРом...

    DartPower, 19 Марта 2023

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

    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
    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
    namespace TimeMachineSimulator
    {
        class Program
        {
            static void Main()
            {
                Console.WriteLine("Welcome to the Time Machine Simulator!");
                TimeMachine machine = new();
                while (true)
                {
                    Console.WriteLine("What would you like to do?");
                    Console.WriteLine("1. Travel in time");
                    Console.WriteLine("2. Show current time");
                    Console.WriteLine("3. Show travel history");
                    Console.WriteLine("4. Exit");
                    string input = Console.ReadLine();
                    Console.WriteLine();
                    switch (input)
                    {
                        case "1":
                            Console.Write("Enter the number of years to travel: ");
                            int years = int.Parse(Console.ReadLine());
                            try
                            {
                                machine.Travel(years);
                                Console.WriteLine("Travel successful.");
                            }
                            catch (TimeMachineException e)
                            {
                                Console.WriteLine(e.Message);
                            }
                            break;
                        case "2":
                            Console.WriteLine("Current time: " + machine.GetCurrentTime());
                            break;
                        case "3":
                            List<DateTime> history = machine.GetTravelHistory();
                            Console.WriteLine("Travel history:");
                            foreach (DateTime time in history)
                            {
                                Console.WriteLine(time);
                            }
                            Console.WriteLine();
                            break;
                        case "4":
                            Console.WriteLine("Thank you for using the Time Machine Simulator! Press any key to exit...");
                            Console.ReadKey();
                            return;
                        default:
                            Console.WriteLine("Invalid input. Please try again.");
                            break;
                    }
                }
            }
        }
    
        public class TimeMachineException : Exception { public TimeMachineException(string message) : base(message){}}
    
        public class TimeMachine
        {
            private DateTime currentTime;
            private readonly List<DateTime> travelHistory;
            public TimeMachine()
            {
                this.currentTime = DateTime.Now;
                this.travelHistory = new List<DateTime>();
            }
            public void Travel(int years)
            {
                DateTime futureTime = this.currentTime.AddYears(years);
                if (futureTime > DateTime.Now)
                {
                    throw new TimeMachineException("Cannot travel to the future!");
                }
                this.currentTime = futureTime;
                this.travelHistory.Add(futureTime);
            }
            public DateTime GetCurrentTime()
            {
                return this.currentTime;
            }
            public List<DateTime> GetTravelHistory()
            {
                return this.travelHistory;
            }
        }
    }

    Пространственно-временной квантовый реинтегратор. Правда в будущее не умеет отправлять, но используя свойства реверсивной энтропии может отправить куда угодно только в прошлое!

    DartPower, 19 Марта 2023

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

    0

    1. 1
    namespace NardeGame { public class NardeGame { static void Main() { Console.WriteLine("Welcome to Narde Game!"); NardeGame game = new(); game.Play(); Console.WriteLine("Thank you for playing Narde Game! Press any key to exit..."); Console.ReadKey(); } private readonly Player player1; private readonly Player player2; private readonly Board board; public NardeGame() { player1 = new Player("Armen"); player2 = new Player("Suren"); board = new Board(); } public void Play() { while (!board.IsGameOver()) { Player currentPlayer = board.GetTurn() == Turn.WHITE ? player1 : player2; Console.WriteLine("It's " + currentPlayer.GetName() + "'s turn."); Console.WriteLine(board); int from, to; do { Console.Write("Enter the starting point of your move: "); from = int.Parse(Console.ReadLine()); Console.Write("Enter the ending point of your move: "); to = int.Parse(Console.ReadLine()); } while (!Board.IsValidMove(from, to, currentPlayer.GetColor())); Board.MakeMove(from, to); board.NextTurn(); } Console.WriteLine("Game over."); Console.WriteLine(board); Console.WriteLine(board.GetWinner().GetName() + " won!"); } } public enum Color { WHITE, BLACK } public enum Turn { WHITE, BLACK } public class Player { private readonly string name; private readonly Color color; public Player(string name) { this.name = name; color = name == "Armen" ? Color.WHITE : Color.BLACK; } public string GetName() { return name; } public Color GetColor() { return color; } } public class Board { private readonly int[] points; private Turn turn; public Board() { points = new int[24] { 2, 0, 0, 0, 0, -5, 0, 3, 0, 0, 0, -5, 5, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, -2 }; turn = Turn.WHITE; } public bool IsGameOver() { int whiteCount = 0; int blackCount = 0; for (int i = 0; i < 24; i++) { if (points[i] > 0) { whiteCount += points[i]; } else if (points[i] < 0) { blackCount -= points[i]; } } return whiteCount == 0 || blackCount == 0; } public Player? GetWinner() { int whiteCount = 0; int blackCount = 0; for (int i = 0; i < 24; i++) { if (points[i] > 0) { whiteCount += points[i]; } else if (points[i] < 0) { blackCount -= points[i]; } } if (whiteCount > blackCount) { return new Player("Armen"); } else if (blackCount > whiteCount) { return new Player("Suren"); } else { return null; } } public Turn GetTurn() { return turn; } public void NextTurn() { turn = turn == Turn.WHITE ? Turn.BLACK : Turn.WHITE; } public static bool IsValidMove(int from, int to, Color color) { return true; } public static void MakeMove(int from, int to) { } public override string ToString() { string output = ""; for (int i = 0; i < 24; i++) { output += points[i] + " "; } return output.TrimEnd(); } } }

    Армяне играют в однострочные нарды... :)

    DartPower, 19 Марта 2023

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