Advertisement
MaoChessy

Task 33 - 2 - fix

Nov 13th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace CLight
  5. {
  6.     class Program
  7.     {
  8.         public static void Main()
  9.         {
  10.             new FightRoom().Work();
  11.         }
  12.     }
  13.     public static class RandomStatic
  14.     {
  15.         static private Random _rand = new Random();
  16.         static public int GetNext(int min, int max)
  17.         {
  18.             return _rand.Next(min, max);
  19.         }
  20.     }
  21.     public static class Messager
  22.     {
  23.         static public void ShowMessageWithColor(string message, ConsoleColor color, bool delay)
  24.         {
  25.             ConsoleColor defaultColor = Console.ForegroundColor;
  26.             Console.ForegroundColor = color;
  27.             Console.WriteLine(message);
  28.             Console.ForegroundColor = defaultColor;
  29.             if (delay)
  30.                 Console.ReadKey();
  31.         }
  32.     }
  33.     class FightRoom
  34.     {
  35.         private List<Warrion> _warrions = new List<Warrion>() { new Mag(), new Barbar(), new Sworder(), new Gunner(), new Priest() };
  36.         public void Work()
  37.         {
  38.             Warrion warrion1;
  39.             Warrion warrion2;
  40.  
  41.             for (int i = 0; i < _warrions.Count; i++)
  42.             {
  43.                 Console.Write($"{i}: ");
  44.                 _warrions[i].ShowInfo();
  45.             }
  46.  
  47.             Console.Write("Выберите индекс первого бойца: ");
  48.             warrion1 = _warrions[Convert.ToInt32(Console.ReadLine())];
  49.             Console.Write("Выберите индекс второго бойца бойца: ");
  50.             warrion2 = _warrions[Convert.ToInt32(Console.ReadLine())];
  51.  
  52.             while (warrion1.Hp > 0 && warrion2.Hp > 0)
  53.             {
  54.                 warrion1.Attack(warrion2);
  55.                 if (!(warrion1.Hp > 0 && warrion2.Hp > 0))
  56.                     break;
  57.                 warrion2.Attack(warrion1);
  58.                 Console.WriteLine();
  59.             }
  60.             if (warrion1.Hp <= 0)
  61.                 Console.WriteLine("Первый воин пал");
  62.             else
  63.                 Console.WriteLine("Второй воин пал");
  64.             Console.ReadKey();
  65.         }
  66.     }
  67.     abstract class Warrion
  68.     {
  69.         public int Hp { get; protected set; }
  70.         public int BaseDamage { get; protected set; }
  71.         public Warrion(int hp, int damage)
  72.         {
  73.             Hp = hp;
  74.             BaseDamage = damage;
  75.         }
  76.         abstract public void ShowInfo();
  77.         public void TakeDamage(int damage)
  78.         {
  79.             Hp -= damage;
  80.         }
  81.         public abstract void Attack(Warrion enemy);
  82.     }
  83.     class Mag : Warrion
  84.     {
  85.         public Mag() : base(RandomStatic.GetNext(100, 200), RandomStatic.GetNext(10, 150)) { }
  86.         public override void Attack(Warrion enemy)
  87.         {
  88.             string[] typeSpell = new string[] { "огненному", "лесному" };
  89.             int indexSpeel = RandomStatic.GetNext(0, 2);
  90.             int damage;
  91.             if (indexSpeel == 0)
  92.                 damage = BaseDamage * 2;
  93.             else
  94.                 damage = BaseDamage / 2;
  95.             enemy.TakeDamage(damage);
  96.             Messager.ShowMessageWithColor($"Маг - Dam:{BaseDamage}; Hp:{Hp} - Нанес урон противнику в {damage} единиц благодаря {typeSpell[indexSpeel]} заклинанию", ConsoleColor.Green, false);
  97.         }
  98.         override public void ShowInfo()
  99.         {
  100.             Messager.ShowMessageWithColor($"Маг - Dam:{BaseDamage}; Hp:{Hp}", ConsoleColor.White, false);
  101.         }
  102.     }
  103.     class Barbar : Warrion
  104.     {
  105.         public Barbar() : base(RandomStatic.GetNext(250, 500), RandomStatic.GetNext(75, 125)) { }
  106.         public override void Attack(Warrion enemy)
  107.         {
  108.             bool isAmuck = Convert.ToBoolean(RandomStatic.GetNext(0, 2));
  109.             int damage;
  110.             if (isAmuck)
  111.                 damage = (int)(BaseDamage * 1.5f);
  112.             else
  113.                 damage = BaseDamage;
  114.             enemy.TakeDamage(damage);
  115.             Messager.ShowMessageWithColor($"Варвар - Dam:{BaseDamage}; Hp:{Hp} - Нанес урон противнику в {damage} единиц. Состояние ярости {isAmuck.ToString()}", ConsoleColor.Blue, false);
  116.         }
  117.         override public void ShowInfo()
  118.         {
  119.             Messager.ShowMessageWithColor($"Варвар - Dam:{BaseDamage}; Hp:{Hp}", ConsoleColor.White, false);
  120.         }
  121.     }
  122.     class Sworder : Warrion
  123.     {
  124.         public Sworder() : base(RandomStatic.GetNext(200, 600), RandomStatic.GetNext(100, 200)) { }
  125.         public override void Attack(Warrion enemy)
  126.         {
  127.             int remorse = RandomStatic.GetNext(1, 6);
  128.             int damage;
  129.             damage = BaseDamage / remorse;
  130.             enemy.TakeDamage(damage);
  131.             Messager.ShowMessageWithColor($"Мечник - Dam:{BaseDamage}; Hp:{Hp} - Нанес урон противнику в {damage} единиц. Угрызение совести в {remorse} единицы, уменьшила его атаку на {BaseDamage - damage}", ConsoleColor.Cyan, false);
  132.         }
  133.         override public void ShowInfo()
  134.         {
  135.             Messager.ShowMessageWithColor($"Мечник - Dam:{BaseDamage}; Hp:{Hp}", ConsoleColor.White, false);
  136.         }
  137.     }
  138.     class Gunner : Warrion
  139.     {
  140.         public Gunner() : base(RandomStatic.GetNext(100, 400), RandomStatic.GetNext(50, 100)) { }
  141.         public override void Attack(Warrion enemy)
  142.         {
  143.             bool criticalShot = RandomStatic.GetNext(0, 101) < 20;
  144.             int damage;
  145.             if (criticalShot)
  146.                 damage = BaseDamage * 10;
  147.             else
  148.                 damage = BaseDamage / 3;
  149.             enemy.TakeDamage(damage);
  150.             Messager.ShowMessageWithColor($"Стрелок - Dam:{BaseDamage}; Hp:{Hp} - Нанес урон противнику в {damage} единиц. Критический выстрел - {criticalShot}", ConsoleColor.Magenta, false);
  151.         }
  152.         override public void ShowInfo()
  153.         {
  154.             Messager.ShowMessageWithColor($"Стрелок - Dam:{BaseDamage}; Hp:{Hp}", ConsoleColor.White, false);
  155.         }
  156.     }
  157.     class Priest : Warrion
  158.     {
  159.         public Priest() : base(RandomStatic.GetNext(250, 300), RandomStatic.GetNext(10, 70)) { }
  160.         public override void Attack(Warrion enemy)
  161.         {
  162.             int powerPrayer = RandomStatic.GetNext(0, 11);
  163.             int damage = BaseDamage * powerPrayer;
  164.             enemy.TakeDamage(damage);
  165.             Messager.ShowMessageWithColor($"Священник - Dam:{BaseDamage}; Hp:{Hp} - Нанес урон противнику в {damage} единиц. Молитва в {powerPrayer}, увеличила атаку на {damage - BaseDamage}", ConsoleColor.White, false);
  166.         }
  167.         override public void ShowInfo()
  168.         {
  169.             Messager.ShowMessageWithColor($"Священник - Dam:{BaseDamage}; Hp:{Hp}", ConsoleColor.White, false);
  170.         }
  171.     }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement