Pro_Unit

WarriorsBattle

Mar 17th, 2020
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.02 KB | None | 0 0
  1. using System;
  2.  
  3. namespace WarriorsBattle
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int warriorIndex;
  10.             Warrior[] warriors =
  11.             {
  12.                 new Mage ("- Mage -      ",250, 70, 15),
  13.                 new Rogue ("- Rogue -     ", 250, 100, 30),
  14.                 new Tank ("- Tank -      ", 400, 70, 50),
  15.                 new Gladiator ("- Gladiator - ",250, 130, 15),
  16.                 new Monk ("- Monk -      ",250, 90, 50)
  17.             };
  18.  
  19.             for (int i = 0; i < warriors.Length; i++)
  20.             {
  21.                 Console.Write(i + " ");
  22.                 warriors[i].ShowAllStats();
  23.             }
  24.  
  25.             Console.WriteLine("\n Выберите первого бойца: ");
  26.             warriorIndex = Convert.ToInt32(Console.ReadLine());
  27.  
  28.             Warrior firstWarrior = warriors[warriorIndex];
  29.             Console.WriteLine(" Вы выбрали - " + firstWarrior.name);
  30.  
  31.             firstWarrior.ShowAllStats();
  32.  
  33.             Console.WriteLine(" Выберите второго бойца: ");
  34.             warriorIndex = Convert.ToInt32(Console.ReadLine());
  35.  
  36.             Warrior secondWarrior = warriors[warriorIndex];
  37.             Console.WriteLine(" Вы выбрали - " + secondWarrior.name);
  38.  
  39.             secondWarrior.ShowAllStats();
  40.  
  41.             System.Console.WriteLine("Нажмите любую клавишу чтобы начать бой");
  42.             Console.ReadKey();
  43.  
  44.             while (firstWarrior.Health > 0 && secondWarrior.Health > 0)
  45.             {
  46.  
  47.                 System.Console.WriteLine(" --- Do Specials --- ");
  48.                 firstWarrior.DoSpecial();
  49.                 secondWarrior.DoSpecial();
  50.  
  51.                 firstWarrior.ShowAllStats();
  52.                 secondWarrior.ShowAllStats();
  53.  
  54.                 System.Console.WriteLine(" --- Do Attack --- ");
  55.  
  56.                 firstWarrior.TakenDamage(secondWarrior.Damage);
  57.                 secondWarrior.TakenDamage(firstWarrior.Damage);
  58.  
  59.                 firstWarrior.ShowAllStats();
  60.                 secondWarrior.ShowAllStats();
  61.             }
  62.  
  63.             if (firstWarrior.Health > 0)
  64.                 System.Console.WriteLine($"Победил {firstWarrior.name}");
  65.             else if (secondWarrior.Health > 0)
  66.                 System.Console.WriteLine($"Победил {secondWarrior.name}");
  67.  
  68.         }
  69.     }
  70.     class Warrior   //Общий класс
  71.     {
  72.         public string name;
  73.         public int Health;
  74.         public int Damage;
  75.         public int Armor;
  76.         public Warrior(string name, int health, int damage, int armor)
  77.         {
  78.             this.name = name;
  79.             Health = health;
  80.             Damage = damage;
  81.             Armor = armor;
  82.         }
  83.  
  84.         public Warrior(int health, int damage, int armor)  //Конструктор
  85.         {
  86.             Health = health;
  87.             Damage = damage;
  88.             Armor = armor;
  89.         }
  90.  
  91.         public void TakenDamage(int damage)
  92.         {
  93.             Health -= damage - Armor;
  94.         }
  95.  
  96.         public void ShowAllStats()
  97.         {
  98.             Console.WriteLine(name + "Здоровья " + Health + " Урон " + Damage + " Броня " + Armor);
  99.         }
  100.         public virtual void DoSpecial()
  101.         {
  102.             throw new NotImplementedException();
  103.         }
  104.  
  105.     }
  106.  
  107.     class Mage : Warrior
  108.     {
  109.         public Mage(string name, int health, int damage, int armor) : base(name, health, damage, armor)
  110.         {
  111.         }
  112.         public void FireCast()
  113.         {
  114.             Damage += 100;
  115.             Armor -= 5;
  116.         }
  117.         public override void DoSpecial()
  118.         {
  119.             FireCast();
  120.         }
  121.     }
  122.  
  123.     class Rogue : Warrior
  124.     {
  125.         public Rogue(string name, int health, int damage, int armor) : base(name, health, damage, armor)
  126.         { }
  127.         public void Evade()
  128.         {
  129.             Health -= Damage * 0;
  130.         }
  131.         public override void DoSpecial()
  132.         {
  133.             Evade();
  134.         }
  135.     }
  136.  
  137.     class Tank : Warrior
  138.     {
  139.         public Tank(string name, int health, int damage, int armor) : base(name, health, damage, armor)
  140.         { }
  141.         public void ShieldsUp()
  142.         {
  143.             Armor += 100;
  144.         }
  145.         public override void DoSpecial()
  146.         {
  147.             ShieldsUp();
  148.         }
  149.     }
  150.  
  151.     class Gladiator : Warrior
  152.     {
  153.         public Gladiator(string name, int health, int damage, int armor) : base(name, health, damage, armor)
  154.         { }
  155.         public void CriticalBlow()
  156.         {
  157.             Damage *= 2;
  158.         }
  159.         public override void DoSpecial()
  160.         {
  161.             CriticalBlow();
  162.         }
  163.     }
  164.  
  165.     class Monk : Warrior
  166.     {
  167.         public Monk(string name, int health, int damage, int armor) : base(name, health, damage, armor)
  168.         { }
  169.         public void CriticalBlow()
  170.         {
  171.             Health += 15;
  172.         }
  173.         public override void DoSpecial()
  174.         {
  175.             CriticalBlow();
  176.         }
  177.     }
  178. }
Add Comment
Please, Sign In to add comment