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 CSLight
- {
- class Program
- {
- static void Main(string[] args)
- {
- Battle battle = new Battle();
- battle.Start();
- Console.ReadKey();
- }
- }
- class Battle
- {
- private Random _rand;
- private Troop _firstTroop;
- private Troop _secondTroop;
- public Battle()
- {
- _rand = new Random();
- _firstTroop = new Troop();
- _secondTroop = new Troop();
- }
- public void Start()
- {
- while (GetTroopStatus(_firstTroop) && GetTroopStatus(_secondTroop))
- {
- Console.WriteLine("\n\nПервый отряд:");
- _firstTroop.ShowAllStats();
- Simulate(_secondTroop, _firstTroop);
- _firstTroop.CleanBattleground();
- Console.WriteLine("\n\nВторой отряд:");
- _secondTroop.ShowAllStats();
- Simulate(_firstTroop, _secondTroop);
- _secondTroop.CleanBattleground();
- }
- Console.WriteLine($"\n\nКонец симуляции");
- }
- private bool GetTroopStatus(Troop troop)
- {
- return troop.Count() > 0;
- }
- private void Simulate(Troop attackTroops, Troop defenceTroops)
- {
- int targetId;
- for (int i = 0; i < attackTroops.Count(); i++)
- {
- targetId = _rand.Next(0, defenceTroops.Count());
- defenceTroops.TakeDamage(targetId, attackTroops.GetDamageThroughId(i));
- }
- }
- }
- class Troop
- {
- private Random _rand = new Random();
- private List<Warrior> _troops = new List<Warrior>();
- public Troop()
- {
- int warriorsCount = _rand.Next(25, 36);
- for (int i = 0; i < warriorsCount; i++)
- {
- if (i % 2 == 0)
- _troops.Add(new ShotGunner(90, 20, 5));
- if (i % 4 == 0)
- _troops.Add(new MachineGunner(200, 8, 1.2));
- if (i % 5 == 0)
- _troops.Add(new Sniper(70, 30));
- }
- }
- public void CleanBattleground()
- {
- for (int i = 0; i < _troops.Count; i++)
- if (_troops[i].Health <= 0)
- {
- _troops.RemoveAt(i);
- i -= 1;
- }
- }
- public void TakeDamage(int id, double damage)
- {
- _troops[id].TakeDamage(damage);
- }
- public int Count()
- {
- return _troops.Count;
- }
- public double GetDamageThroughId(int id)
- {
- return _troops[id].Damage;
- }
- public double GetHealthThroughId(int id)
- {
- return _troops[id].Health;
- }
- public void ShowAllStats()
- {
- for (int i = 0; i < 3; i++)
- {
- if (i == 0)
- ShowTroopStats(_troops, "shortgun");
- if (i == 1)
- ShowTroopStats(_troops, "machinegun");
- if (i == 2)
- ShowTroopStats(_troops, "sniper");
- }
- }
- private void ShowTroopStats(List<Warrior> troops, string classId)
- {
- Console.WriteLine();
- foreach (var warrior in troops)
- if (warrior.ClassId == classId)
- Console.WriteLine($"Здоровье - {(int)warrior.Health}, Урон - {(int)warrior.Damage}");
- Console.WriteLine();
- }
- }
- class Warrior
- {
- protected Random Rand = new Random();
- public string ClassId { get; protected set; }
- public double Health { get; protected set; }
- public double Damage { get; protected set; }
- public Warrior(double health, double damage)
- {
- Health = health;
- Damage = damage;
- }
- public virtual void TakeDamage(double damage)
- {
- Health -= damage;
- }
- }
- class MachineGunner : Warrior
- {
- private double _fireRate;
- public MachineGunner(double health, double damage, double fireRate) : base(health, damage)
- {
- _fireRate = fireRate;
- ClassId = "machinegun";
- }
- public override void TakeDamage(double damage)
- {
- base.TakeDamage(damage);
- ChangeDamage();
- }
- public void ChangeDamage()
- {
- Damage *= _fireRate;
- }
- }
- class Sniper : Warrior
- {
- private double _baseDamage;
- public Sniper(double health, double damage) : base (health, damage)
- {
- _baseDamage = damage;
- ClassId = "sniper";
- }
- public override void TakeDamage(double damage)
- {
- base.TakeDamage(damage);
- ChangeDamage();
- }
- private void ChangeDamage()
- {
- if (Damage == _baseDamage)
- {
- int probability = Rand.Next(0, 3);
- if (probability == 1)
- Damage *= 3;
- }
- else
- {
- Damage /= 3;
- }
- }
- }
- class ShotGunner : Warrior
- {
- private double _cureSpeed;
- public ShotGunner(double health, double damage, double cureSpeed) : base(health, damage)
- {
- _cureSpeed = cureSpeed;
- ClassId = "shortgun";
- }
- public override void TakeDamage(double damage)
- {
- base.TakeDamage(damage);
- Health += _cureSpeed;
- }
- }
- }
Add Comment
Please, Sign In to add comment