Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace War
- {
- class Program
- {
- static void Main(string[] args)
- {
- War war = new War();
- war.FormPlatoons();
- war.Fight();
- war.ShowWinner();
- }
- }
- class War
- {
- private int _firstPlatoonsSize = 3;
- private int _secondPlatoonsSize = 3;
- private Platoon _firstPlatoon;
- private Platoon _secondPlatoon;
- public void FormPlatoons()
- {
- _firstPlatoon = new Platoon(_firstPlatoonsSize, "Великобритания");
- _secondPlatoon = new Platoon(_secondPlatoonsSize, "США");
- }
- public void Fight()
- {
- while(_firstPlatoon.IsCombatReady && _secondPlatoon.IsCombatReady)
- {
- Strike();
- RemoveDied();
- }
- }
- public void Strike()
- {
- Console.WriteLine("");
- _firstPlatoon.Attack(_secondPlatoon);
- _secondPlatoon.Attack(_firstPlatoon);
- }
- public void RemoveDied()
- {
- _firstPlatoon.RemoveDied();
- _secondPlatoon.RemoveDied();
- }
- public void ShowWinner()
- {
- if (_firstPlatoon.IsCombatReady)
- Console.WriteLine($"Победил взвод страны {_firstPlatoon.Country}");
- else if (_secondPlatoon.IsCombatReady)
- Console.WriteLine($"Победил взвод страны {_secondPlatoon.Country}");
- else
- Console.WriteLine("Все умерли");
- }
- }
- class Soldier
- {
- private static Random _random;
- private int _featureMultiplyer = 2;
- private int _minDamage = 30;
- private int _maxDamage = 50;
- private int _minHealth = 100;
- private int _maxHealth = 120;
- private int _minArmor = 10;
- private int _maxArmor = 15;
- static Soldier()
- {
- _random = new Random();
- }
- public Soldier()
- {
- int variants = Enum.GetValues(typeof(Feature)).Length;
- Feature feature = (Feature)_random.Next(variants);
- Damage = _random.Next(_minDamage, _maxDamage);
- Health = _random.Next(_minHealth, _maxHealth);
- Armor = _random.Next(_minArmor, _maxArmor);
- switch(feature)
- {
- case Feature.StrengthenedDamage:
- Damage *= _featureMultiplyer;
- break;
- case Feature.StrengthenedHealth:
- Health *= _featureMultiplyer;
- break;
- case Feature.StrengthenedArmor:
- Armor *= _featureMultiplyer;
- break;
- }
- }
- enum Feature
- {
- StrengthenedDamage = 0,
- StrengthenedHealth = 1,
- StrengthenedArmor = 2
- }
- public int Damage { get; private set; }
- public int Health { get; private set; }
- public int Armor { get; private set; }
- public bool IsAlive => Health > 0;
- public void TakeDamage(int residualDamage)
- {
- Health -= residualDamage;
- }
- public void Attack(Soldier soldier)
- {
- int residualDamage = Damage < soldier.Armor ? 0 : Damage - soldier.Armor;
- soldier.TakeDamage(residualDamage);
- }
- public string ShowStats()
- {
- return string.Format($"Атака: {Damage}, Здоровье: {Health}, Броня: {Armor}");
- }
- }
- class Platoon
- {
- private Soldier _fightingSoldier;
- private Stack<Soldier> _soldiers = new Stack<Soldier>();
- public Platoon(int soldiersCount, string country)
- {
- Country = country;
- for (int i = 0; i < soldiersCount; i++)
- _soldiers.Push(new Soldier());
- }
- public string Country { get; private set; }
- public bool IsCombatReady => _soldiers.Count != 0;
- public void RemoveDied()
- {
- if (_fightingSoldier.IsAlive == false)
- {
- ConsoleColor defaultColor = Console.ForegroundColor;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine($"Взвод страны {Country} потерял бойца");
- Console.ForegroundColor = defaultColor;
- _fightingSoldier = null;
- _soldiers.Pop();
- }
- }
- public Soldier GetSoldier()
- {
- if (_fightingSoldier == null)
- {
- _fightingSoldier = _soldiers.Peek();
- Console.WriteLine($"В сражение вступает боец страны {Country} с характеристиками: {_fightingSoldier.ShowStats()}");
- }
- return _fightingSoldier;
- }
- public void Attack(Platoon enemyPlatoon)
- {
- Soldier enemy = enemyPlatoon.GetSoldier();
- GetSoldier().Attack(enemy);
- Console.WriteLine($"Боец страны {enemyPlatoon.Country} получает ранение. Здоровье {enemy.Health}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement