Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Classes
- {
- internal class Program
- {
- static void Main()
- {
- Arena arena = new Arena();
- arena.Fight();
- }
- }
- class Arena
- {
- public void Fight()
- {
- bool isRuning = true;
- while (isRuning)
- {
- List<Fighter> fighters = new List<Fighter>();
- SelectionMenu(fighters);
- if (fighters.Count != 0)
- {
- bool isWarriorAlive = true;
- int turn = 1;
- int firstFighter = 0;
- int secondFighter = 1;
- bool isFirstFighterAlive = true;
- bool isSecondFighterAlive = true;
- while (isWarriorAlive)
- {
- Console.WriteLine($"Turn {turn}");
- turn++;
- isFirstFighterAlive = fighters[firstFighter].TakeDamage(fighters[secondFighter].GetAttack());
- isSecondFighterAlive = fighters[secondFighter].TakeDamage(fighters[firstFighter].GetAttack());
- isWarriorAlive = isFirstFighterAlive && isSecondFighterAlive;
- }
- Console.ForegroundColor = ConsoleColor.Green;
- if (!isFirstFighterAlive && !isSecondFighterAlive)
- {
- Console.WriteLine($"\nDraw!");
- }
- else if (isFirstFighterAlive)
- {
- Console.WriteLine($"\nWarrior {firstFighter + 1} wins!");
- }
- else if (isSecondFighterAlive)
- {
- Console.WriteLine($"\nWarrior {secondFighter + 1} wins!");
- }
- Console.WriteLine("\nPress something");
- Console.ReadKey();
- Console.ResetColor();
- Console.Clear();
- }
- else
- {
- isRuning = false;
- }
- }
- }
- private List<Fighter> SelectionMenu(List<Fighter> fighters)
- {
- const int ChooseDoubleDamageWarrior = 1;
- const int ChooseTwiceStrikesWarrior = 2;
- const int ChooseHealingWarrior = 3;
- const int ChooseMageWarrior = 4;
- const int ChooseEvadingWarrior = 5;
- const int ExitMenu = 0;
- string doubleDamageWarriorName = "Double Damage Warrior";
- string twiceStrikesWarriorName = "Twice Strikes Warrior";
- string healingWarriorName = "Healing Warrior";
- string mageWarriorName = "Mage Warrior";
- string evadingWarriorName = "Evading Warrior";
- string exitMenu = "Exit";
- Console.WriteLine($"" +
- $"{ChooseDoubleDamageWarrior} - {doubleDamageWarriorName}\n" +
- $"{ChooseTwiceStrikesWarrior} - {twiceStrikesWarriorName}\n" +
- $"{ChooseHealingWarrior} - {healingWarriorName}\n" +
- $"{ChooseMageWarrior} - {mageWarriorName}\n" +
- $"{ChooseEvadingWarrior} - {evadingWarriorName}\n" +
- $"{ExitMenu} - {exitMenu}\n" +
- $"");
- int numberOfWarriors = 2;
- for (int i = 0; i < numberOfWarriors; i++)
- {
- int index = i + 1;
- Console.WriteLine($"choose {index} fighter {ChooseDoubleDamageWarrior}-{ChooseEvadingWarrior}, or {ExitMenu} for exit");
- 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 minAttack = 18;
- int maxAttack = 23;
- int attack = random.Next(minAttack, maxAttack + 1);
- bool hasChosen = true;
- switch (fighterType)
- {
- case ChooseDoubleDamageWarrior:
- fighters.Add(new DoubleDamageWarrior(health, attack, index + " " + doubleDamageWarriorName));
- break;
- case ChooseTwiceStrikesWarrior:
- fighters.Add(new TwiceStrikesWarrior(health, attack, index + " " + twiceStrikesWarriorName));
- break;
- case ChooseHealingWarrior:
- fighters.Add(new HealingWarrior(health, attack, index + " " + healingWarriorName));
- break;
- case ChooseMageWarrior:
- fighters.Add(new MageWarrior(health, attack, index + " " + mageWarriorName));
- break;
- case ChooseEvadingWarrior:
- fighters.Add(new EvadingWarrior(health, attack, index + " " + evadingWarriorName));
- break;
- case ExitMenu:
- return null;
- default:
- i--;
- hasChosen = false;
- break;
- }
- if (hasChosen)
- {
- Console.WriteLine($"Warrior {index} has health - {health}, attack - {attack}");
- }
- }
- return fighters;
- }
- }
- abstract class Fighter
- {
- protected int Health;
- protected int Attack;
- protected string Name;
- protected Random Random = new Random();
- protected Fighter(int health, int attack, string name)
- {
- Health = health;
- Attack = attack;
- Name = name;
- }
- public virtual bool TakeDamage(int enemyDamage)
- {
- Console.WriteLine($"Warrior {Name} take {enemyDamage} damage");
- Health -= enemyDamage;
- ShowHealth();
- bool isAlive = Health > 0;
- return isAlive;
- }
- public virtual int GetAttack() => Attack;
- public virtual void SpecialAttack() { }
- protected void ShowHealth()
- {
- Health = Health > 0 ? Health : 0;
- Console.WriteLine($"Warrior {Name} has {Health} health");
- }
- protected void PrintGreenMessage(string Message)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(Message);
- Console.ResetColor();
- }
- }
- class DoubleDamageWarrior : Fighter
- {
- private int _simpleDamage;
- public DoubleDamageWarrior(int health, int attack, string name) : base(health, attack, name)
- {
- _simpleDamage = Attack;
- }
- public override int GetAttack()
- {
- SpecialAttack();
- return base.GetAttack();
- }
- public override void SpecialAttack()
- {
- int probability = 3;
- int minProbability = 0;
- int maxProbability = 9;
- if (Random.Next(minProbability, maxProbability + 1) < probability)
- {
- int damageMultiplier = 2;
- Attack = _simpleDamage * damageMultiplier;
- PrintGreenMessage($"Warrior {Name} make Special Attack damage X{damageMultiplier}");
- }
- else
- {
- Attack = _simpleDamage;
- }
- }
- }
- class TwiceStrikesWarrior : Fighter
- {
- private int _hitCount = 1;
- private int _simpleDamage;
- public TwiceStrikesWarrior(int health, int attack, string name) : base(health, attack, name)
- {
- _simpleDamage = Attack;
- }
- public override int GetAttack()
- {
- SpecialAttack();
- return base.GetAttack();
- }
- public override void SpecialAttack()
- {
- int damageMultiplier = 2;
- int criticalAttackPeriod = 3;
- if (_hitCount % criticalAttackPeriod == 0)
- {
- Attack = _simpleDamage * damageMultiplier;
- PrintGreenMessage($"Warrior {Name} make Special Attack damage X{damageMultiplier}");
- }
- else
- {
- Attack = _simpleDamage;
- }
- _hitCount++;
- }
- }
- class HealingWarrior : Fighter
- {
- private int _rage;
- private int _normalHealth;
- public HealingWarrior(int health, int attack, string name) : base(health, attack, name)
- {
- _normalHealth = health;
- }
- public override void SpecialAttack()
- {
- int rageThreshold = 80;
- int healthRecovery = 30;
- _rage = _normalHealth - Health;
- if (_rage > rageThreshold && Health > 0)
- {
- Health += healthRecovery;
- _normalHealth = _normalHealth - rageThreshold + healthRecovery;
- PrintGreenMessage($"Warrior {Name} make Special Attack Heal +{healthRecovery}");
- }
- }
- public override bool TakeDamage(int enemyDamage)
- {
- SpecialAttack();
- return base.TakeDamage(enemyDamage);
- }
- }
- class MageWarrior : Fighter
- {
- private int _mana = 45;
- private int _mageDamage = 20;
- private int _spellCosts = 20;
- private int _simpleDamage;
- public MageWarrior(int health, int attack, string name) : base(health, attack, name)
- {
- _simpleDamage = Attack;
- }
- public override int GetAttack()
- {
- SpecialAttack();
- return base.GetAttack();
- }
- public override void SpecialAttack()
- {
- if (_mana > _spellCosts)
- {
- _mana -= _spellCosts;
- Attack = _simpleDamage + _mageDamage;
- PrintGreenMessage($"Warrior {Name} make Special Attack Fireball");
- }
- else
- {
- Attack = _simpleDamage;
- }
- }
- }
- class EvadingWarrior : Fighter
- {
- private bool isEvading = false;
- private int _currentHealth;
- public EvadingWarrior(int health, int attack, string name) : base(health, attack, name)
- {
- _currentHealth = Health;
- }
- public override bool TakeDamage(int enemyDamage)
- {
- Health -= enemyDamage;
- SpecialAttack();
- Console.WriteLine($"Warrior {Name} take {enemyDamage} damage");
- ShowHealth();
- bool isAlive = Health > 0;
- return isAlive;
- }
- public override void SpecialAttack()
- {
- int probability = 3;
- int minProbability = 0;
- int maxProbability = 9;
- isEvading = Random.Next(minProbability, maxProbability + 1) < probability;
- if (isEvading)
- {
- Health = _currentHealth;
- PrintGreenMessage($"Warrior {Name} make Special Attack Evading");
- }
- else
- {
- _currentHealth = Health;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement