Advertisement
Rodunskiy

Untitled

Aug 11th, 2023
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         Battlefield battlefield = new Battlefield();
  9.  
  10.         if (battlefield.TryCreativeBattle())
  11.         {
  12.             battlefield.Battle();
  13.             battlefield.ShowBattleResult();
  14.         }
  15.     }
  16. }
  17.  
  18. class Battlefield
  19. {
  20.     private Fighter _fighter1;
  21.     private Fighter _fighter2;
  22.     private List<Fighter> _fighters = new List<Fighter>();
  23.  
  24.     public Battlefield()
  25.     {
  26.         _fighters.Add(new Orc("Orc", 1000, 30, 100));
  27.         _fighters.Add(new Elf("Elf", 1000, 40, 100, 100));
  28.         _fighters.Add(new Dwarf("Dwarf", 1000, 60, 90));
  29.         _fighters.Add(new Human("Human", 1000, 50, 100));
  30.         _fighters.Add(new Undead("Undead", 700, 30, 80));
  31.  
  32.         _fighter1 = SelectFighter();
  33.         _fighter2 = SelectFighter();
  34.     }
  35.  
  36.     public Fighter SelectFighter()
  37.     {
  38.         Fighter fighter = null;
  39.         string userInput;
  40.         Console.WriteLine("Выберите двух бойцов для поединка:");
  41.  
  42.         ShowInfo();
  43.  
  44.         userInput = Console.ReadLine();
  45.  
  46.         foreach (var item in _fighters)
  47.         {
  48.             if(item.Name == userInput)
  49.             {
  50.                 fighter = item;
  51.                 _fighters.Remove(fighter);
  52.                 break;
  53.             }
  54.         }
  55.  
  56.         return fighter;
  57.     }
  58.  
  59.     public bool TryCreativeBattle()
  60.     {
  61.  
  62.         if (_fighter1 == null || _fighter2 == null)
  63.         {
  64.             Console.WriteLine("Ошибка выбора бойца");
  65.             return false;
  66.         }
  67.         else
  68.         {
  69.             Console.WriteLine("Бойцы выбраны! Нажмите любую клавишу чтобы начать бой.");
  70.  
  71.             Console.ReadKey();
  72.             Console.Clear();
  73.  
  74.             return true;
  75.         }
  76.     }
  77.  
  78.     public void Battle()
  79.     {
  80.         while (_fighter1.IsAlive && _fighter2.IsAlive)
  81.         {
  82.             _fighter1.ShowStats();
  83.             _fighter2.ShowStats();
  84.             _fighter1.Strike(_fighter2);
  85.             _fighter2.Strike(_fighter1);
  86.  
  87.             Console.ReadKey();
  88.             Console.Clear();
  89.         }
  90.     }
  91.  
  92.     public void ShowBattleResult()
  93.     {
  94.         if (_fighter1.IsDead && _fighter2.IsDead)
  95.         {
  96.             Console.WriteLine("Оба бойца погибли.");
  97.         }
  98.         else if (_fighter1.IsDead)
  99.         {
  100.             Console.WriteLine($"{_fighter2.Name} побеждает.");
  101.         }
  102.         else if (_fighter2.IsDead)
  103.         {
  104.             Console.WriteLine($"{_fighter1.Name} побеждает.");
  105.         }
  106.     }
  107.  
  108.     public void ShowInfo()
  109.     {
  110.         foreach (var fighter in _fighters)
  111.         {
  112.             fighter.ShowStats();
  113.         }
  114.     }
  115. }
  116.  
  117. class Fighter
  118. {
  119.     protected int Damage;
  120.     protected float Armor;
  121.     protected float Health;
  122.  
  123.     public Fighter (string name, float health, float armor, int damage)
  124.     {
  125.         Name = name;
  126.         Health = health;
  127.         Armor = armor;
  128.         Damage = damage;
  129.     }
  130.  
  131.     public bool IsDead => Health <= 0;
  132.     public bool IsAlive => Health > 0;
  133.  
  134.     public string Name { get; private set; }
  135.  
  136.     public virtual void Strike(Fighter fighter) => fighter.TakeDamage(Damage);
  137.  
  138.  
  139.     public void TakeDamage(float damage)
  140.     {
  141.         int divider = 100;
  142.  
  143.         Health -= damage * (1 - (Armor / divider));
  144.     }
  145.  
  146.     public void ShowStats()
  147.     {
  148.         Console.WriteLine($"{Name}|Жизни:{Health}|Броня:{Armor}|Урон:{Damage}");
  149.     }
  150. }
  151.  
  152. class Orc : Fighter
  153. {
  154.     private int _orcRage = 0;
  155.  
  156.     public Orc(string name, int health, int armor, int damage) : base(name, health, armor, damage) { }
  157.  
  158.     public override void Strike(Fighter fighter)
  159.     {
  160.         base.Strike(fighter);
  161.         Waaagh();
  162.     }
  163.  
  164.     private void Waaagh()
  165.     {
  166.         int maximumValueRage = 10;
  167.         int multiplierDamage = 2;
  168.  
  169.         _orcRage++;
  170.  
  171.         if (_orcRage == maximumValueRage)
  172.         {
  173.             Damage *= multiplierDamage;
  174.             Console.WriteLine("Орк активирует WAAAAGH!!!");
  175.         }
  176.     }
  177. }
  178.  
  179. class Elf : Fighter
  180. {
  181.     private int _attackCounter = 0;
  182.     private int _damageFireboll = 50;
  183.     private int _mana;
  184.  
  185.     public Elf(string name, int health, int armor, int damage, int mana) : base(name, health, armor, damage)
  186.     {
  187.         _mana = mana;
  188.     }
  189.  
  190.     public override void Strike(Fighter fighter)
  191.     {
  192.         base.Strike(fighter);
  193.         Fireball(fighter);
  194.     }
  195.  
  196.     public void Fireball(Fighter fighter)
  197.     {
  198.         int divider = 3;
  199.         int subtractor = 25;
  200.  
  201.         _attackCounter++;
  202.        
  203.         if(_attackCounter % divider == 0)
  204.         {
  205.             _mana -= subtractor;
  206.  
  207.             if (_mana > 0)
  208.             {
  209.                 fighter.TakeDamage(_damageFireboll);
  210.                 Console.WriteLine("Эльф запускает Fireball!");
  211.             }
  212.         }
  213.     }
  214. }
  215.  
  216. class Dwarf : Fighter
  217. {
  218.     private Random _random = new Random();
  219.  
  220.     public Dwarf(string name, int health, int armor, int damage) : base(name, health, armor, damage) { }
  221.  
  222.     public override void Strike(Fighter fighter)
  223.     {
  224.         base.Strike(fighter);
  225.         ResentmentDwarf();
  226.     }
  227.  
  228.     public void ResentmentDwarf()
  229.     {
  230.         int maxRandom = 101;
  231.         int percent = 50;
  232.         int randomNumber = _random.Next(maxRandom);
  233.  
  234.         if (randomNumber <= percent)
  235.         {
  236.             Armor++;
  237.             Console.WriteLine("Гном улучшил броню на 1 еденицу!");
  238.         }
  239.     }
  240. }
  241.  
  242. class Human : Fighter
  243. {
  244.     private int _attackCounter = 0;
  245.     private int _maxHealth;
  246.     private int _healingValue = 50;
  247.  
  248.     public Human(string name, int health, int armor, int damage) : base(name, health, armor, damage)
  249.     {
  250.         _maxHealth = health;
  251.     }
  252.  
  253.     public override void Strike(Fighter fighter)
  254.     {
  255.         base.Strike(fighter);
  256.         SwordLight();
  257.     }
  258.  
  259.     public void SwordLight()
  260.     {
  261.         int divider = 3;
  262.  
  263.         _attackCounter++;
  264.  
  265.         if (_attackCounter % divider == 0)
  266.         {
  267.             if (Health + _healingValue  <= _maxHealth)
  268.             {
  269.                 Health += _healingValue;
  270.                 Console.WriteLine($"Человек восстанавливает {_healingValue} жизней!");
  271.             }
  272.         }  
  273.     }
  274. }
  275.  
  276. class Undead : Fighter
  277. {
  278.     private int _resurrectionsCount = 1;
  279.     private int _maxHealth;
  280.  
  281.     public Undead(string name, int health, int armor, int damage) : base(name, health, armor, damage)
  282.     {
  283.         _maxHealth = health;
  284.     }
  285.  
  286.     public override void Strike(Fighter fighter)
  287.     {
  288.         base.Strike(fighter);
  289.         RiseFromTheDead();
  290.     }
  291.  
  292.     public void RiseFromTheDead()
  293.     {
  294.         int healthMaxIndex = 100;
  295.  
  296.         if (Health <= healthMaxIndex)
  297.         {
  298.             if (_resurrectionsCount > 0)
  299.             {
  300.                 Health = _maxHealth;
  301.                 Console.WriteLine("Нежить возвращается на поле битвы!");
  302.                 _resurrectionsCount--;
  303.             }
  304.         }
  305.     }
  306. }
  307.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement