Advertisement
OldBeliver

UnnumberedHill_ver02

Jun 8th, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace UnnumberredHill_02
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             BattleField unnumberedHill = new BattleField();
  14.  
  15.             int taskNumber = 3;
  16.  
  17.             for (int i = 0; i < taskNumber; i++)
  18.             {
  19.                 unnumberedHill.Battle();
  20.                 Console.Clear();
  21.             }
  22.         }
  23.     }
  24.  
  25.     class BattleField
  26.     {
  27.         private HeadQuarter headQuarter = new HeadQuarter();
  28.         private Random rand = new Random();
  29.  
  30.         public void Battle()
  31.         {
  32.             int attackCounter = 0;
  33.             int attackLimit = 13;
  34.  
  35.             List<MilitaryMan> blueTeam = new List<MilitaryMan>();
  36.             blueTeam = headQuarter.CreateTeam();
  37.  
  38.             List<MilitaryMan> redTeam = new List<MilitaryMan>();
  39.             redTeam = headQuarter.CreateTeam();
  40.  
  41.             ViewFirstPartOfMilitaryOrder();
  42.  
  43.             headQuarter.ViewTeam(blueTeam);
  44.  
  45.             ViewSecondPartOfMilitaryOrder();
  46.             headQuarter.ViewTeam(redTeam);
  47.  
  48.             MoveUpIntoPosition();
  49.  
  50.             while (blueTeam.Count != 0 && redTeam.Count != 0)
  51.             {
  52.                 UseCombatSkill(blueTeam);
  53.                 UseCombatSkill(redTeam);
  54.  
  55.                 Console.WriteLine($"данные о командах\n");
  56.  
  57.                 Console.WriteLine($"синяя команда");
  58.                 headQuarter.ViewTeam(blueTeam);
  59.                 Console.WriteLine($"-----------------");
  60.                 Console.WriteLine();
  61.                 Console.WriteLine($"красная команда");
  62.                 headQuarter.ViewTeam(redTeam);
  63.  
  64.                 Console.WriteLine($"\nгрохот выстрелов разорвал тишину над безымянной высотой\nнажмите любую для продолжения");
  65.                 Console.ReadKey();
  66.                 Console.Clear();
  67.  
  68.                 Console.WriteLine($"ранения синей команды:");
  69.                 TradeBlows(redTeam, blueTeam);
  70.                 Console.WriteLine();
  71.                 Console.WriteLine($"ранения красной команды:");
  72.                 TradeBlows(blueTeam, redTeam);
  73.  
  74.                 Console.WriteLine($"\nпосле очередной атаки пришло время работы санитаров\n");
  75.  
  76.                 int quantity = 0;
  77.                 UseMedicalSkills(blueTeam);
  78.                 RemoveDadMan(blueTeam, out quantity);
  79.                 Console.WriteLine($"безвозвратные потери синей команды: {quantity}");
  80.                 Console.WriteLine();
  81.                 UseMedicalSkills(redTeam);
  82.                 RemoveDadMan(redTeam, out quantity);
  83.                 Console.WriteLine($"безвозвратные потери красной команды: {quantity}");
  84.  
  85.                 Console.ReadKey();
  86.                 Console.Clear();
  87.  
  88.                 attackCounter++;
  89.  
  90.                 if (attackCounter >= attackLimit)
  91.                 {
  92.                     Console.WriteLine($"Бойцы устали - {attackLimit} атак за спиной. Безымянная высота осталась ничьей");
  93.                     break;
  94.                 }
  95.                 else if (blueTeam.Count == 0 && redTeam.Count == 0)
  96.                 {
  97.                     Console.WriteLine($"остались все в земле сырой на безымянной высоте");
  98.                 }
  99.                 else if (blueTeam.Count == 0)
  100.                 {
  101.                     Console.WriteLine($"безымянная высота осталась за красной командой");
  102.                 }
  103.                 else if (redTeam.Count == 0)
  104.                 {
  105.                     Console.WriteLine($"безымянная высота осталась за синей командой");
  106.                 }
  107.             }
  108.             Console.WriteLine($"\nВойна никогда не заканчивается\nоткрыть новый пакет из штаба фронта");
  109.             Console.ReadKey();
  110.         }
  111.  
  112.         private void ViewFirstPartOfMilitaryOrder()
  113.         {
  114.             string splitbar = "--------------------------------------";
  115.             Console.WriteLine(splitbar);
  116.             Console.WriteLine($"| Приказ штаба фронта |");
  117.             Console.WriteLine(splitbar);
  118.             Console.WriteLine($"в рамках учений красной группе захватить и удерживать безымянную высоту до подхода основных сил,");
  119.             Console.WriteLine($"по данным войсковой разведки: в данный район выдвинулась синяя группа противника в составе:\n");
  120.         }
  121.  
  122.         private void ViewSecondPartOfMilitaryOrder()
  123.         {
  124.             Console.WriteLine($"\nнажмите любую, чтобы продолжить читать приказ\n");
  125.             Console.ReadKey();
  126.  
  127.             Console.WriteLine($"красной группе выдвинуться в заданный район через час после получения приказа,");
  128.             Console.WriteLine($"но не поздее N-часов, надцатого числа текущего месяца,\nв составе:\n");
  129.         }
  130.  
  131.         private void MoveUpIntoPosition()
  132.         {
  133.             Console.WriteLine($"\nнажмите любую для выдвижения группы в заданный квадрат ");
  134.             Console.ReadKey();
  135.             Console.Clear();
  136.  
  137.             if (rand.Next(0, 2) == 0)
  138.             {
  139.                 Console.WriteLine($"Ваша команда первой заняла высоту и приняла бой");
  140.             }
  141.             else
  142.             {
  143.                 Console.WriteLine($"Вы не успели занять высоту и начали разведку боем");
  144.             }
  145.  
  146.             Console.WriteLine($"\nнажмите любую для продолжения");
  147.             Console.ReadKey();
  148.             Console.Clear();
  149.         }
  150.  
  151.         private void UseCombatSkill(List<MilitaryMan> team)
  152.         {
  153.             for (int i = 0; i < team.Count; i++)
  154.             {
  155.                 team[i].UseCombatSkill();
  156.             }
  157.         }
  158.  
  159.         private void TradeBlows(List<MilitaryMan> attacker, List<MilitaryMan> defender)
  160.         {
  161.             for (int i = 0; i < attacker.Count; i++)
  162.             {
  163.                 int index = rand.Next(defender.Count);
  164.                 defender[index].TakeDamage(attacker[i].Damage);
  165.  
  166.                 Console.WriteLine($"боец №{index + 1} получил урон {defender[index].InjuryReceived}");
  167.             }
  168.         }
  169.  
  170.         private void RemoveDadMan(List<MilitaryMan> team, out int quantity)
  171.         {
  172.             quantity = 0;
  173.             for (int i = team.Count - 1; i >= 0; i--)
  174.             {
  175.                 if (team[i].Health <= 0)
  176.                 {
  177.                     team.RemoveAt(i);
  178.                     Console.WriteLine($"боец №{i + 1} убит");
  179.                     quantity++;
  180.                 }
  181.             }
  182.         }
  183.  
  184.         private void UseMedicalSkills(List<MilitaryMan> team)
  185.         {
  186.             for (int i = 0; i < team.Count; i++)
  187.             {
  188.                 team[i].UseMedicalSkill(team,  rand);
  189.             }
  190.         }
  191.     }
  192.  
  193.     class HeadQuarter
  194.     {
  195.         private Random rand = new Random();
  196.  
  197.         public List<MilitaryMan> CreateTeam()
  198.         {
  199.             List<MilitaryMan> team = new List<MilitaryMan>();
  200.  
  201.             int minSize = 6;
  202.             int maxSize = 9;
  203.             int size = rand.Next(minSize, maxSize + 1);
  204.             int caseNumber = 2;
  205.  
  206.             int lowerHealth = 10;
  207.             int upperHealth = 15;
  208.             int randomHealth;
  209.  
  210.             int lowerDamage = 2;
  211.             int upperDamage = 3;
  212.             int randomDamage;
  213.  
  214.             int soldierArmor = 1;
  215.             int medicArmor = 0;
  216.  
  217.             for (int i = 0; i < size; i++)
  218.             {
  219.                 randomHealth = rand.Next(lowerHealth, upperHealth + 1);
  220.                 randomDamage = rand.Next(lowerDamage, upperDamage + 1);
  221.  
  222.                 switch (rand.Next(1, caseNumber + 1))
  223.                 {
  224.                     case 1:
  225.                         team.Add(new Soldier(randomHealth, randomDamage, soldierArmor));
  226.                         break;
  227.                     case 2:
  228.                         team.Add(new Medic(randomHealth, randomDamage, medicArmor));
  229.                         break;
  230.                     default:
  231.                         Console.WriteLine($"число вне диапазона - проверьте переменную caseNumber");
  232.                         break;
  233.                 }
  234.             }
  235.             return team;
  236.         }
  237.  
  238.         public void ViewTeam(List<MilitaryMan> team)
  239.         {
  240.             Console.WriteLine($" №  род войск\tHP\tУрон\tБроня");
  241.             Console.WriteLine($"--------------------------------------");
  242.             for (int i = 0; i < team.Count; i++)
  243.             {
  244.                 Console.Write($"{i + 1:d2}. ");
  245.                 team[i].ShowStats();
  246.             }
  247.         }
  248.  
  249.     }
  250.  
  251.     abstract class MilitaryMan
  252.     {
  253.         public string Type { get; protected set; }
  254.         public int MaxHealth { get; protected set; }
  255.         public int Health { get; protected set; }
  256.         public int Damage { get; protected set; }
  257.         public int Armor { get; protected set; }
  258.         public int InjuryReceived { get; protected set; }
  259.  
  260.         public MilitaryMan(int health, int damage, int armor)
  261.         {
  262.             MaxHealth = health;
  263.             Health = MaxHealth;
  264.             Damage = damage;
  265.             Armor = armor;
  266.         }
  267.  
  268.         public void ShowStats()
  269.         {
  270.             Console.WriteLine($"{Type}\t{Health}\t  {Damage}\t  {Armor}");
  271.         }
  272.  
  273.         public void TakeDamage(int damage)
  274.         {
  275.             InjuryReceived = damage - Armor;
  276.  
  277.             if (InjuryReceived < 0)
  278.             {
  279.                 InjuryReceived = 0;
  280.             }
  281.  
  282.             Health -= InjuryReceived;
  283.         }
  284.  
  285.         public void TakeHeal()
  286.         {
  287.             Health += 3;
  288.  
  289.             if (Health > MaxHealth)
  290.             {
  291.                 Health = MaxHealth;
  292.             }
  293.         }
  294.  
  295.         public virtual void UseCombatSkill() { }
  296.         public virtual void UseMedicalSkill(List<MilitaryMan> team, Random rand) { }
  297.     }
  298.  
  299.     class Soldier : MilitaryMan
  300.     {
  301.         public Soldier(int health, int damage, int armor) : base(health, damage, armor)
  302.         {
  303.             Type = "рядовой";
  304.         }
  305.  
  306.         public override void UseCombatSkill()
  307.         {
  308.             int addition = 2;
  309.             Damage += addition;
  310.         }
  311.     }
  312.  
  313.     class Medic : MilitaryMan
  314.     {
  315.         public Medic(int health, int damage, int armor) : base(health, damage, armor)
  316.         {
  317.             Type = "военврач";
  318.         }
  319.  
  320.         public override void UseMedicalSkill(List<MilitaryMan> team, Random rand)
  321.         {
  322.             int index = rand.Next(team.Count);
  323.  
  324.             team[index].TakeHeal();
  325.             Console.WriteLine($"подлечили бойца № {index + 1}");
  326.         }
  327.     }
  328. }
  329.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement