Advertisement
Dr_Max_Experience

Fighters

Jan 28th, 2022
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ООП
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Fighter[] fighters = { new Fighter("F0", 60, 6, 2), new Fighter("F1", 90, 5, 0), new Fighter("F2", 40, 8, 4) };
  10.             int fighterIndex;
  11.  
  12.             for (int i = 0; i < fighters.Length; i++)
  13.             {
  14.                 fighters[i].ShowStats();
  15.             }
  16.  
  17.             Console.Write("Первый боец: ");
  18.             fighterIndex = Convert.ToInt32(Console.ReadLine());
  19.             Fighter firstFighter = fighters[fighterIndex];
  20.             Console.Write("Второй боец: ");
  21.             fighterIndex = Convert.ToInt32(Console.ReadLine());
  22.             Fighter secondFighter = fighters[fighterIndex];
  23.  
  24.             while(firstFighter.Health > 0 && secondFighter.Health > 0)
  25.             {
  26.                 Console.WriteLine();
  27.                 firstFighter.TakeDamage(secondFighter.Damage);
  28.                 secondFighter.TakeDamage(firstFighter.Damage);
  29.                 firstFighter.ShowStats();
  30.                 secondFighter.ShowStats();
  31.             }
  32.         }
  33.     }
  34.  
  35.     class Fighter
  36.     {
  37.         private string _name;
  38.         private int _health;
  39.         private int _damage;
  40.         private int _armor;
  41.  
  42.         public int Health
  43.         {
  44.             get
  45.             {
  46.                 return _health;
  47.             }
  48.         }
  49.  
  50.         public int Damage
  51.         {
  52.             get
  53.             {
  54.                 return _damage;
  55.             }
  56.         }
  57.  
  58.         public Fighter(string name, int health, int damage, int armor)
  59.         {
  60.             _name = name;
  61.             _health = health;
  62.             _damage = damage;
  63.             _armor = armor;
  64.         }
  65.  
  66.         public void ShowStats()
  67.         {
  68.             Console.WriteLine(_name + " HP:" + _health + " DMG:" + _damage + " ARM:" + _armor);
  69.         }
  70.  
  71.         public void TakeDamage(int damage)
  72.         {
  73.             _health -= damage - _armor;
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement