Advertisement
TwinFrame

Clight_19_BossFight

Mar 27th, 2023 (edited)
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.75 KB | None | 0 0
  1. using System;
  2. using System.Reflection;
  3.  
  4. namespace Clight_19
  5. {
  6.     class Program
  7.     {
  8.         static void Main()
  9.         {
  10.             const string SimpleAttack = "1";
  11.             const string MiddleAttack = "2";
  12.             const string StrongAttack = "3";
  13.             const string MegaAttack = "4";
  14.  
  15.             Random random = new Random();
  16.             string userInput = "";
  17.             bool isCorrectInput = false;
  18.  
  19.             int fightingStep = 1;
  20.  
  21.             int bossHealth = 200;
  22.             int bossDamage = 10;
  23.  
  24.             int playerHealth = 100;
  25.  
  26.             int playerDamage = 10;
  27.             int minIncrementalDamage = 2;
  28.             int maxIncrementalDamage = 10;
  29.             int currentDamage;
  30.             float MiddleAttackFactor = 1.2f;
  31.             float StrongAttackFactor = 2f;
  32.             float MegaAttackFactor = 3;
  33.  
  34.             bool canHit;
  35.             bool isSuccessfulMegaAttack;
  36.             byte minPercentage = 0;
  37.             byte maxPercentage = 100;
  38.             byte probabilityStrongAttackOfPercentages = 85;
  39.             byte probabilitySuccessfulMegaAttackOfPercentages = 60;
  40.  
  41.             int playerPower;
  42.             int maxPlayerPower = 10;
  43.             int requiredPowerForMegaAttack = 5;
  44.             int restorePowerByStep = 2;
  45.             float powerFactor;
  46.  
  47.             playerPower = maxPlayerPower;
  48.  
  49.             while (playerHealth > 0 && bossHealth > 0)
  50.             {
  51.                 Console.Clear();
  52.                 Console.WriteLine($"Ход боя: {fightingStep}\n");
  53.                 Console.WriteLine($"Здоровье игрока: {playerHealth}");
  54.                 Console.WriteLine($"Сила игрока: {playerPower}\n");
  55.                 Console.WriteLine($"Здоровье босса: {bossHealth}\n");
  56.  
  57.                 Console.WriteLine($"{SimpleAttack} - Простой удар. Слабый, но восстанавливает силы.");
  58.                 Console.WriteLine($"{MiddleAttack} - Средняя атака.");
  59.                 Console.WriteLine($"{StrongAttack} - Сильная атака. Зависит от силы игрока. Вероятность промахнуться.");
  60.                 Console.WriteLine($"{MegaAttack} - Мега атака. Если сила игрока > {requiredPowerForMegaAttack}. Вероятность нанести себе урон.\n");
  61.  
  62.                 if (playerPower > 0)
  63.                 {
  64.                     isCorrectInput = false;
  65.  
  66.                     while (isCorrectInput == false)
  67.                     {
  68.                         isCorrectInput = true;
  69.  
  70.                         Console.Write("Выберете номер удара: ");
  71.                         userInput = Console.ReadLine();
  72.  
  73.                         switch (userInput)
  74.                         {
  75.                             case SimpleAttack:
  76.                                 bossHealth -= playerDamage;
  77.  
  78.                                 playerPower += restorePowerByStep;
  79.  
  80.                                 Console.WriteLine($"Ваш удар нанёс {playerDamage} урона. Возобновление силы +{restorePowerByStep}.");
  81.                                 break;
  82.                             case MiddleAttack:
  83.                                 currentDamage = playerDamage + (int)(random.Next(minIncrementalDamage, ++maxIncrementalDamage) * MiddleAttackFactor);
  84.  
  85.                                 bossHealth -= currentDamage;
  86.  
  87.                                 playerPower -= restorePowerByStep;
  88.  
  89.                                 Console.WriteLine($"Ваш удар нанёс {currentDamage} урона.");
  90.                                 break;
  91.                             case StrongAttack:
  92.                                 canHit = random.Next(minPercentage, ++maxPercentage) <= probabilityStrongAttackOfPercentages;
  93.  
  94.                                 if (canHit)
  95.                                 {
  96.                                     powerFactor = maxPlayerPower / playerPower;
  97.  
  98.                                     currentDamage = playerDamage + (int)(random.Next(minIncrementalDamage, ++maxIncrementalDamage)
  99.                                         * StrongAttackFactor * powerFactor);
  100.  
  101.                                     bossHealth -= currentDamage;
  102.  
  103.                                     playerPower -= restorePowerByStep;
  104.  
  105.                                     Console.WriteLine($"Ваш удар нанёс {currentDamage} урона.");
  106.                                 }
  107.                                 else
  108.                                 {
  109.                                     playerPower += restorePowerByStep;
  110.  
  111.                                     Console.WriteLine($"Промахнулись. Возобновление силы +{restorePowerByStep}");
  112.                                 }
  113.                                 break;
  114.                             case MegaAttack:
  115.                                 if (playerPower > requiredPowerForMegaAttack)
  116.                                 {
  117.                                     isSuccessfulMegaAttack = random.Next(minPercentage, ++maxPercentage) <= probabilitySuccessfulMegaAttackOfPercentages;
  118.  
  119.                                     if (isSuccessfulMegaAttack == false)
  120.                                     {
  121.                                         playerHealth -= playerDamage;
  122.  
  123.                                         currentDamage = (int)(playerDamage * MegaAttackFactor);
  124.  
  125.                                         bossHealth -= currentDamage;
  126.  
  127.                                         playerPower -= restorePowerByStep;
  128.  
  129.                                         Console.WriteLine($"Нанесён урон {currentDamage} не только боссу, но и себе {playerDamage}.");
  130.                                     }
  131.                                     else
  132.                                     {
  133.                                         currentDamage = (int)(playerDamage * MegaAttackFactor);
  134.  
  135.                                         bossHealth -= currentDamage;
  136.  
  137.                                         playerPower -= restorePowerByStep;
  138.  
  139.                                         Console.WriteLine($"Ваш удар нанёс {currentDamage} урона.");
  140.                                     }
  141.                                 }
  142.                                 else
  143.                                 {
  144.                                     playerPower += restorePowerByStep;
  145.  
  146.                                     Console.WriteLine($"Вам не хватило сил нанести удар. Возобновление силы +{restorePowerByStep}");
  147.                                 }
  148.                                 break;
  149.                             default:
  150.                                 isCorrectInput = false;
  151.                                 Console.WriteLine("Не корректно введён номер.");
  152.                                 break;
  153.                         }
  154.                     }
  155.                 }
  156.                 else
  157.                 {
  158.                     playerPower += restorePowerByStep;
  159.  
  160.                     Console.WriteLine($"Вам не хватило сил нанести удар. Возобновление силы +{restorePowerByStep}");
  161.                 }
  162.  
  163.                 playerPower = Math.Clamp(playerPower, 0, maxPlayerPower);
  164.  
  165.                 playerHealth -= bossDamage;
  166.  
  167.                 Console.WriteLine($"Босс нанёс вам {bossDamage} урона.");
  168.  
  169.                 if (playerHealth <= 0 && bossHealth <= 0)
  170.                 {
  171.                     Console.WriteLine("\nНичья.");
  172.                 }
  173.                 else if (playerHealth <= 0)
  174.                 {
  175.                     Console.WriteLine("\nВы убиты.");
  176.                 }
  177.                 else if (bossHealth <= 0)
  178.                 {
  179.                     Console.WriteLine("\nВы победили.");
  180.                 }
  181.  
  182.                 Console.Write("\nДля продолжения нажмите любую клавишу.");
  183.                 Console.ReadKey();
  184.  
  185.                 fightingStep++;
  186.             }
  187.         }
  188.     }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement