Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- internal class Program
- {
- //Создать 5 бойцов, пользователь выбирает 2 бойцов и они сражаются друг с другом до смерти. У каждого бойца могут быть свои статы.
- //Каждый игрок должен иметь особую способность для атаки, которая свойственна только его классу!
- static void Main(string[] args)
- {
- new Game().Start();
- }
- abstract class Warrior
- {
- public string Name { get; private set; }
- public int Health { get; private set; }
- public int Damage { get; private set; }
- public int Armor { get; private set; }
- public int Dodge { get; private set; }
- public Warrior(string name, int health, int damage, int armor, int dodge)
- {
- Name = name;
- Health = health;
- Damage = damage;
- Armor = armor;
- Dodge = dodge;
- }
- public abstract void ShowAbilityHero();
- public abstract int Atack();
- public void TakeDamage(int damage)
- {
- if (CalculateRandom())
- {
- int finalDamage = damage - Armor;
- if (finalDamage > 0)
- {
- Health -= finalDamage;
- Console.WriteLine($"{Name} получил {finalDamage} урона, Здоровье - {Health}");
- }
- }
- else
- {
- Console.WriteLine("ПРОМАХ.");
- }
- }
- public void ShowInfo()
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(Name);
- Console.ForegroundColor = ConsoleColor.Gray;
- Console.Write($" - Здоровье: {Health}, Урон: {Damage}, Броня: {Armor}, Уклон: {Dodge}%\nУникальность: ");
- ShowAbilityHero();
- }
- protected void TakeHealth(int health)
- {
- Health += health;
- }
- protected void TakeDodge(int dodge)
- {
- Dodge += dodge;
- }
- private bool CalculateRandom()
- {
- int minRandom = 0;
- int maxRandom = 101;
- return new Random().Next(minRandom, maxRandom) > Dodge;
- }
- }
- class Gladiator : Warrior
- {
- private int _boostDamage;
- private int _cooldownAbility;
- private int _timeCount;
- public Gladiator() : base("Гладиатор", 150, 15, 5, 10)
- {
- _boostDamage = 2;
- _cooldownAbility = 3;
- _timeCount = 0;
- }
- public override int Atack()
- {
- int damage;
- if (_timeCount == _cooldownAbility)
- {
- damage = Damage * _boostDamage;
- _timeCount = 0;
- }
- else
- {
- damage = Damage;
- _timeCount++;
- }
- return damage;
- }
- public override void ShowAbilityHero()
- {
- Console.WriteLine("Каждые " + _cooldownAbility + " раунда наносит двойной Урон.\n");
- }
- }
- class Assasin : Warrior
- {
- private int _multiplierCrit;
- public Assasin() : base("Ассасин", 100, 7, 2, 50)
- {
- _multiplierCrit = 5;
- }
- public override int Atack()
- {
- int damage;
- int minRandom = 1;
- int maxRandom = 4;
- Random random = new Random();
- int chanceCrit = random.Next(minRandom, maxRandom);
- if (chanceCrit == minRandom)
- {
- damage = Damage * _multiplierCrit;
- Console.Write(Name + " критует! ");
- }
- else
- {
- damage = Damage;
- }
- return damage;
- }
- public override void ShowAbilityHero()
- {
- Console.WriteLine($"С 33% шансом наносит х{_multiplierCrit} крит Урон.\n");
- }
- }
- class Barbarian : Warrior
- {
- private int _timeCount;
- private int _timeAction;
- private int _cooldownAbility;
- private int _boostDamage;
- public Barbarian() : base("Варвар", 125, 10, 0, 15)
- {
- _timeCount = 5;
- _timeAction = 3;
- _cooldownAbility = 5;
- _boostDamage = 25;
- }
- public override int Atack()
- {
- int damage;
- if (_timeCount == _cooldownAbility)
- {
- _timeCount = 0;
- }
- if (_timeCount < _timeAction)
- {
- damage = _boostDamage;
- _timeCount++;
- }
- else
- {
- damage = Damage;
- _timeCount++;
- }
- return damage;
- }
- public override void ShowAbilityHero()
- {
- Console.WriteLine($"Каждые {_cooldownAbility} раундов усиливает Урон на {_boostDamage} на {_timeAction} раунда.\n");
- }
- }
- class Troll : Warrior
- {
- private int _boostDamage;
- private int _boostDodge;
- private int _minHealth;
- private bool _isAlarm;
- public Troll() : base("Троль", 90, 10, 5, 10)
- {
- _boostDamage = 20;
- _boostDodge = 50;
- _minHealth = 60;
- _isAlarm = false;
- }
- public override int Atack()
- {
- int damage;
- if (Health < _minHealth && _isAlarm == false)
- {
- _isAlarm = true;
- TakeDodge(_boostDodge);
- }
- if (_isAlarm == true)
- {
- damage = Damage + _boostDamage;
- }
- else
- {
- damage = Damage;
- }
- return damage;
- }
- public override void ShowAbilityHero()
- {
- Console.WriteLine($"При снижении Здоровья до {_minHealth} увеличивает Уклон на {_boostDodge} и Урон на {_boostDamage} до конца боя.\n");
- }
- }
- class Vampire : Warrior
- {
- private int _takeLife;
- public Vampire() : base("Вампир", 100, 15, 0, 25)
- {
- _takeLife = 5;
- }
- public override int Atack()
- {
- TakeHealth(_takeLife);
- return Damage;
- }
- public override void ShowAbilityHero()
- {
- Console.WriteLine($"Каждый раунд увеличивает здоровье на {_takeLife}.\n");
- }
- }
- class Game
- {
- private Warrior _wariorOne = null;
- private Warrior _warriorTwo = null;
- private List<Warrior> _warriors = new List<Warrior>
- {
- new Gladiator(),
- new Assasin(),
- new Barbarian(),
- new Troll(),
- new Vampire()
- };
- public void Start()
- {
- int indexBlockedWarrior = 0;
- for (int i = 0; i < _warriors.Count; i++)
- {
- Console.Write(i + 1 + ". ");
- _warriors[i].ShowInfo();
- }
- Console.Write("Выбери себе воина: ");
- ChooseWarrior(ref _wariorOne,ref indexBlockedWarrior);
- Console.Write("Выбери противника: ");
- ChooseWarrior(ref _warriorTwo, ref indexBlockedWarrior);
- Fight();
- }
- private void ChooseWarrior(ref Warrior warrior, ref int indexBlockedWarrior)
- {
- while (warrior == null)
- {
- int indexWarrior = ReadInt(Console.ReadLine());
- if (indexWarrior == indexBlockedWarrior)
- {
- Console.WriteLine("Этот воин занят.");
- }
- else if (indexWarrior > 0 && indexWarrior <= _warriors.Count)
- {
- warrior = _warriors[indexWarrior - 1];
- indexBlockedWarrior = indexWarrior;
- Console.WriteLine("Выбран воин - " + warrior.Name + "\n");
- }
- else
- {
- Console.Write("Ошибка ввода! Повторите: ");
- }
- }
- }
- private void Fight()
- {
- bool inBattle = true;
- int round = 1;
- while (inBattle)
- {
- Console.Clear();
- Console.WriteLine("Раунд: " + round);
- Console.WriteLine(_wariorOne.Name + " Здоровье - " + _wariorOne.Health + " VS "
- + _warriorTwo.Name + " Здоровье - " + _warriorTwo.Health);
- Console.WriteLine();
- Console.ReadKey();
- if (_wariorOne.Health > 0 && _warriorTwo.Health > 0)
- {
- _warriorTwo.TakeDamage(_wariorOne.Atack());
- Console.ReadKey();
- _wariorOne.TakeDamage(_warriorTwo.Atack());
- Console.ReadKey();
- }
- if (_wariorOne.Health <= 0 || _warriorTwo.Health <= 0)
- {
- ShowResultFight();
- inBattle = false;
- }
- round++;
- }
- Console.ReadKey();
- }
- private void ShowResultFight()
- {
- if (_wariorOne.Health <= 0 && _warriorTwo.Health <= 0)
- {
- Console.WriteLine("Оба воина погибли!");
- }
- if (_wariorOne.Health <= 0)
- {
- Console.WriteLine(_wariorOne.Name + " ПРОИГРАЛ!");
- }
- else if (_warriorTwo.Health <= 0)
- {
- Console.WriteLine(_warriorTwo.Name + " ПРОИГРАЛ!");
- }
- }
- private int ReadInt(string convert)
- {
- bool success = int.TryParse(convert, out int number);
- while (success == false)
- {
- Console.Write("Ошибка конвертации, повторите ввод: ");
- success = int.TryParse(Console.ReadLine(), out number);
- }
- return number;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement