Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal class Program
- {
- public static void Main()
- {
- Arena arena = new Arena();
- arena.Work();
- }
- }
- class Arena
- {
- private Fighter _firstFighter;
- private Fighter _secondFighter;
- public void Work()
- {
- bool isUnselected = true;
- Fighter[] fighters =
- {
- new Warrior("Воин", 100, 20),
- new Rogue("Мошенник", 80, 15),
- new Healer("Целитель", 90, 10),
- new Archer("Лучник", 110, 25),
- new Knight("Рыцарь", 110, 25)
- };
- while (isUnselected)
- {
- Console.WriteLine("__________Все бойцы__________");
- for (int i = 0; i < fighters.Length; i++)
- {
- Console.WriteLine($"№{i + 1} | { fighters[i].Name}");
- }
- Console.WriteLine("\nВыберите первого бойца (1-5): ");
- int firstIndexFighter = int.Parse(Console.ReadLine()) - 1;
- Console.WriteLine("Выберите второго бойца (1-5): ");
- int secondIndexFighter = int.Parse(Console.ReadLine()) - 1;
- if (firstIndexFighter == secondIndexFighter)
- {
- Console.WriteLine("Вы выбрали одинаковых бойцов! Повторите выбор.");
- }
- else if (firstIndexFighter < 0 || firstIndexFighter >= fighters.Length || secondIndexFighter < 0 || secondIndexFighter >= fighters.Length)
- {
- Console.WriteLine("Некорректный выбор!");
- }
- else
- {
- _firstFighter = fighters[firstIndexFighter];
- _secondFighter = fighters[secondIndexFighter];
- isUnselected = false;
- Console.Clear();
- }
- }
- while (_firstFighter.Health > 0 && _secondFighter.Health > 0)
- {
- Console.WriteLine($"\nПервый боец аттакует противника на {_firstFighter.AttackDamage}!");
- _firstFighter.Attack(_secondFighter);
- Console.WriteLine($"Второй боец аттакует противника на {_secondFighter.AttackDamage}!\n");
- _secondFighter.Attack(_firstFighter);
- Console.WriteLine($"№1 | {_firstFighter.Name} | Здоровье: {_firstFighter.Health}");
- Console.WriteLine($"№2 | {_secondFighter.Name} | Здоровье: {_secondFighter.Health}");
- Console.WriteLine();
- }
- }
- }
- abstract class Fighter
- {
- protected const int WarriorSpecialAbilityParameter = 2;
- protected const int RogueSpecialAbiliryParameter = 3;
- protected const int HealerSpecialAbiliryParameter = 5;
- protected const int ArcherSpecialAbiliryParameter = 15;
- protected const int KnightSpecialAbiliryParameter = 100;
- public string Name { get; protected set; }
- public int Health { get; protected set; }
- public int AttackDamage { get; protected set; }
- public int TreatYourself(int treat)
- {
- return Health += treat;
- }
- public int TakeDamage(int damage)
- {
- return Health -= damage;
- }
- public virtual void Attack(Fighter enemy)
- {
- enemy.TakeDamage(AttackDamage);
- }
- public abstract int UseSpecialAbility(int specialAbility);
- }
- class Warrior : Fighter
- {
- public Warrior(string name, int health, int attackDamage)
- {
- Name = name;
- Health = health;
- AttackDamage = attackDamage;
- }
- public override int UseSpecialAbility(int specialAbility)
- {
- return TakeDamage(AttackDamage * specialAbility);
- }
- public override void Attack(Fighter enemy)
- {
- enemy.TakeDamage(AttackDamage);
- enemy.UseSpecialAbility(WarriorSpecialAbilityParameter);
- }
- }
- class Rogue : Fighter
- {
- public Rogue(string name, int health, int attackDamage)
- {
- Name = name;
- Health = health;
- AttackDamage = attackDamage;
- }
- public override int UseSpecialAbility(int specialAbility)
- {
- return TakeDamage(AttackDamage % specialAbility);
- }
- public override void Attack(Fighter enemy)
- {
- enemy.TakeDamage(AttackDamage);
- enemy.UseSpecialAbility(RogueSpecialAbiliryParameter);
- }
- }
- class Healer : Fighter
- {
- public Healer(string name, int health, int attackDamage)
- {
- Name = name;
- Health = health;
- AttackDamage = attackDamage;
- }
- public override int UseSpecialAbility(int specialAbility)
- {
- return TreatYourself(specialAbility);
- }
- public override void Attack(Fighter enemy)
- {
- enemy.TakeDamage(AttackDamage);
- Health = UseSpecialAbility(HealerSpecialAbiliryParameter);
- }
- }
- class Archer : Fighter
- {
- private Random _randomArrowsCount = new Random();
- private int _minArrowsCount = 1;
- private int _maxArrowsCount = 10;
- public Archer(string name, int health, int attackDamage)
- {
- Name = name;
- Health = health;
- AttackDamage = attackDamage;
- }
- public override int UseSpecialAbility(int specialAbility)
- {
- return TakeDamage(AttackDamage / specialAbility * _randomArrowsCount.Next(_minArrowsCount, _maxArrowsCount + 1));
- }
- public override void Attack(Fighter enemy)
- {
- enemy.TakeDamage(AttackDamage);
- enemy.UseSpecialAbility(ArcherSpecialAbiliryParameter);
- }
- }
- class Knight : Fighter
- {
- private Random _randomArmorCount = new Random();
- private int _minArmorCount = 5;
- private int _maxArmorCount = 20;
- public Knight(string name, int health, int attackDamage)
- {
- Name = name;
- Health = health;
- AttackDamage = attackDamage;
- }
- public override int UseSpecialAbility(int specialAbility)
- {
- return TreatYourself(Health * _randomArmorCount.Next(_minArmorCount, _maxArmorCount + 1) % specialAbility);
- }
- public override void Attack(Fighter enemy)
- {
- enemy.TakeDamage(AttackDamage);
- Health = UseSpecialAbility(ArcherSpecialAbiliryParameter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement