pol9na

Бойцы

Mar 31st, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.23 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 Study
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Fighter[] fighters = { new Fighter("Johj", 500, 50, 0), new Fighter("Mark", 250, 20, 25), new Fighter("Alex", 150, 100, 10), new Fighter("Max" , 300,30,0) };
  13.             int fighterIndex;
  14.             for (int i = 0; i < fighters.Length; i++)
  15.             {
  16.                 Console.Write(i + " ");
  17.                 fighters[i].ShowStats();
  18.             }
  19.  
  20.             Console.Write("Выберите бойца правых ворот:");
  21.             fighterIndex = Convert.ToInt32(Console.ReadLine());
  22.             Fighter rightFighter = fighters[fighterIndex];
  23.             Console.Write("Выберите бойца левых ворот:");
  24.             fighterIndex = Convert.ToInt32(Console.ReadLine());
  25.             Fighter leftFighter = fighters[fighterIndex];
  26.  
  27.             while(leftFighter.Health>0&&rightFighter.Health>0)
  28.             {
  29.                 leftFighter.TakeDamage(rightFighter.Damage);
  30.                 rightFighter.TakeDamage(leftFighter.Damage);
  31.                 leftFighter.ShowStats();
  32.                 rightFighter.ShowStats();
  33.            
  34.             }
  35.         }
  36.            
  37.      }
  38.  
  39.    
  40.     class Fighter
  41.     {
  42.         private int _health;
  43.         private string _name;
  44.         private int _damage;
  45.         private int _armor;
  46.  
  47.         public int Health
  48.         {
  49.             get
  50.             {
  51.                 return _health;
  52.             }
  53.  
  54.         }
  55.         public int Damage
  56.         {
  57.             get {
  58.                 return _damage;
  59.             }
  60.        
  61.         }
  62.         public Fighter(string name, int health, int damage, int armor)
  63.         {
  64.             _name = name;
  65.             _health = health;
  66.             _damage = damage;
  67.             _armor = armor;
  68.         }
  69.  
  70.         public void ShowStats()
  71.         {
  72.             Console.WriteLine(_name + " HP- " + _health + " DMG- " + _damage + " Armor- " + _armor);
  73.        
  74.         }
  75.  
  76.         public void TakeDamage(int damage)
  77.         {
  78.             _health -= damage - _armor;
  79.         }
  80.     }
  81.  
  82.    
  83. }
Add Comment
Please, Sign In to add comment