Pro_Unit

WarriorsBattle

Mar 19th, 2020
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.01 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.     abstract class Warrior   //Общий класс
  71.     {
  72.         public string Name { get; set;}
  73.         public int Health { get; set;}
  74.         public int Damage { get; set;}
  75.         public int Armor { get; set;}
  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 abstract void DoSpecial();
  101.  
  102.     }
  103.  
  104.     class Mage : Warrior
  105.     {
  106.         public Mage(string name, int health, int damage, int armor) : base(name, health, damage, armor)
  107.         {
  108.         }
  109.         public void FireCast()
  110.         {
  111.             Damage += 100;
  112.             Armor -= 5;
  113.         }
  114.         public override void DoSpecial()
  115.         {
  116.             FireCast();
  117.         }
  118.     }
  119.  
  120.     class Rogue : Warrior
  121.     {
  122.         public Rogue(string name, int health, int damage, int armor) : base(name, health, damage, armor)
  123.         { }
  124.         public void Evade()
  125.         {
  126.             Health -= Damage * 0;
  127.         }
  128.         public override void DoSpecial()
  129.         {
  130.             Evade();
  131.         }
  132.     }
  133.  
  134.     class Tank : Warrior
  135.     {
  136.         public Tank(string name, int health, int damage, int armor) : base(name, health, damage, armor)
  137.         { }
  138.         public void ShieldsUp()
  139.         {
  140.             Armor += 100;
  141.         }
  142.         public override void DoSpecial()
  143.         {
  144.             ShieldsUp();
  145.         }
  146.     }
  147.  
  148.     class Gladiator : Warrior
  149.     {
  150.         public Gladiator(string name, int health, int damage, int armor) : base(name, health, damage, armor)
  151.         { }
  152.         public void CriticalBlow()
  153.         {
  154.             Damage *= 2;
  155.         }
  156.         public override void DoSpecial()
  157.         {
  158.             CriticalBlow();
  159.         }
  160.     }
  161.  
  162.     class Monk : Warrior
  163.     {
  164.         public Monk(string name, int health, int damage, int armor) : base(name, health, damage, armor)
  165.         { }
  166.         public void CriticalBlow()
  167.         {
  168.             Health += 15;
  169.         }
  170.         public override void DoSpecial()
  171.         {
  172.             CriticalBlow();
  173.         }
  174.     }
  175. }
Add Comment
Please, Sign In to add comment