Advertisement
TeT91

ДЗ Бой с боссом

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