Advertisement
LeRoY_Go

Untitled

Feb 16th, 2022
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace C_Sharp_Junior
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             bool isExit = false;
  11.             Arena arena = new Arena();
  12.  
  13.             while (isExit == false)
  14.             {
  15.                 Console.Write("1 - Выбрать бойцов и начать бой\n2 - Информация о бойцах\n3 - Выход из игры\nКоманда:");
  16.                 bool successfulConversion = int.TryParse(Console.ReadLine(), out int userInput);
  17.  
  18.                 if (successfulConversion == true)
  19.                 {
  20.                     switch (userInput)
  21.                     {
  22.                         case 1:
  23.                             arena.ChooseFighter();
  24.                             break;
  25.                         case 2:
  26.                             arena.PersonInfo();
  27.                             break;
  28.                         case 3:
  29.                             isExit = true;
  30.                             break;
  31.                     }
  32.                 }
  33.  
  34.                 Console.ReadKey();
  35.                 Console.Clear();
  36.             }
  37.         }
  38.     }
  39.  
  40.     class Arena
  41.     {
  42.         private List<Warrior> _warriors;
  43.         private List<Warrior> _warriorsUserInpyt;
  44.  
  45.         public Arena()
  46.         {
  47.             _warriors = new List<Warrior> { new Knight("Воин-Солдат", 100, 20, 70), new Magician("Маг-Черадей", 80, 50, 20, 100), new Engineer("Инжинер", 80, 30, 50, 15), new Archer("Лучник", 60, 15, 35, 20), new Healer("Медик", 150, 12, 20, 25) };
  48.             _warriorsUserInpyt = new List<Warrior>();
  49.         }
  50.  
  51.         public void PersonInfo()
  52.         {
  53.             for (int i = 0; i < _warriors.Count; i++)
  54.             {
  55.                 _warriors[i].ShowInfo();
  56.             }
  57.         }
  58.  
  59.         public void ChooseFighter()
  60.         {
  61.             Console.WriteLine("Выберите бойцов:\n1- Воин-Солдат\n2- Маг-Черадей\n3- Инжинер\n4- Лучник\n5- Медик\n");
  62.             Console.Write("Боец №1: ");
  63.             int userInpyt1 = ChoiceWar();
  64.             _warriorsUserInpyt.Add(_warriors[userInpyt1]);
  65.             int userInpyt2;
  66.             do
  67.             {
  68.                 Console.Write("Боуц №2: ");
  69.                 userInpyt2 = ChoiceWar();
  70.             } while (userInpyt1 == userInpyt2);
  71.             _warriorsUserInpyt.Add(_warriors[userInpyt2]);
  72.             Console.Clear();
  73.  
  74.             for (int i = 0; i < _warriorsUserInpyt.Count; i++)
  75.             {
  76.                 _warriorsUserInpyt[i].ShowInfo();
  77.             }
  78.  
  79.             Console.Write("\nНажмите кнопку для начала боя");
  80.             Console.ReadKey();
  81.             Console.Clear();
  82.             Battle();
  83.         }
  84.  
  85.         private int ChoiceWar()
  86.         {
  87.             int userInput = 0;
  88.             bool warriorChosenCorrectly = false;
  89.  
  90.             while (warriorChosenCorrectly == false)
  91.             {
  92.                 bool successfulConversion = int.TryParse(Console.ReadLine(), out userInput);
  93.  
  94.                 if (successfulConversion == true && userInput <= _warriors.Count && userInput > 0)
  95.                 {
  96.                     warriorChosenCorrectly = true;
  97.                 }
  98.                 else
  99.                 {
  100.                     Console.WriteLine("Бойца с таким номером нет. Выберите другова бойца.");
  101.                 }
  102.             }
  103.  
  104.             return userInput - 1;
  105.         }
  106.  
  107.         private void Battle()
  108.         {
  109.             int round = 0;
  110.  
  111.             while (_warriorsUserInpyt[0].Health > 0 && _warriorsUserInpyt[1].Health > 0)
  112.             {
  113.                 Console.WriteLine($"Жизни {_warriorsUserInpyt[0].NameWarrior} - {_warriorsUserInpyt[0].Health}");
  114.                 Console.WriteLine($"Жизни {_warriorsUserInpyt[1].NameWarrior} - {_warriorsUserInpyt[1].Health}");
  115.                 _warriorsUserInpyt[0].TakingDamage(_warriorsUserInpyt[1].Damage);
  116.                 _warriorsUserInpyt[1].TakingDamage(_warriorsUserInpyt[0].Damage);
  117.  
  118.                 if (round == 2)
  119.                 {
  120.                     _warriorsUserInpyt[0].AbilityStrike();
  121.                     _warriorsUserInpyt[1].AbilityStrike();
  122.                     round = 0;
  123.                 }
  124.                 round++;
  125.             }
  126.  
  127.             if (_warriorsUserInpyt[0].Health <= 0)
  128.             {
  129.                 Console.WriteLine("Победил " + _warriorsUserInpyt[1].NameWarrior);
  130.             }
  131.             else if (_warriorsUserInpyt[1].Health <= 0)
  132.             {
  133.                 Console.WriteLine("Победил " + _warriorsUserInpyt[0].NameWarrior);
  134.             }
  135.             _warriorsUserInpyt.Clear();
  136.         }
  137.     }
  138.  
  139.     class Warrior
  140.     {
  141.         public string NameWarrior { get; private set; }
  142.         public int Armor { get; private set; }
  143.         public int Health { get; private set; }
  144.         public int Damage { get; private set; }
  145.  
  146.         public Warrior(string nameWarrior, int health, int damage, int armor)
  147.         {
  148.             NameWarrior = nameWarrior;
  149.             Health = health;
  150.             Damage = damage;
  151.             Armor = armor;
  152.         }
  153.  
  154.         public virtual void ShowInfo()
  155.         {
  156.             Console.WriteLine($"Тип: {NameWarrior}\nЗдоровье: {Health}\nБроня: {Armor}\nУрон: {Damage}");
  157.         }
  158.  
  159.         public void TakingDamage(int damage)
  160.         {
  161.             Health -= Armor - damage;
  162.         }
  163.  
  164.         public void ChangeHealthAbilityStrike()
  165.         {
  166.             int valueRestoringHealth = 200;
  167.             Health = valueRestoringHealth;
  168.         }
  169.  
  170.         public void ChangeDamageAbilityStrike()
  171.         {
  172.             int valueDamageEntrainment = 2;
  173.             Damage *= valueDamageEntrainment;
  174.         }
  175.  
  176.         public virtual void AbilityStrike()
  177.         {
  178.         }
  179.     }
  180.  
  181.     class Knight : Warrior
  182.     {
  183.         public Knight(string nameWarrior, int health, int damage, int armor) : base(nameWarrior, health, damage, armor)
  184.         {
  185.         }
  186.  
  187.         public override void ShowInfo()
  188.         {
  189.             base.ShowInfo();
  190.             Console.WriteLine("Способность: Режим ярости");
  191.             Console.WriteLine(new string('-', 70));
  192.         }
  193.  
  194.         public override void AbilityStrike()
  195.         {
  196.             ChangeDamageAbilityStrike();
  197.         }
  198.     }
  199.  
  200.     class Magician : Warrior
  201.     {
  202.         private int _mana;
  203.  
  204.         public Magician(string nameWarrior, int health, int damage, int armor, int mana) : base(nameWarrior, health, damage, armor)
  205.         {
  206.             _mana = mana;
  207.         }
  208.  
  209.         public override void ShowInfo()
  210.         {
  211.             base.ShowInfo();
  212.             Console.WriteLine($"Мана: {_mana}\nСпособность: Выстрел магическими шарами");
  213.             Console.WriteLine(new string('-', 70));
  214.         }
  215.  
  216.         public override void AbilityStrike()
  217.         {
  218.             int consumptionMana = 40;
  219.             if (_mana > consumptionMana)
  220.             {
  221.                 ChangeDamageAbilityStrike();
  222.                 _mana -= consumptionMana;
  223.             }
  224.         }
  225.     }
  226.  
  227.     class Engineer : Warrior
  228.     {
  229.         private int _mechanisms;
  230.  
  231.         public Engineer(string nameWarrior, int health, int damage, int armor, int mechanisms) : base(nameWarrior, health, damage, armor)
  232.         {
  233.             _mechanisms = mechanisms;
  234.         }
  235.  
  236.         public override void ShowInfo()
  237.         {
  238.             base.ShowInfo();
  239.             Console.WriteLine($"Механизмы: {_mechanisms}\nСпособность: Постройка царь-пушки");
  240.             Console.WriteLine(new string('-', 70));
  241.         }
  242.         public override void AbilityStrike()
  243.         {
  244.             int consumptionMechanisms = 50;
  245.             if (_mechanisms >= consumptionMechanisms)
  246.             {
  247.                 ChangeDamageAbilityStrike();
  248.                 _mechanisms -= consumptionMechanisms;
  249.             }
  250.         }
  251.     }
  252.  
  253.     class Archer : Warrior
  254.     {
  255.         private int _arrows;
  256.  
  257.         public Archer(string nameWarrior, int health, int damage, int armor, int arrows) : base(nameWarrior, health, damage, armor)
  258.         {
  259.             _arrows = arrows;
  260.         }
  261.  
  262.         public override void ShowInfo()
  263.         {
  264.             base.ShowInfo();
  265.             Console.WriteLine($"Стрелы: {_arrows}\nСпособность: Шквал стрел");
  266.             Console.WriteLine(new string('-', 70));
  267.         }
  268.  
  269.         public override void AbilityStrike()
  270.         {
  271.             int ConsumptionArrows = 25;
  272.             if (_arrows >= ConsumptionArrows)
  273.             {
  274.                 ChangeDamageAbilityStrike();
  275.                 _arrows -= ConsumptionArrows;
  276.             }
  277.         }
  278.     }
  279.  
  280.     class Healer : Warrior
  281.     {
  282.         private int _potions;
  283.  
  284.         public Healer(string nameWarrior, int health, int damage, int armor, int potions) : base(nameWarrior, health, damage, armor)
  285.         {
  286.             _potions = potions;
  287.         }
  288.  
  289.         public override void ShowInfo()
  290.         {
  291.             base.ShowInfo();
  292.             Console.WriteLine($"Зелья: {_potions}\nСпособность: Полное восстановление здоровье + баф");
  293.             Console.Write(new string('-', 70));
  294.         }
  295.  
  296.         public override void AbilityStrike()
  297.         {
  298.             int consumptionPotions = 10;
  299.             if (_potions >= consumptionPotions)
  300.             {
  301.                 ChangeHealthAbilityStrike();
  302.                 _potions -= consumptionPotions;
  303.             }
  304.         }
  305.     }
  306. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement