Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Threading;
- class Program
- {
- static void Main(string[] args)
- {
- Arena arena = new Arena();
- arena.StartGame();
- }
- }
- class Arena
- {
- public void StartGame()
- {
- Warrior firstWarrior;
- Warrior secondWarrior;
- Console.WriteLine("\tДобро пожаловать на арену \"Team Fortress 2\".");
- Console.WriteLine("\nВыберите первого бойца.");
- firstWarrior = SelectWarrior();
- Console.WriteLine("\nВыберите второго бойца.");
- secondWarrior = SelectWarrior();
- Console.WriteLine("Да начнётся бой!\n");
- System.Threading.Thread.Sleep(1000);
- Fight(firstWarrior, secondWarrior);
- }
- private Warrior SelectWarrior()
- {
- bool isSelectedWarrior = false;
- Warrior warrior = null;
- Warrior[] warriors =
- {
- new Soldier ("Солдат", 200, 50, 2),
- new HeavyWarrior ("Хейви", 300, 25, 4),
- new Sniper ("Снайпер", 125, 105, 0),
- new Demoman ("Демоман", 185, 70, 2),
- new Scout ("Скаут", 125, 10, 1),
- };
- ShowAllWarriors(warriors);
- while (isSelectedWarrior == false)
- {
- int.TryParse(Console.ReadLine(), out int userWarriorSellected);
- isSelectedWarrior = userWarriorSellected > 0 && userWarriorSellected <= warriors.Length;
- if (isSelectedWarrior)
- {
- warrior = warriors[userWarriorSellected - 1];
- }
- else
- {
- Console.Write("\aТакого бойца в списке нет, или нужно вводить число. Попробуйте еще раз: ");
- }
- }
- return warrior;
- }
- private void ShowAllWarriors(Warrior[] warriors)
- {
- int counter = 1;
- Console.WriteLine("\n Список персонажей:");
- foreach (Warrior warrior in warriors)
- {
- Console.Write(counter + " ");
- warrior.ShowStats();
- counter++;
- }
- }
- private bool TryPickingWinner(Warrior firstWarrior, Warrior secondWarrior)
- {
- if (secondWarrior.Health <= 0 && firstWarrior.Health > 0)
- {
- Console.WriteLine($"\nПобедил {firstWarrior.Name}! Поздравляем победителя!");
- return true;
- }
- else if (firstWarrior.Health <= 0 && secondWarrior.Health > 0)
- {
- Console.WriteLine($"\nПобедил {secondWarrior.Name}! Поздравляем победителя!");
- return true;
- }
- else if (firstWarrior.Health <= 0 && secondWarrior.Health <= 0)
- {
- Console.WriteLine("Погибли оба бойца. Победителей нет.");
- return true;
- }
- return false;
- }
- private void Fight(Warrior firstWarrior, Warrior secondWarrior)
- {
- bool isEndFight = false;
- while (isEndFight == false)
- {
- firstWarrior.Attack(secondWarrior);
- secondWarrior.Attack(firstWarrior);
- firstWarrior.ShowCurrentHealth();
- secondWarrior.ShowCurrentHealth();
- System.Threading.Thread.Sleep(500);
- Console.WriteLine();
- isEndFight = TryPickingWinner(firstWarrior, secondWarrior);
- }
- }
- }
- abstract class Warrior
- {
- protected int Damage;
- private int _defence;
- private Random _random = new Random();
- public Warrior(string name, int health, int damage, int defence)
- {
- Name = name;
- Health = health;
- Damage = damage;
- _defence = defence;
- }
- public string Name { get; protected set; }
- public int Health { get; protected set; }
- public virtual void TakeDamage(int damage)
- {
- if ((damage - _defence) > 0)
- Health -= damage - _defence;
- }
- public virtual void Attack(Warrior warrior)
- {
- warrior.TakeDamage(Damage);
- }
- public void ShowCurrentHealth()
- {
- Console.WriteLine($"{Name} здоровье: {Health}");
- }
- public void ShowStats()
- {
- Console.WriteLine($"{Name}: Здоровье - {Health}, Урон - {Damage}, Броня - {_defence}");
- }
- protected bool CanToUseSkill(int deltaChanceSuccess = 0)
- {
- int minimumValue = 0;
- int maximumValue = 101;
- int defaultChanceSuccess = 20;
- return _random.Next(minimumValue, maximumValue) <= defaultChanceSuccess + deltaChanceSuccess;
- }
- }
- class Soldier : Warrior
- {
- public Soldier(string name, int health, int damage, int defence) : base(name, health, damage, defence) { }
- public override void Attack(Warrior warrior)
- {
- float multiplyingFactor = 2.5F;
- int deltaChanceSuccess = 10;
- int takeDamageFromYourShots = 50;
- if (CanToUseSkill(deltaChanceSuccess))
- {
- warrior.TakeDamage(Convert.ToInt32(Damage * multiplyingFactor));
- Health -= takeDamageFromYourShots;
- }
- else
- {
- base.Attack(warrior);
- }
- }
- }
- class HeavyWarrior : Warrior
- {
- public HeavyWarrior(string name, int health, int damage, int defence) : base(name, health, damage, defence) { }
- public override void Attack(Warrior warrior)
- {
- int defaultChanceSuccess = -10;
- int recoveryHealth = 50;
- if (CanToUseSkill(defaultChanceSuccess))
- Health += recoveryHealth;
- base.Attack(warrior);
- }
- }
- class Sniper : Warrior
- {
- public Sniper(string name, int health, int damage, int defence) : base(name, health, damage, defence) { }
- public override void Attack(Warrior warrior)
- {
- float multiplyingFactor = 1.8F;
- int deltaChanceSuccess = 5;
- if (CanToUseSkill(deltaChanceSuccess))
- warrior.TakeDamage(Convert.ToInt32(Damage * multiplyingFactor));
- else
- base.Attack(warrior);
- }
- }
- class Demoman : Warrior
- {
- private int _gunReloading;
- public Demoman(string name, int health, int damage, int defence, int _gunReloading = 0) : base(name, health, damage, defence) { }
- public override void Attack(Warrior warrior)
- {
- int deltaChanceSuccess = 30;
- int coldownGunReloadingInTurns = 3;
- if (_gunReloading > 0)
- _gunReloading--;
- if (CanToUseSkill(deltaChanceSuccess) && _gunReloading == 0)
- {
- warrior.TakeDamage(Damage);
- warrior.TakeDamage(Damage);
- _gunReloading = coldownGunReloadingInTurns;
- }
- else
- {
- Console.WriteLine(Name + " не смог выстрелить, кроме того осталось еще " + _gunReloading + " ходов перезарядки.");
- }
- }
- }
- class Scout : Warrior
- {
- public Scout(string name, int health, int damage, int defence) : base(name, health, damage, defence) { }
- public override void TakeDamage(int damage)
- {
- int deltaChanceSuccess = 50;
- if (CanToUseSkill(deltaChanceSuccess))
- {
- Console.WriteLine(Name + " увернулся от удара.");
- }
- else
- {
- base.TakeDamage(damage);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement