Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace CLight
- {
- class Program
- {
- public static void Main()
- {
- new FightRoom().Work();
- }
- }
- public static class RandomStatic
- {
- static private Random _rand = new Random();
- static public int GetNext(int min, int max)
- {
- return _rand.Next(min, max);
- }
- }
- public static class Messager
- {
- static public void ShowMessageWithColor(string message, ConsoleColor color, bool delay)
- {
- ConsoleColor defaultColor = Console.ForegroundColor;
- Console.ForegroundColor = color;
- Console.WriteLine(message);
- Console.ForegroundColor = defaultColor;
- if (delay)
- Console.ReadKey();
- }
- }
- class FightRoom
- {
- private List<Warrion> _warrions = new List<Warrion>() { new Mag(), new Barbar(), new Sworder(), new Gunner(), new Priest() };
- public void Work()
- {
- Warrion warrion1;
- Warrion warrion2;
- for (int i = 0; i < _warrions.Count; i++)
- {
- Console.Write($"{i}: ");
- _warrions[i].ShowInfo();
- }
- Console.Write("Выберите индекс первого бойца: ");
- warrion1 = _warrions[Convert.ToInt32(Console.ReadLine())];
- Console.Write("Выберите индекс второго бойца бойца: ");
- warrion2 = _warrions[Convert.ToInt32(Console.ReadLine())];
- while (warrion1.Hp > 0 && warrion2.Hp > 0)
- {
- warrion1.Attack(warrion2);
- if (!(warrion1.Hp > 0 && warrion2.Hp > 0))
- break;
- warrion2.Attack(warrion1);
- Console.WriteLine();
- }
- if (warrion1.Hp <= 0)
- Console.WriteLine("Первый воин пал");
- else
- Console.WriteLine("Второй воин пал");
- Console.ReadKey();
- }
- }
- abstract class Warrion
- {
- public int Hp { get; protected set; }
- public int BaseDamage { get; protected set; }
- public Warrion(int hp, int damage)
- {
- Hp = hp;
- BaseDamage = damage;
- }
- abstract public void ShowInfo();
- public void TakeDamage(int damage)
- {
- Hp -= damage;
- }
- public abstract void Attack(Warrion enemy);
- }
- class Mag : Warrion
- {
- public Mag() : base(RandomStatic.GetNext(100, 200), RandomStatic.GetNext(10, 150)) { }
- public override void Attack(Warrion enemy)
- {
- string[] typeSpell = new string[] { "огненному", "лесному" };
- int indexSpeel = RandomStatic.GetNext(0, 2);
- int damage;
- if (indexSpeel == 0)
- damage = BaseDamage * 2;
- else
- damage = BaseDamage / 2;
- enemy.TakeDamage(damage);
- Messager.ShowMessageWithColor($"Маг - Dam:{BaseDamage}; Hp:{Hp} - Нанес урон противнику в {damage} единиц благодаря {typeSpell[indexSpeel]} заклинанию", ConsoleColor.Green, false);
- }
- override public void ShowInfo()
- {
- Messager.ShowMessageWithColor($"Маг - Dam:{BaseDamage}; Hp:{Hp}", ConsoleColor.White, false);
- }
- }
- class Barbar : Warrion
- {
- public Barbar() : base(RandomStatic.GetNext(250, 500), RandomStatic.GetNext(75, 125)) { }
- public override void Attack(Warrion enemy)
- {
- bool isAmuck = Convert.ToBoolean(RandomStatic.GetNext(0, 2));
- int damage;
- if (isAmuck)
- damage = (int)(BaseDamage * 1.5f);
- else
- damage = BaseDamage;
- enemy.TakeDamage(damage);
- Messager.ShowMessageWithColor($"Варвар - Dam:{BaseDamage}; Hp:{Hp} - Нанес урон противнику в {damage} единиц. Состояние ярости {isAmuck.ToString()}", ConsoleColor.Blue, false);
- }
- override public void ShowInfo()
- {
- Messager.ShowMessageWithColor($"Варвар - Dam:{BaseDamage}; Hp:{Hp}", ConsoleColor.White, false);
- }
- }
- class Sworder : Warrion
- {
- public Sworder() : base(RandomStatic.GetNext(200, 600), RandomStatic.GetNext(100, 200)) { }
- public override void Attack(Warrion enemy)
- {
- int remorse = RandomStatic.GetNext(1, 6);
- int damage;
- damage = BaseDamage / remorse;
- enemy.TakeDamage(damage);
- Messager.ShowMessageWithColor($"Мечник - Dam:{BaseDamage}; Hp:{Hp} - Нанес урон противнику в {damage} единиц. Угрызение совести в {remorse} единицы, уменьшила его атаку на {BaseDamage - damage}", ConsoleColor.Cyan, false);
- }
- override public void ShowInfo()
- {
- Messager.ShowMessageWithColor($"Мечник - Dam:{BaseDamage}; Hp:{Hp}", ConsoleColor.White, false);
- }
- }
- class Gunner : Warrion
- {
- public Gunner() : base(RandomStatic.GetNext(100, 400), RandomStatic.GetNext(50, 100)) { }
- public override void Attack(Warrion enemy)
- {
- bool criticalShot = RandomStatic.GetNext(0, 101) < 20;
- int damage;
- if (criticalShot)
- damage = BaseDamage * 10;
- else
- damage = BaseDamage / 3;
- enemy.TakeDamage(damage);
- Messager.ShowMessageWithColor($"Стрелок - Dam:{BaseDamage}; Hp:{Hp} - Нанес урон противнику в {damage} единиц. Критический выстрел - {criticalShot}", ConsoleColor.Magenta, false);
- }
- override public void ShowInfo()
- {
- Messager.ShowMessageWithColor($"Стрелок - Dam:{BaseDamage}; Hp:{Hp}", ConsoleColor.White, false);
- }
- }
- class Priest : Warrion
- {
- public Priest() : base(RandomStatic.GetNext(250, 300), RandomStatic.GetNext(10, 70)) { }
- public override void Attack(Warrion enemy)
- {
- int powerPrayer = RandomStatic.GetNext(0, 11);
- int damage = BaseDamage * powerPrayer;
- enemy.TakeDamage(damage);
- Messager.ShowMessageWithColor($"Священник - Dam:{BaseDamage}; Hp:{Hp} - Нанес урон противнику в {damage} единиц. Молитва в {powerPrayer}, увеличила атаку на {damage - BaseDamage}", ConsoleColor.White, false);
- }
- override public void ShowInfo()
- {
- Messager.ShowMessageWithColor($"Священник - Dam:{BaseDamage}; Hp:{Hp}", ConsoleColor.White, false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement