Advertisement
Rodunskiy

Untitled

Apr 18th, 2023
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.86 KB | None | 0 0
  1. const string SwordStrikeCommand = "1";
  2. const string CrossbowShotCommand = "2";
  3. const string SwordStrikeFromShadowsCommand = "3";
  4. const string HideInShadowsAndHealthingCommand = "4";
  5.  
  6. Random random = new Random();
  7.  
  8. int heroLife = 400;
  9. int bossLife = 1000;
  10. int bossAttackMin = 50;
  11. int bossAttackMax = 200;
  12. bool isWorkingHideInShadows = false;
  13. string typeAttack;
  14.  
  15. while (heroLife > 0 && bossLife > 0)
  16. {
  17.     Console.WriteLine($"Жизни героя:{heroLife}\nЖизни босса:{bossLife}\nВыберите действие:\n{SwordStrikeCommand} <-- удар мечем.\n{CrossbowShotCommand} <-- выстрел из арбалета." +
  18.         $"\n{SwordStrikeFromShadowsCommand} <-- удар мечем из тени.\n{HideInShadowsAndHealthingCommand} <-- спрятаться в тени.");
  19.     typeAttack = Console.ReadLine();
  20.  
  21.     switch (typeAttack)
  22.     {
  23.         case SwordStrikeCommand:
  24.             int swordStrike = 100;
  25.  
  26.             Console.WriteLine($"Удар мечем!");
  27.             bossLife -= swordStrike;
  28.             heroLife -= random.Next(bossAttackMin, bossAttackMax);
  29.             Console.Clear();
  30.             break;
  31.  
  32.         case CrossbowShotCommand:
  33.             int crossbowShotAttackMin = 50;
  34.             int crossbowShotAttackMax = 150;
  35.  
  36.             Console.WriteLine($"Выстрел из арбалета!");
  37.             bossLife -= random.Next(crossbowShotAttackMin,crossbowShotAttackMax);
  38.             heroLife -= random.Next(bossAttackMin, bossAttackMax);
  39.             Console.Clear();
  40.             break;
  41.  
  42.         case SwordStrikeFromShadowsCommand:
  43.             int swordStrikeFromShadows = 300;
  44.  
  45.             if (isWorkingHideInShadows == true)
  46.             {
  47.                 Console.WriteLine($"Удар мечем из тени!");
  48.                 bossLife -= swordStrikeFromShadows;
  49.                 heroLife -= random.Next(bossAttackMin, bossAttackMax);
  50.                 isWorkingHideInShadows = false;
  51.                 Console.Clear();
  52.             }
  53.             else
  54.             {
  55.                 Console.WriteLine($"Атака не сработала!");
  56.                 heroLife -= random.Next(bossAttackMin, bossAttackMax);
  57.                 Console.Clear();
  58.             }
  59.             break;
  60.  
  61.         case HideInShadowsAndHealthingCommand:
  62.             int hideInShadowsAndHealthing = 100;
  63.  
  64.             Console.WriteLine($"Герой спрятался в тени и восстановил 100 жизней!");
  65.             heroLife += hideInShadowsAndHealthing;
  66.             isWorkingHideInShadows = true;
  67.             Console.Clear();
  68.             break;
  69.     }
  70. }
  71.  
  72. if (bossLife <= 0 && heroLife <= 0)
  73. {
  74.     Console.WriteLine("Ничья!");
  75. }
  76. else if (bossLife > 0)
  77. {
  78.     Console.WriteLine("Босс побеждает!");
  79. }
  80. else if (heroLife > 0)
  81. {
  82.     Console.WriteLine("Герой побеждает!");
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement