Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Program
- {
- static void Main(string[] args)
- {
- Battlefield battlefield = new Battlefield();
- if (battlefield.TryCreativeBattle())
- {
- battlefield.Battle();
- battlefield.ShowBattleResult();
- }
- }
- }
- class Battlefield
- {
- private Fighter _fighter1;
- private Fighter _fighter2;
- private List<Fighter> _fighters = new List<Fighter>();
- public Battlefield()
- {
- _fighters.Add(new Orc("Orc", 1000, 30, 100));
- _fighters.Add(new Elf("Elf", 1000, 40, 100, 100));
- _fighters.Add(new Dwarf("Dwarf", 1000, 60, 90));
- _fighters.Add(new Human("Human", 1000, 50, 100));
- _fighters.Add(new Undead("Undead", 700, 30, 80));
- _fighter1 = SelectFighter();
- _fighter2 = SelectFighter();
- }
- public Fighter SelectFighter()
- {
- Fighter fighter = null;
- string userInput;
- Console.WriteLine("Выберите двух бойцов для поединка:");
- ShowInfo();
- userInput = Console.ReadLine();
- foreach (var item in _fighters)
- {
- if(item.Name == userInput)
- {
- fighter = item;
- _fighters.Remove(fighter);
- break;
- }
- }
- return fighter;
- }
- public bool TryCreativeBattle()
- {
- if (_fighter1 == null || _fighter2 == null)
- {
- Console.WriteLine("Ошибка выбора бойца");
- return false;
- }
- else
- {
- Console.WriteLine("Бойцы выбраны! Нажмите любую клавишу чтобы начать бой.");
- Console.ReadKey();
- Console.Clear();
- return true;
- }
- }
- public void Battle()
- {
- while (_fighter1.IsAlive && _fighter2.IsAlive)
- {
- _fighter1.ShowStats();
- _fighter2.ShowStats();
- _fighter1.Strike(_fighter2);
- _fighter2.Strike(_fighter1);
- Console.ReadKey();
- Console.Clear();
- }
- }
- public void ShowBattleResult()
- {
- if (_fighter1.IsDead && _fighter2.IsDead)
- {
- Console.WriteLine("Оба бойца погибли.");
- }
- else if (_fighter1.IsDead)
- {
- Console.WriteLine($"{_fighter2.Name} побеждает.");
- }
- else if (_fighter2.IsDead)
- {
- Console.WriteLine($"{_fighter1.Name} побеждает.");
- }
- }
- public void ShowInfo()
- {
- foreach (var fighter in _fighters)
- {
- fighter.ShowStats();
- }
- }
- }
- class Fighter
- {
- protected int Damage;
- protected float Armor;
- protected float Health;
- public Fighter (string name, float health, float armor, int damage)
- {
- Name = name;
- Health = health;
- Armor = armor;
- Damage = damage;
- }
- public bool IsDead => Health <= 0;
- public bool IsAlive => Health > 0;
- public string Name { get; private set; }
- public virtual void Strike(Fighter fighter) => fighter.TakeDamage(Damage);
- public void TakeDamage(float damage)
- {
- int divider = 100;
- Health -= damage * (1 - (Armor / divider));
- }
- public void ShowStats()
- {
- Console.WriteLine($"{Name}|Жизни:{Health}|Броня:{Armor}|Урон:{Damage}");
- }
- }
- class Orc : Fighter
- {
- private int _orcRage = 0;
- public Orc(string name, int health, int armor, int damage) : base(name, health, armor, damage) { }
- public override void Strike(Fighter fighter)
- {
- base.Strike(fighter);
- Waaagh();
- }
- private void Waaagh()
- {
- int maximumValueRage = 10;
- int multiplierDamage = 2;
- _orcRage++;
- if (_orcRage == maximumValueRage)
- {
- Damage *= multiplierDamage;
- Console.WriteLine("Орк активирует WAAAAGH!!!");
- }
- }
- }
- class Elf : Fighter
- {
- private int _attackCounter = 0;
- private int _damageFireboll = 50;
- private int _mana;
- public Elf(string name, int health, int armor, int damage, int mana) : base(name, health, armor, damage)
- {
- _mana = mana;
- }
- public override void Strike(Fighter fighter)
- {
- base.Strike(fighter);
- Fireball(fighter);
- }
- public void Fireball(Fighter fighter)
- {
- int divider = 3;
- int subtractor = 25;
- _attackCounter++;
- if(_attackCounter % divider == 0)
- {
- _mana -= subtractor;
- if (_mana > 0)
- {
- fighter.TakeDamage(_damageFireboll);
- Console.WriteLine("Эльф запускает Fireball!");
- }
- }
- }
- }
- class Dwarf : Fighter
- {
- private Random _random = new Random();
- public Dwarf(string name, int health, int armor, int damage) : base(name, health, armor, damage) { }
- public override void Strike(Fighter fighter)
- {
- base.Strike(fighter);
- ResentmentDwarf();
- }
- public void ResentmentDwarf()
- {
- int maxRandom = 101;
- int percent = 50;
- int randomNumber = _random.Next(maxRandom);
- if (randomNumber <= percent)
- {
- Armor++;
- Console.WriteLine("Гном улучшил броню на 1 еденицу!");
- }
- }
- }
- class Human : Fighter
- {
- private int _attackCounter = 0;
- private int _maxHealth;
- private int _healingValue = 50;
- public Human(string name, int health, int armor, int damage) : base(name, health, armor, damage)
- {
- _maxHealth = health;
- }
- public override void Strike(Fighter fighter)
- {
- base.Strike(fighter);
- SwordLight();
- }
- public void SwordLight()
- {
- int divider = 3;
- _attackCounter++;
- if (_attackCounter % divider == 0)
- {
- if (Health + _healingValue <= _maxHealth)
- {
- Health += _healingValue;
- Console.WriteLine($"Человек восстанавливает {_healingValue} жизней!");
- }
- }
- }
- }
- class Undead : Fighter
- {
- private int _resurrectionsCount = 1;
- private int _maxHealth;
- public Undead(string name, int health, int armor, int damage) : base(name, health, armor, damage)
- {
- _maxHealth = health;
- }
- public override void Strike(Fighter fighter)
- {
- base.Strike(fighter);
- RiseFromTheDead();
- }
- public void RiseFromTheDead()
- {
- int healthMaxIndex = 100;
- if (Health <= healthMaxIndex)
- {
- if (_resurrectionsCount > 0)
- {
- Health = _maxHealth;
- Console.WriteLine("Нежить возвращается на поле битвы!");
- _resurrectionsCount--;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement