Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Task47._1
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- BattleField battleField = new BattleField();
- Console.WriteLine("Добро пожаловать бог войн, дабы угодить вам срана организует битву взводов, для начала нажмите Enter или любую кнопку.");
- Console.ReadKey();
- battleField.Battle();
- battleField.ShowResult();
- }
- }
- class BattleField
- {
- private Random _random = new Random();
- private List<Soldier> _platoonFist = new List<Soldier>();
- private List<Soldier> _platoonSecond = new List<Soldier>();
- private Soldier _soldierFirst;
- private Soldier _soldierSecond;
- public BattleField()
- {
- int minCountSoldierPlatoon = 15;
- int maxCountSoldierPlatoon = 60;
- int countSoldierPlatoon = _random.Next(minCountSoldierPlatoon, maxCountSoldierPlatoon);
- CreatePlatoon(countSoldierPlatoon, _platoonFist);
- CreatePlatoon(countSoldierPlatoon, _platoonSecond);
- }
- public void Battle()
- {
- string fisrPlatoon =
- "Взвод первой страны: ";
- string secondPlatoon =
- "Взвод второй страны: ";
- while (_platoonFist.Count > 0 && _platoonSecond.Count > 0)
- {
- _soldierFirst = _platoonFist[_random.Next(0, _platoonFist.Count)];
- _soldierSecond = _platoonSecond[_random.Next(0, _platoonSecond.Count)];
- Console.WriteLine(fisrPlatoon);
- ShowSoldierPlatoon(_platoonFist);
- Console.WriteLine(secondPlatoon);
- ShowSoldierPlatoon(_platoonSecond);
- _soldierFirst.TakeDamege(_soldierSecond.Damage);
- _soldierSecond.TakeDamege(_soldierFirst.Damage);
- _soldierFirst.UseSpecialCriticalDamage();
- _soldierSecond.UseSpecialCriticalDamage();
- RemoveSoldier();
- System.Threading.Thread.Sleep(100);
- Console.Clear();
- }
- }
- public void ShowResult()
- {
- string tie =
- "Ничья, оба взвода погибли.";
- string winFirst =
- "Взвод 1-ой страны победил!";
- string winSecond =
- "Взвод 2-ой страны победил!";
- if (_platoonFist.Count > 0 && _platoonSecond.Count > 0)
- {
- Console.WriteLine(tie);
- }
- else if (_platoonFist.Count <= 0)
- {
- Console.WriteLine(winFirst);
- }
- else if (_platoonSecond.Count <= 0)
- {
- Console.WriteLine(winSecond);
- }
- }
- private void RemoveSoldier()
- {
- if (_soldierFirst.Health <= 0)
- {
- _platoonFist.Remove(_soldierFirst);
- }
- if (_soldierSecond.Health <= 0)
- {
- _platoonSecond.Remove(_soldierSecond);
- }
- }
- private void ShowSoldierPlatoon(List<Soldier> soldiers)
- {
- foreach (var soldier in soldiers)
- {
- Console.WriteLine(
- $"=============================\n" +
- $"{soldier.Name}\n" +
- $"Здоровье: {soldier.Health}\n" +
- $"Урон: {soldier.Damage}\n" +
- $"Броня: {soldier.Armor}\n" +
- $"=============================");
- }
- }
- private void CreatePlatoon(int numberSoldiers, List<Soldier> soldiers)
- {
- for (int i = 0; i < numberSoldiers; i++)
- {
- soldiers.Add(GetSoldier());
- }
- }
- private Soldier GetSoldier()
- {
- int minNumberClassSoldier = 0;
- int maxNumberClassSoldier = 4;
- int soldierClass = _random.Next(minNumberClassSoldier, maxNumberClassSoldier);
- if (soldierClass == 0)
- {
- return new Stormtrooper("Штурмовик", 150, 80, 25);
- }
- else if (soldierClass == 1)
- {
- return new MachineGunner("Пулемётчик", 400, 35, 80);
- }
- else if (soldierClass == 2)
- {
- return new Medic("Медик", 100, 50, 20);
- }
- else if (soldierClass == 3)
- {
- return new Enginier("Инженер", 125, 45,15);
- }
- else
- {
- return new Sniper("Снайпер", 60, 120,10);
- }
- }
- }
- class Soldier
- {
- public string Name { get; protected set; }
- public float Health { get; protected set; }
- public float Damage { get; protected set; }
- public float Armor { get; protected set; }
- public Soldier(string name, float health, float damage, float armor)
- {
- Name = name;
- Health = health;
- Damage = damage;
- Armor = armor;
- }
- public void TakeDamege(float damageSoldier)
- {
- Health -= damageSoldier * (100 - Armor) / 100;
- Console.WriteLine($"{Name} нанёс {damageSoldier} урона");
- }
- public void UseSpecialCriticalDamage()
- {
- Random random = new Random();
- int rangeMaxNumbersChanceUsingAbility = 2543;
- int chanceUseSpecialCriticalDamage = random.Next(rangeMaxNumbersChanceUsingAbility);
- int chanceCriticalDamage = 250;
- if (chanceUseSpecialCriticalDamage < chanceCriticalDamage)
- {
- UseCriticalDamage();
- }
- }
- protected virtual void UseCriticalDamage() { }
- }
- class Stormtrooper : Soldier
- {
- private float _damageBuff = 0.15f;
- private float _armorBuff = 0.25f;
- public Stormtrooper(string name, float health, float damage, float armor) : base(name, health, damage, armor) { }
- protected override void UseCriticalDamage()
- {
- Console.WriteLine($"{Name} яросно кричит и идёт в атаку");
- Damage += Damage * _damageBuff;
- Armor += Armor * _armorBuff;
- }
- }
- class MachineGunner : Soldier
- {
- private float _damageBuff = 0.5f;
- public MachineGunner(string name, float health, float damage, float armor) : base(name, health, damage, armor) { }
- protected override void UseCriticalDamage()
- {
- Console.WriteLine($"{Name} достаёт второй пулемёт и начинает стрелять из двух рук.");
- Damage += Damage * _damageBuff;
- }
- }
- class Medic : Soldier
- {
- private float _damageBuff = 0.05f;
- private float _healthBuff = 0.4f;
- public Medic(string name, float health, float damage, float armor) : base(name, health, damage, armor) { }
- protected override void UseCriticalDamage()
- {
- Console.WriteLine($"{Name} вколол укол адреналина и повысил на время здоровье и немного урона");
- Damage += Damage * _damageBuff;
- Health += Health * _healthBuff;
- }
- }
- class Enginier : Soldier
- {
- private float _armorBuff = 0.5f;
- public Enginier(string name, float health, float damage, float armor) : base(name, health, damage, armor) { }
- protected override void UseCriticalDamage()
- {
- Console.WriteLine($"{Name} включает активную защиту своего костюма");
- Armor += Armor * _armorBuff;
- }
- }
- class Sniper : Soldier
- {
- private float _damageBuff = 0.25f;
- private float _armorBuff = 1;
- public Sniper(string name, float health, float damage, float armor) : base(name, health, damage, armor) { }
- protected override void UseCriticalDamage()
- {
- Console.WriteLine($"{Name} сливается с местностью вдыхает и стреляет бронибойным патроном");
- Damage += Damage * _damageBuff;
- Armor += Armor * _armorBuff;
- }
- }
- }
Add Comment
Please, Sign In to add comment