Advertisement
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 UnnumberredHill_02
- {
- class Program
- {
- static void Main(string[] args)
- {
- BattleField unnumberedHill = new BattleField();
- int taskNumber = 3;
- for (int i = 0; i < taskNumber; i++)
- {
- unnumberedHill.Battle();
- Console.Clear();
- }
- }
- }
- class BattleField
- {
- private HeadQuarter headQuarter = new HeadQuarter();
- private Random rand = new Random();
- public void Battle()
- {
- int attackCounter = 0;
- int attackLimit = 13;
- List<MilitaryMan> blueTeam = new List<MilitaryMan>();
- blueTeam = headQuarter.CreateTeam();
- List<MilitaryMan> redTeam = new List<MilitaryMan>();
- redTeam = headQuarter.CreateTeam();
- ViewFirstPartOfMilitaryOrder();
- headQuarter.ViewTeam(blueTeam);
- ViewSecondPartOfMilitaryOrder();
- headQuarter.ViewTeam(redTeam);
- MoveUpIntoPosition();
- while (blueTeam.Count != 0 && redTeam.Count != 0)
- {
- UseCombatSkill(blueTeam);
- UseCombatSkill(redTeam);
- Console.WriteLine($"данные о командах\n");
- Console.WriteLine($"синяя команда");
- headQuarter.ViewTeam(blueTeam);
- Console.WriteLine($"-----------------");
- Console.WriteLine();
- Console.WriteLine($"красная команда");
- headQuarter.ViewTeam(redTeam);
- Console.WriteLine($"\nгрохот выстрелов разорвал тишину над безымянной высотой\nнажмите любую для продолжения");
- Console.ReadKey();
- Console.Clear();
- Console.WriteLine($"ранения синей команды:");
- TradeBlows(redTeam, blueTeam);
- Console.WriteLine();
- Console.WriteLine($"ранения красной команды:");
- TradeBlows(blueTeam, redTeam);
- Console.WriteLine($"\nпосле очередной атаки пришло время работы санитаров\n");
- int quantity = 0;
- UseMedicalSkills(blueTeam);
- RemoveDadMan(blueTeam, out quantity);
- Console.WriteLine($"безвозвратные потери синей команды: {quantity}");
- Console.WriteLine();
- UseMedicalSkills(redTeam);
- RemoveDadMan(redTeam, out quantity);
- Console.WriteLine($"безвозвратные потери красной команды: {quantity}");
- Console.ReadKey();
- Console.Clear();
- attackCounter++;
- if (attackCounter >= attackLimit)
- {
- Console.WriteLine($"Бойцы устали - {attackLimit} атак за спиной. Безымянная высота осталась ничьей");
- break;
- }
- else if (blueTeam.Count == 0 && redTeam.Count == 0)
- {
- Console.WriteLine($"остались все в земле сырой на безымянной высоте");
- }
- else if (blueTeam.Count == 0)
- {
- Console.WriteLine($"безымянная высота осталась за красной командой");
- }
- else if (redTeam.Count == 0)
- {
- Console.WriteLine($"безымянная высота осталась за синей командой");
- }
- }
- Console.WriteLine($"\nВойна никогда не заканчивается\nоткрыть новый пакет из штаба фронта");
- Console.ReadKey();
- }
- private void ViewFirstPartOfMilitaryOrder()
- {
- string splitbar = "--------------------------------------";
- Console.WriteLine(splitbar);
- Console.WriteLine($"| Приказ штаба фронта |");
- Console.WriteLine(splitbar);
- Console.WriteLine($"в рамках учений красной группе захватить и удерживать безымянную высоту до подхода основных сил,");
- Console.WriteLine($"по данным войсковой разведки: в данный район выдвинулась синяя группа противника в составе:\n");
- }
- private void ViewSecondPartOfMilitaryOrder()
- {
- Console.WriteLine($"\nнажмите любую, чтобы продолжить читать приказ\n");
- Console.ReadKey();
- Console.WriteLine($"красной группе выдвинуться в заданный район через час после получения приказа,");
- Console.WriteLine($"но не поздее N-часов, надцатого числа текущего месяца,\nв составе:\n");
- }
- private void MoveUpIntoPosition()
- {
- Console.WriteLine($"\nнажмите любую для выдвижения группы в заданный квадрат ");
- Console.ReadKey();
- Console.Clear();
- if (rand.Next(0, 2) == 0)
- {
- Console.WriteLine($"Ваша команда первой заняла высоту и приняла бой");
- }
- else
- {
- Console.WriteLine($"Вы не успели занять высоту и начали разведку боем");
- }
- Console.WriteLine($"\nнажмите любую для продолжения");
- Console.ReadKey();
- Console.Clear();
- }
- private void UseCombatSkill(List<MilitaryMan> team)
- {
- for (int i = 0; i < team.Count; i++)
- {
- team[i].UseCombatSkill();
- }
- }
- private void TradeBlows(List<MilitaryMan> attacker, List<MilitaryMan> defender)
- {
- for (int i = 0; i < attacker.Count; i++)
- {
- int index = rand.Next(defender.Count);
- defender[index].TakeDamage(attacker[i].Damage);
- Console.WriteLine($"боец №{index + 1} получил урон {defender[index].InjuryReceived}");
- }
- }
- private void RemoveDadMan(List<MilitaryMan> team, out int quantity)
- {
- quantity = 0;
- for (int i = team.Count - 1; i >= 0; i--)
- {
- if (team[i].Health <= 0)
- {
- team.RemoveAt(i);
- Console.WriteLine($"боец №{i + 1} убит");
- quantity++;
- }
- }
- }
- private void UseMedicalSkills(List<MilitaryMan> team)
- {
- for (int i = 0; i < team.Count; i++)
- {
- team[i].UseMedicalSkill(team, rand);
- }
- }
- }
- class HeadQuarter
- {
- private Random rand = new Random();
- public List<MilitaryMan> CreateTeam()
- {
- List<MilitaryMan> team = new List<MilitaryMan>();
- int minSize = 6;
- int maxSize = 9;
- int size = rand.Next(minSize, maxSize + 1);
- int caseNumber = 2;
- int lowerHealth = 10;
- int upperHealth = 15;
- int randomHealth;
- int lowerDamage = 2;
- int upperDamage = 3;
- int randomDamage;
- int soldierArmor = 1;
- int medicArmor = 0;
- for (int i = 0; i < size; i++)
- {
- randomHealth = rand.Next(lowerHealth, upperHealth + 1);
- randomDamage = rand.Next(lowerDamage, upperDamage + 1);
- switch (rand.Next(1, caseNumber + 1))
- {
- case 1:
- team.Add(new Soldier(randomHealth, randomDamage, soldierArmor));
- break;
- case 2:
- team.Add(new Medic(randomHealth, randomDamage, medicArmor));
- break;
- default:
- Console.WriteLine($"число вне диапазона - проверьте переменную caseNumber");
- break;
- }
- }
- return team;
- }
- public void ViewTeam(List<MilitaryMan> team)
- {
- Console.WriteLine($" № род войск\tHP\tУрон\tБроня");
- Console.WriteLine($"--------------------------------------");
- for (int i = 0; i < team.Count; i++)
- {
- Console.Write($"{i + 1:d2}. ");
- team[i].ShowStats();
- }
- }
- }
- abstract class MilitaryMan
- {
- public string Type { get; protected set; }
- public int MaxHealth { get; protected set; }
- public int Health { get; protected set; }
- public int Damage { get; protected set; }
- public int Armor { get; protected set; }
- public int InjuryReceived { get; protected set; }
- public MilitaryMan(int health, int damage, int armor)
- {
- MaxHealth = health;
- Health = MaxHealth;
- Damage = damage;
- Armor = armor;
- }
- public void ShowStats()
- {
- Console.WriteLine($"{Type}\t{Health}\t {Damage}\t {Armor}");
- }
- public void TakeDamage(int damage)
- {
- InjuryReceived = damage - Armor;
- if (InjuryReceived < 0)
- {
- InjuryReceived = 0;
- }
- Health -= InjuryReceived;
- }
- public void TakeHeal()
- {
- Health += 3;
- if (Health > MaxHealth)
- {
- Health = MaxHealth;
- }
- }
- public virtual void UseCombatSkill() { }
- public virtual void UseMedicalSkill(List<MilitaryMan> team, Random rand) { }
- }
- class Soldier : MilitaryMan
- {
- public Soldier(int health, int damage, int armor) : base(health, damage, armor)
- {
- Type = "рядовой";
- }
- public override void UseCombatSkill()
- {
- int addition = 2;
- Damage += addition;
- }
- }
- class Medic : MilitaryMan
- {
- public Medic(int health, int damage, int armor) : base(health, damage, armor)
- {
- Type = "военврач";
- }
- public override void UseMedicalSkill(List<MilitaryMan> team, Random rand)
- {
- int index = rand.Next(team.Count);
- team[index].TakeHeal();
- Console.WriteLine($"подлечили бойца № {index + 1}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement