Advertisement
lovelyvook

Unit_17

Mar 31st, 2024 (edited)
1,000
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.53 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Ijunior
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             const string CommandSimpleAttack = "1";
  10.             const string CommandFireBall = "2";
  11.             const string CommandExplosion = "3";
  12.             const string CommandTreatment = "4";
  13.  
  14.             int bossHealth = 150;
  15.             Random random = new Random();
  16.             int minRandomNumber = 10;
  17.             int maxRandomNumber = 21;
  18.             int userDefaultHealth = 100;
  19.             int userDefaultMana = 20;
  20.             int userCurrentHealth = 100;
  21.             int userCurrentMana = 20;
  22.             int userSimpleAttack = 12;
  23.             int userFireBallAttack = 20;
  24.             int userExplosionAttack = 40;
  25.             int costOfFireBall = 10;
  26.             int increaseHealth = 20;
  27.             int increaseMana = 5;
  28.             int numberOfExplosion = 0;
  29.             int numberOfTreatment = 5;
  30.             bool isWork = true;
  31.             string userInput;
  32.  
  33.             Console.WriteLine($"Здоровье босса {bossHealth} | Здоровье игрока {userDefaultHealth} | Мана игрока {userDefaultMana}\n");
  34.  
  35.             while (isWork)
  36.             {
  37.                 Console.WriteLine($"{CommandSimpleAttack} - простая атака" +
  38.                     $"\n{CommandFireBall} - огненный шар (тратит {costOfFireBall} маны)" +
  39.                     $"\n{CommandExplosion} - взрыв (доступно {numberOfExplosion})" +
  40.                     $"\n{CommandTreatment} - лечение (доступно {numberOfTreatment})");
  41.                 Console.Write("Введите номер действия: ");
  42.                 userInput = Console.ReadLine();
  43.                 Console.WriteLine();
  44.  
  45.                 switch (userInput)
  46.                 {
  47.                     case CommandSimpleAttack:
  48.                         bossHealth -= userSimpleAttack;
  49.                         Console.WriteLine("Игрок атакует на " + userSimpleAttack);
  50.                         break;
  51.  
  52.                     case CommandFireBall:
  53.                         bossHealth -= userFireBallAttack;
  54.  
  55.                         if (userCurrentMana - costOfFireBall >= 0)
  56.                         {
  57.                             userCurrentMana -= costOfFireBall;
  58.                             numberOfExplosion = 1;
  59.                             Console.WriteLine("Игрок атакует на " + userFireBallAttack);
  60.                         }
  61.                         else
  62.                         {
  63.                             Console.WriteLine("Недостаточно маны");
  64.                         }
  65.  
  66.                         break;
  67.  
  68.                     case CommandExplosion:
  69.                         if (numberOfExplosion > 0)
  70.                         {
  71.                             bossHealth -= userExplosionAttack;
  72.                             Console.WriteLine("Игрок атакует на " + userExplosionAttack);
  73.                             numberOfExplosion = 0;
  74.                         }
  75.                         else
  76.                         {
  77.                             Console.WriteLine("Перед взрывом нужно использовать огненный шар");
  78.                         }
  79.                         break;
  80.  
  81.                     case CommandTreatment:
  82.                         if (numberOfTreatment > 0)
  83.                         {
  84.                             userCurrentHealth += increaseHealth;
  85.  
  86.                             if (userCurrentHealth > userDefaultHealth)
  87.                             {
  88.                                 userCurrentHealth = userDefaultHealth;
  89.                             }
  90.  
  91.                             userCurrentMana += increaseMana;
  92.  
  93.                             if (userCurrentMana > userDefaultMana)
  94.                             {
  95.                                 userCurrentMana = userDefaultMana;
  96.                             }
  97.  
  98.                             Console.WriteLine($"Здоровье восстановлено до {userCurrentHealth} | Мана восстановлена до {userCurrentMana}");
  99.                             numberOfTreatment--;
  100.                         }
  101.                         else
  102.                         {
  103.                             Console.WriteLine("Аптечек больше нет");
  104.                         }
  105.                         break;
  106.  
  107.                     default:
  108.                         Console.WriteLine("Промах игрока");
  109.                         break;
  110.                 }
  111.  
  112.                 int bossAttack = random.Next(minRandomNumber, maxRandomNumber);
  113.                 userCurrentHealth -= bossAttack;
  114.                 Console.WriteLine("Босс атакует на " + bossAttack);
  115.                 Console.WriteLine($"\nЗдоровье босса {bossHealth} | Здоровье игрока {userCurrentHealth} | Мана игрока {userCurrentMana}\n");
  116.  
  117.                 if (bossHealth < 0 || userCurrentHealth < 0)
  118.                 {
  119.                     isWork = false;
  120.                 }
  121.             }
  122.  
  123.             if (bossHealth < 0 && userCurrentHealth < 0)
  124.             {
  125.                 Console.WriteLine("Ничья");                
  126.             }
  127.             else if (bossHealth < 0)
  128.             {
  129.                 Console.WriteLine("Победа игрока");
  130.             }
  131.             else if (userCurrentHealth < 0)
  132.             {
  133.                 Console.WriteLine("Победа босса");
  134.             }
  135.         }
  136.     }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement