Advertisement
alexey3017

Untitled

Mar 25th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.91 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);
  30.                 rightWarrior.TakeDamage(leftWarrior.Damage);
  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)
  60.         {
  61.             _health -= damage - _armor;
  62.         }
  63.     }
  64.  
  65.     class Knight : Warrior
  66.     {
  67.         public Knight(string name, int health, int armor, int damage) : base(name, health, armor, damage)
  68.         {
  69.         }
  70.  
  71.         public int GrateHeal(int damage, int health)
  72.         {
  73.            if(health < 50)
  74.             {
  75.                 return health += 30;
  76.             }
  77.             else
  78.             {
  79.                 return health;
  80.             }
  81.         }
  82.     }
  83.     class Rogue : Warrior
  84.     {
  85.         public Rogue(string name, int health, int armor, int damage, int attackSpeed) : base(name, health, armor, damage)
  86.         {
  87.         }
  88.  
  89.         public  int DoubleDamage(int damage, int health,int attackspeed)
  90.         {
  91.             return damage * attackspeed;
  92.         }
  93.     }
  94.     class Paladin : Warrior
  95.     {
  96.         public Paladin(string name, int health, int armor, int damage) : base(name, health, armor, damage)
  97.         {
  98.         }
  99.  
  100.         public int SpecitalAttack(int damage, int health)
  101.         {
  102.             if(health > 30 && health < 200)
  103.             {
  104.                 return damage /= 2;
  105.             }
  106.             else
  107.             {
  108.                 return damage;
  109.             }
  110.         }
  111.     }
  112.     class Mage : Warrior
  113.     {
  114.         public Mage(string name, int health, int armor, int damage) : base(name, health, armor, damage)
  115.         {
  116.         }
  117.  
  118.         public int FireBolt(int damage, int health)
  119.         {
  120.             int attack = 5;
  121.             return damage*= attack;
  122.         }
  123.     }
  124.  
  125.     class Hunter : Warrior
  126.     {
  127.         public Hunter(string name, int health, int armor, int damage) : base(name, health, armor, damage)
  128.         {
  129.         }
  130.  
  131.         public int AimShot(int damage, int health)
  132.         {
  133.             return damage *= 5;
  134.         }
  135.     }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement