OldBeliver

GladiatorsGames_ver01

May 18th, 2021 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.78 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 GladiatorGames
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Arena arena = new Arena();
  14.             arena.Work();
  15.         }
  16.     }
  17.  
  18.     class Arena
  19.     {
  20.         private List<Gladiator> _gladiators;
  21.  
  22.         public Arena()
  23.         {
  24.             _gladiators = new List<Gladiator>();
  25.         }
  26.  
  27.         public void Work()
  28.         {
  29.             bool isOpen = true;
  30.             string userInput;
  31.             int gladiatorIndex = -1;
  32.             Random rand = new Random();
  33.            
  34.             while (isOpen)
  35.             {
  36.                 LoadGladiators();
  37.  
  38.                 Console.WriteLine($"Ave, Caesar, morituri te salutant! (латынь)\nСлавься, Цезарь, идущие на смерть приветствуют тебя!");
  39.                 Console.WriteLine($"\nВыбери достойных сражаться в Колизее перед твоим взором\n");
  40.  
  41.  
  42.                 Console.Write($"нажми любую, что посмотреть гладиаторов или exit для выхода: ");
  43.                 userInput = Console.ReadLine();
  44.  
  45.                 switch (userInput)
  46.                 {
  47.                     case "учше":
  48.                     case "exit":
  49.                         isOpen = false;
  50.                         break;
  51.                     default:
  52.                         ShowAllGladiators();
  53.  
  54.                         Console.Write($"\nВыберите гладиатора каменных ворот: ");
  55.                         gladiatorIndex = TryGetIndex(_gladiators.Count);
  56.                         Gladiator stoneGateGladiator = _gladiators[gladiatorIndex - 1];
  57.  
  58.                         Console.Write($"Выберите гладиатора железных ворот: ");
  59.                         gladiatorIndex = TryGetIndex(_gladiators.Count);
  60.                         Gladiator ironGateGladiator = _gladiators[gladiatorIndex - 1];
  61.  
  62.                         while (stoneGateGladiator.HitPoints > 0 && ironGateGladiator.HitPoints > 0)
  63.                         {
  64.                             stoneGateGladiator.TryUseSpeciality(rand);
  65.                             ironGateGladiator.TryUseSpeciality(rand);
  66.  
  67.                             Console.WriteLine();
  68.                             stoneGateGladiator.TakeDamage(ironGateGladiator.Injury);
  69.                             ironGateGladiator.TakeDamage(stoneGateGladiator.Injury);
  70.  
  71.                             stoneGateGladiator.ShowHeals();
  72.                             ironGateGladiator.ShowHeals();
  73.                         }
  74.  
  75.                         if (stoneGateGladiator.HitPoints <= 0 && ironGateGladiator.HitPoints <= 0)
  76.                         {
  77.                             Console.WriteLine($"\nОба гладиатора пали на Арене");
  78.                         }
  79.                         else if (stoneGateGladiator.HitPoints <= 0)
  80.                         {
  81.                             stoneGateGladiator.ShowDeathCertificate();
  82.                         }
  83.                         else if (ironGateGladiator.HitPoints <= 0)
  84.                         {
  85.                             ironGateGladiator.ShowDeathCertificate();
  86.                         }
  87.  
  88.                         Console.ReadKey();
  89.                         Console.Clear();
  90.                         _gladiators.RemoveRange(0, _gladiators.Count);
  91.                         break;
  92.                 }
  93.             }
  94.         }
  95.  
  96.         private void ShowAllGladiators()
  97.         {
  98.             Console.WriteLine();
  99.             for (int i = 0; i < _gladiators.Count; i++)
  100.             {
  101.                 Console.Write($"{i + 1}. ");
  102.                 _gladiators[i].ShowStats();
  103.             }
  104.         }
  105.  
  106.         private void LoadGladiators()
  107.         {
  108.             _gladiators.Add(new Berserk("Бъорн", 100, 10, 2));
  109.             _gladiators.Add(new Berserk("Ульф", 100, 9, 3));
  110.             _gladiators.Add(new Kamikaze("Ивао", 110, 10, 2));
  111.             _gladiators.Add(new Kamikaze("Исаму", 90, 10, 2));
  112.             _gladiators.Add(new Ambidexter("Мордо",110,7,2));
  113.             _gladiators.Add(new Ambidexter("Кецилий",100,10,2));
  114.         }
  115.  
  116.         private bool TryReadInt(out int number)
  117.         {
  118.             bool result = false;
  119.  
  120.             result = int.TryParse(Console.ReadLine(), out number);
  121.  
  122.             return result;
  123.         }
  124.  
  125.         private int TryGetIndex(int size)
  126.         {
  127.             int minLimit = 0;
  128.             int maxLimit = size;
  129.             bool isGetIndex = false;
  130.             int number;
  131.  
  132.             TryReadInt(out number);
  133.  
  134.             while (isGetIndex == false)
  135.             {
  136.                 if (number > minLimit && number <= maxLimit)
  137.                 {
  138.                     isGetIndex = true;
  139.                 }
  140.                 else
  141.                 {
  142.                     Console.Write($"Введите число в диапазоне от {minLimit + 1} до {maxLimit}: ");
  143.                     TryReadInt(out number);
  144.                 }
  145.             }
  146.             return number;
  147.         }
  148.     }
  149.  
  150.     abstract class Gladiator
  151.     {
  152.         protected string Name;
  153.         protected int Health;
  154.         protected int Damage;
  155.         protected int Armor;
  156.         protected string Type;
  157.         protected string Speciality;
  158.  
  159.         public int HitPoints
  160.         {
  161.             get
  162.             {
  163.                 return Health;
  164.             }
  165.         }
  166.  
  167.         public int Injury
  168.         {
  169.             get
  170.             {
  171.                 return Damage;
  172.             }
  173.         }
  174.  
  175.         public Gladiator(string name, int health, int damage, int armor)
  176.         {
  177.             Name = name;
  178.             Health = health;
  179.             Damage = damage;
  180.             Armor = armor;
  181.         }
  182.  
  183.         public abstract void UseSpeciality();
  184.  
  185.         public void TryUseSpeciality(Random rand)
  186.         {
  187.             int limit = 3;
  188.             bool tryToUse;
  189.  
  190.             tryToUse = (rand.Next(0, limit) == 0);
  191.  
  192.             if (tryToUse)
  193.             {
  194.                 UseSpeciality();
  195.             }
  196.         }
  197.  
  198.         public virtual void ShowDeathCertificate()
  199.         {
  200.             Console.WriteLine($"\nгладиатор {Name} отправился в царство Аида");
  201.         }
  202.  
  203.         public void ShowStats()
  204.         {
  205.             Console.WriteLine($"{Type} {Name}\tздоровье {Health}\tурон {Damage}\tброня {Armor}");
  206.         }
  207.  
  208.         public void ShowHeals()
  209.         {
  210.             Console.WriteLine($"{Type} {Name}\tздоровье {Health}");
  211.         }
  212.  
  213.         public void TakeDamage(int damage)
  214.         {
  215.             Health -= damage - Armor;
  216.         }
  217.     }
  218.  
  219.     class Berserk : Gladiator
  220.     {
  221.         public Berserk(string name, int health, int damage, int armor) : base(name, health, damage, armor)
  222.         {
  223.             Type = "берсеркер";
  224.             Speciality = "грызет щит, что уменьшает броню (-2), но увеличивает урон (+10)";
  225.         }
  226.  
  227.         public override void UseSpeciality()
  228.         {
  229.             Console.WriteLine($"{Type} {Name} применил навык - {Speciality}");
  230.             Armor -= 2;
  231.             Damage += 10;
  232.         }
  233.  
  234.         public override void ShowDeathCertificate()
  235.         {
  236.             Console.WriteLine($"\n{Type} {Name} отправился в Вальхаллу");
  237.         }
  238.     }
  239.  
  240.     class Kamikaze : Gladiator
  241.     {
  242.         public Kamikaze(string name, int health, int damage, int armor) : base(name, health, damage, armor)
  243.         {
  244.             Type = "камикадзе";
  245.             Speciality = "дополнительно нанесет 50 единиц урона, но погибнет после такого удара";
  246.         }
  247.  
  248.         public override void UseSpeciality()
  249.         {
  250.             Console.WriteLine($"{Type} {Name} применил навык - {Speciality}");
  251.             Damage += 50;
  252.             Health = 1;
  253.         }
  254.  
  255.         public override void ShowDeathCertificate()
  256.         {
  257.             Console.WriteLine($"\n{Type} {Name} отправился к Будде");
  258.         }
  259.     }
  260.  
  261.     class Ambidexter: Gladiator
  262.     {
  263.         public Ambidexter(string name, int health, int damage, int armor): base (name, health, damage, armor)
  264.         {
  265.             Type = "амбидекстер";
  266.             Speciality = "наносит двойной урон 2-мя мечами";
  267.         }
  268.  
  269.         public override void UseSpeciality()
  270.         {
  271.             Console.WriteLine($"{Type} {Name} применил навык - {Speciality}");
  272.             Damage *= 2;
  273.         }
  274.     }
  275. }
  276.  
Add Comment
Please, Sign In to add comment