Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace Classes
- {
- internal class Program
- {
- static void Main()
- {
- Arena arena = new Arena();
- arena.Fight();
- }
- }
- class Arena
- {
- private List<IFigthing> fighters = new List<IFigthing>();
- public void Fight()
- {
- SelectionMenu(fighters);
- bool isWarriorAlive = true;
- int turn = 1;
- int firstFighter = 0;
- int secondFighter = 1;
- while (isWarriorAlive)
- {
- Console.WriteLine($"Turn {turn}");
- turn++;
- fighters[secondFighter].TakeDamage(fighters[firstFighter].Damage(), firstFighter + 1);
- fighters[firstFighter].TakeDamage(fighters[secondFighter].Damage(), secondFighter + 1);
- fighters[firstFighter].ShowHealth(firstFighter + 1);
- fighters[secondFighter].ShowHealth(secondFighter + 1);
- isWarriorAlive = fighters[firstFighter].Health() > 0 && fighters[secondFighter].Health() > 0;
- }
- Console.ForegroundColor = ConsoleColor.Green;
- if (fighters[firstFighter].Health() == 0 && fighters[secondFighter].Health() == 0)
- {
- Console.WriteLine($"Draw!");
- }
- else if (fighters[firstFighter].Health() > 0 && fighters[secondFighter].Health() == 0)
- {
- Console.WriteLine($"Warrior {firstFighter + 1} wins!");
- }
- else if (fighters[firstFighter].Health() == 0 && fighters[secondFighter].Health() > 0)
- {
- Console.WriteLine($"Warrior {secondFighter + 1} wins!");
- }
- Console.ResetColor();
- }
- private List<IFigthing> SelectionMenu(List<IFigthing> fighters)
- {
- const int ChooseDoubleDamageWarrior = 1;
- const int ChooseTwiceStrikesWarrior = 2;
- const int ChooseHealingWarrior = 3;
- const int ChooseMageWarrior = 4;
- const int ChooseEvadingWarrior = 5;
- int numberOfWarriors = 2;
- Console.WriteLine($"" +
- $"{ChooseDoubleDamageWarrior} - Double Damage Warrior\n" +
- $"{ChooseTwiceStrikesWarrior} - Twice Strikes Warrior\n" +
- $"{ChooseHealingWarrior} - Healing Warrior\n" +
- $"{ChooseMageWarrior} - Mage Warrior\n" +
- $"{ChooseEvadingWarrior} - Evading Warrior\n" +
- $"");
- for (int i = 0; i < numberOfWarriors; i++)
- {
- Console.WriteLine($"choose {i + 1} fighter {ChooseDoubleDamageWarrior}-{ChooseEvadingWarrior}");
- int.TryParse(Console.ReadLine(), out int fighterType);
- Random random = new Random();
- int minHealth = 120;
- int maxHealth = 160;
- int health = random.Next(minHealth, maxHealth + 1);
- int minDamage = 18;
- int maxDamage = 23;
- int damage = random.Next(minDamage, maxDamage + 1);
- bool hasChosen = true;
- switch (fighterType)
- {
- case ChooseDoubleDamageWarrior:
- fighters.Add(new DoubleDamageWarrior(health, damage));
- break;
- case ChooseTwiceStrikesWarrior:
- fighters.Add(new TwiceStrikesWarrior(health, damage));
- break;
- case ChooseHealingWarrior:
- fighters.Add(new HealingWarrior(health, damage));
- break;
- case ChooseMageWarrior:
- fighters.Add(new MageWarrior(health, damage));
- break;
- case ChooseEvadingWarrior:
- fighters.Add(new EvadingWarrior(health, damage));
- break;
- default:
- i--;
- hasChosen = false;
- break;
- }
- if (hasChosen)
- {
- Console.WriteLine($"Warrior {i + 1} has health - {health}, damage - {damage}");
- }
- }
- return fighters;
- }
- }
- interface IFigthing
- {
- int Health();
- int Damage();
- void TakeDamage(int damage, int warriorNumber);
- void ShowHealth(int warriorNumber);
- }
- class Fighter
- {
- public int _health;
- protected int _damage;
- protected Random _random = new Random();
- protected Fighter(int health, int damage)
- {
- _health = health;
- _damage = damage;
- }
- public void TakeDamage(int damage, int warriorsNumber)
- {
- Console.WriteLine($"Warrior {warriorsNumber} deals {damage} damage");
- _health = _health > 0 ? _health - damage : 0;
- }
- public int Health() => _health;
- public int Damage() => _damage;
- public void ShowHealth(int warriorsNumber)
- {
- Console.Write($"Warrior {warriorsNumber} has health: ");
- Console.WriteLine(_health = _health > 0 ? _health : 0);
- }
- protected void SpecialAttack() { }
- protected void PrintGreenMessage(string Message)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(Message);
- Console.ResetColor();
- }
- }
- class DoubleDamageWarrior : Fighter, IFigthing
- {
- private int _simpleDamage;
- public DoubleDamageWarrior(int health, int damage) : base(health, damage)
- {
- _simpleDamage = _damage;
- }
- new public int Damage()
- {
- SpecialAttack();
- return _damage;
- }
- new private void SpecialAttack()
- {
- int probability = 3;
- if (_random.Next(0, 10) < probability)
- {
- int damageMultiplier = 2;
- _damage = _simpleDamage * damageMultiplier;
- PrintGreenMessage($"Special Attack damage X{damageMultiplier}");
- }
- else
- {
- _damage = _simpleDamage;
- }
- }
- }
- class TwiceStrikesWarrior : Fighter, IFigthing
- {
- private int _hitCount = 1;
- private int _simpleDamage;
- public TwiceStrikesWarrior(int health, int damage) : base(health, damage)
- {
- _simpleDamage = _damage;
- }
- new public int Damage()
- {
- SpecialAttack();
- return _damage;
- }
- new private void SpecialAttack()
- {
- int damageMultiplier = 2;
- int criticalAttackPeriod = 3;
- if (_hitCount % criticalAttackPeriod == 0)
- {
- _damage = _damage * damageMultiplier;
- PrintGreenMessage($"Special Attack damage X{damageMultiplier}");
- }
- else
- {
- _damage = _simpleDamage;
- }
- _hitCount++;
- }
- }
- class HealingWarrior : Fighter, IFigthing
- {
- private int _rage;
- private int _normalHealth;
- public HealingWarrior(int health, int damage) : base(health, damage)
- {
- _normalHealth = health;
- }
- new public int Damage()
- {
- SpecialAttack();
- return _damage;
- }
- new private void SpecialAttack()
- {
- int rageThreshold = 80;
- int healthRecovery = 30;
- _rage = _normalHealth - _health;
- if (_rage > rageThreshold)
- {
- _health += healthRecovery;
- _normalHealth = _normalHealth - rageThreshold + healthRecovery;
- PrintGreenMessage($"Special Attack Heal +{healthRecovery}");
- }
- }
- }
- class MageWarrior : Fighter, IFigthing
- {
- private int _mana = 45;
- private int _mageDamage = 20;
- private int _spellCosts = 20;
- private int _simpleDamage;
- public MageWarrior(int health, int damage) : base(health, damage)
- {
- _simpleDamage = _damage;
- }
- new public int Damage()
- {
- SpecialAttack();
- return _damage;
- }
- new private void SpecialAttack()
- {
- if (_mana > _spellCosts)
- {
- _mana -= _spellCosts;
- _damage += _mageDamage;
- PrintGreenMessage("Special Attack Fireball");
- }
- else
- {
- _damage = _simpleDamage;
- }
- }
- }
- class EvadingWarrior : Fighter, IFigthing
- {
- private bool isEvading = false;
- private int _currentHealth;
- public EvadingWarrior(int health, int damage) : base(health, damage)
- {
- _currentHealth = _health;
- }
- new public int Damage()
- {
- SpecialAttack();
- return _damage;
- }
- new private void SpecialAttack()
- {
- int probability = 3;
- isEvading = _random.Next(0, 10) < probability;
- if (isEvading)
- {
- _health = _currentHealth;
- PrintGreenMessage("Special Attack Evading");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement