Advertisement
Rodunskiy

Untitled

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