Advertisement
VoVfe

Untitled

Jul 14th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Policy;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml.Linq;
  8.  
  9. namespace Гладиаторские_бои
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             Fighters[] fighters = new Fighters[] {new Healthy("Фёдр", 111, 11), new Strong("Саша", 62, 36), new Fast("Никита", 61, 30), new Dexterous("Роман", 100, 25), new Wimp("Алекс", 41, 47) };
  16.  
  17.             for (int i = 0; i < fighters.Length; i++)
  18.             {
  19.                 Console.Write($"{i}.");
  20.                 fighters[i].ShowStatistics();
  21.             }
  22.  
  23.             Console.Write("\nВыберите номер 1-ого бойца:");
  24.             var firstFighter = fighters[Convert.ToInt32(Console.ReadLine())];
  25.             Console.Write("Выберите номер 2-ого бойца:");
  26.             var secondFighter = fighters[Convert.ToInt32(Console.ReadLine())];
  27.             Console.Clear();
  28.             firstFighter.ShowStatistics();
  29.             secondFighter.ShowStatistics();
  30.  
  31.             while (firstFighter.Health > 0 && secondFighter.Health > 0)
  32.             {
  33.                 Console.WriteLine();
  34.                 firstFighter.TakeDamage(secondFighter.Damage);
  35.                 firstFighter.Ability();
  36.                 secondFighter.TakeDamage(firstFighter.Damage);
  37.                 secondFighter.Ability();
  38.                 firstFighter.ShowStatistics();
  39.                 secondFighter.ShowStatistics();
  40.                 Console.ReadKey();
  41.             }
  42.  
  43.             if (firstFighter.Health > 0)
  44.             {
  45.                 Console.Write($"\nПроиграл:");
  46.                 secondFighter.ShowStatistics();
  47.                 Console.Write($"Победил:");
  48.                 firstFighter.ShowStatistics();
  49.             }
  50.                
  51.             else if(secondFighter.Health > 0)
  52.             {
  53.                 Console.WriteLine($"\nПроиграл:");
  54.                 firstFighter.ShowStatistics();
  55.                 Console.WriteLine($"Победил:");
  56.                 secondFighter.ShowStatistics();
  57.             }
  58.  
  59.             else if(firstFighter.Health < 0 && secondFighter.Health < 0)
  60.             {
  61.                 Console.WriteLine("Оба бойца погибли!");
  62.             }
  63.             Console.ReadKey();
  64.         }
  65.     }
  66.  
  67.     abstract class Fighters
  68.     {
  69.         protected string Name;
  70.         public int Health {get; protected set;}
  71.         public int Damage {get; protected set;}
  72.         public Fighters(string name, int health, int damage)
  73.         {
  74.             Name = name;
  75.             Health = health;
  76.             Damage = damage;
  77.         }
  78.  
  79.         public void ShowStatistics()
  80.         {
  81.             Console.WriteLine($"имя:{Name}, Жизни - {Health}, урон - {Damage}");
  82.         }
  83.  
  84.         public virtual void TakeDamage(int damage)
  85.         {
  86.             Health -= damage;
  87.         }
  88.  
  89.         public abstract void Ability();
  90.     }
  91.  
  92.     class Healthy : Fighters
  93.     {
  94.         public Healthy(string name, int health, int damage) : base(name, health, damage){}
  95.  
  96.         public override void Ability()
  97.         {
  98.             Health += 8;
  99.         }
  100.     }
  101.  
  102.     class Strong : Fighters
  103.     {
  104.         public Strong(string name, int health, int damage) : base(name, health, damage){}
  105.  
  106.         public override void Ability()
  107.         {
  108.             Damage += 8;
  109.         }
  110.     }
  111.    
  112.     class Fast : Fighters
  113.     {
  114.         public Fast(string name, int health, int damage) : base(name, health, damage){}
  115.  
  116.         public override void Ability()
  117.         {
  118.             Damage *= 2;
  119.         }
  120.     }
  121.  
  122.     class Dexterous : Fighters
  123.     {
  124.         public Dexterous(string name, int health, int damage) : base(name, health, damage){}
  125.  
  126.         public override void Ability()
  127.         {
  128.             Health *= 2;
  129.         }
  130.     }
  131.  
  132.     class Wimp : Fighters
  133.     {
  134.         public Wimp(string name, int health, int damage) : base(name, health, damage){}
  135.  
  136.         public override void Ability()
  137.         {
  138.             Random rand = new Random();
  139.  
  140.             for(int i = 0; i < rand.Next(0,12); i++)
  141.             {
  142.                 Health++;
  143.             }
  144.         }
  145.     }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement