Advertisement
alexey3017

Untitled

Mar 26th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Learn1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Warrior[] warriors = { new Hunter("Иллидан", 130, 10, 25), new Knight("Гаррош", 90, 7, 15), new Rogue("Рагнарос", 180, 2, 33, 2), new Paladin("Нефариан", 220, 0, 29), new Mage("Смертокрыл", 500, 0, 15) };
  13.             for (int i = 0; i < warriors.Length; i++)
  14.             {
  15.                 Console.Write(i + " ");
  16.                 warriors[i].ShowInfo();
  17.             }
  18.  
  19.             Console.WriteLine("Выберите Первого бойца:");
  20.             int righWarriorIndex = Convert.ToInt32(Console.ReadLine());
  21.             Warrior rightWarrior = warriors[righWarriorIndex];
  22.             Console.WriteLine("Выберите Второго бойца:");
  23.             int leftWarriorIndex = Convert.ToInt32(Console.ReadLine());
  24.             Warrior leftWarrior = warriors[leftWarriorIndex];
  25.  
  26.             while (leftWarrior.Health > 0 && rightWarrior.Health > 0)
  27.             {
  28.                 Console.WriteLine();
  29.                 leftWarrior.TakeDamage(rightWarrior.Damage,rightWarrior.Health);
  30.                 rightWarrior.TakeDamage(leftWarrior.Damage,leftWarrior.Health);
  31.                 leftWarrior.ShowInfo();
  32.                 rightWarrior.ShowInfo();
  33.             }
  34.         }
  35.     }
  36.  
  37.     abstract class Warrior
  38.     {
  39.         private string _name;
  40.         private int _health;
  41.         private int _armor;
  42.         private int _damage;
  43.  
  44.         public Warrior(string name, int health, int armor, int damage)
  45.         {
  46.             _name = name;
  47.             _health = health;
  48.             _armor = armor;
  49.             _damage = damage;
  50.         }
  51.         public int Health { get { return _health; } }
  52.         public int Damage { get { return _damage; } }
  53.  
  54.         public void ShowInfo()
  55.         {
  56.             Console.WriteLine($"{_name}: ХП - {_health}, Броня - {_armor}, Дамаг - {_damage}");
  57.         }
  58.  
  59.         public void TakeDamage(int damage,int health)
  60.         {
  61.             _health -= damage - _armor;
  62.             Spec(damage, health);
  63.         }
  64.  
  65.         abstract public int Spec(int damage, int health,int attackspeed = 1);
  66.     }
  67.  
  68.     class Knight : Warrior
  69.     {
  70.         public Knight(string name, int health, int armor, int damage) : base(name, health, armor, damage)
  71.         {
  72.         }
  73.  
  74.         public int GrateHeal(int damage, int health)
  75.         {
  76.            if(health < 50)
  77.             {
  78.                 return health += 30;
  79.             }
  80.             else
  81.             {
  82.                 return health;
  83.             }
  84.         }
  85.  
  86.         public override int Spec(int damage, int health,int attackspeed)
  87.         {
  88.             Console.WriteLine("БАБАЦ");
  89.             return GrateHeal(damage, health);
  90.         }
  91.     }
  92.     class Rogue : Warrior
  93.     {
  94.         public Rogue(string name, int health, int armor, int damage, int attackSpeed) : base(name, health, armor, damage)
  95.         {
  96.         }
  97.  
  98.         public  int DoubleDamage(int damage, int health,int attackspeed)
  99.         {
  100.             return damage * attackspeed;
  101.         }
  102.  
  103.         public override int Spec(int damage, int health, int attackspeed)
  104.         {
  105.             return DoubleDamage(damage, health, attackspeed);
  106.         }
  107.     }
  108.     class Paladin : Warrior
  109.     {
  110.         public Paladin(string name, int health, int armor, int damage) : base(name, health, armor, damage)
  111.         {
  112.         }
  113.  
  114.         public override int Spec(int damage, int health,int attackspeed)
  115.         {
  116.             return SpecitalAttack(damage, health);
  117.         }
  118.  
  119.         public int SpecitalAttack(int damage, int health)
  120.         {
  121.             if(health > 30 && health < 200)
  122.             {
  123.                 return damage /= 2;
  124.             }
  125.             else
  126.             {
  127.                 return damage;
  128.             }
  129.         }
  130.     }
  131.     class Mage : Warrior
  132.     {
  133.         public Mage(string name, int health, int armor, int damage) : base(name, health, armor, damage)
  134.         {
  135.         }
  136.  
  137.         public int FireBolt(int damage, int health)
  138.         {
  139.             int attack = 5;
  140.             return damage*= attack;
  141.         }
  142.  
  143.         public override int Spec(int damage, int health,int attackspeed)
  144.         {
  145.             return FireBolt(damage, health);
  146.         }
  147.     }
  148.  
  149.     class Hunter : Warrior
  150.     {
  151.         public Hunter(string name, int health, int armor, int damage) : base(name, health, armor, damage)
  152.         {
  153.         }
  154.  
  155.         public int AimShot(int damage, int health)
  156.         {
  157.             return damage *= 5;
  158.         }
  159.  
  160.         public override int Spec(int damage, int health, int attackspeed)
  161.         {
  162.             return AimShot(damage, health);
  163.         }
  164.     }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement