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.Work();
- }
- }
- class Arena
- {
- public void Work()
- {
- bool isWorking = true;
- while (isWorking)
- {
- List<Fighter> fighters = new List<Fighter>() {
- new DoubleDamageWarrior(),
- new TwiceStrikesWarrior(),
- new HealingWarrior(),
- new MageWarrior(),
- new EvadingWarrior()};
- for (int i = 0; i < fighters.Count; i++)
- {
- Console.Write($"" +
- $"{i + 1} - {fighters[i].Name}\n" +
- $"");
- }
- int selectedFightersCount = 2;
- Fighter[] selectedFighters = new Fighter[selectedFightersCount];
- for (int i = 0; i < selectedFighters.Length; i++)
- {
- int fighterType = SelectionMenu(i, fighters.Count);
- if (fighterType == fighters.Count)
- {
- isWorking = false;
- i = selectedFighters.Length;
- continue;
- }
- selectedFighters[i] = SetFighter(fighters, fighterType, i);
- }
- if (!isWorking)
- {
- continue;
- }
- Fight(selectedFighters);
- }
- }
- private Fighter SetFighter(List<Fighter> fighters, int fighterType, int indexFighter)
- {
- Fighter fighter = fighters[fighterType].CloneFighter();
- fighter.SetIndex(indexFighter+1);
- Console.WriteLine($"Fighter {fighter.Name} has {fighter.Health} health, {fighter.Damage} damage");
- return fighter;
- }
- private int SelectionMenu(int indexFighter, int fightersCount)
- {
- bool hasChosen = false;
- int fighterType = 0;
- int commandExit = fightersCount + 1;
- while (!hasChosen)
- {
- Console.WriteLine($"\nChoose {indexFighter+1} fighter 1 - {fightersCount}, or {commandExit} for exit");
- hasChosen = int.TryParse(Console.ReadLine(), out fighterType);
- if (hasChosen && (fighterType <= 0 || fighterType > commandExit))
- {
- hasChosen = false;
- Console.WriteLine("select a fighter");
- }
- }
- fighterType--;
- return fighterType;
- }
- private void Fight(Fighter[] fighter)
- {
- bool isWarriorsAlive = true;
- int turn = 1;
- Console.WriteLine();
- while (isWarriorsAlive)
- {
- Console.WriteLine($"Turn {turn}");
- turn++;
- fighter[1].Attack(fighter[0]);
- fighter[0].Attack(fighter[1]);
- fighter[0].ShowHealth();
- fighter[1].ShowHealth();
- isWarriorsAlive = fighter[0].IsAlive && fighter[1].IsAlive;
- }
- if (!fighter[0].IsAlive && !fighter[1].IsAlive)
- {
- UserUtils.PrintGreenMessage($"\nDraw!");
- }
- else if (fighter[0].IsAlive)
- {
- UserUtils.PrintGreenMessage($"\nWarrior {fighter[0].Name} wins!");
- }
- else if (fighter[1].IsAlive)
- {
- UserUtils.PrintGreenMessage($"\nWarrior {fighter[1].Name} wins!");
- }
- Console.WriteLine("\nPress something");
- Console.ReadKey();
- Console.Clear();
- }
- }
- public interface IDamageable
- {
- void TakeDamage(int damage);
- }
- abstract class Fighter : IDamageable
- {
- protected Fighter(string name)
- {
- Name = name;
- SetStats();
- }
- public int Health { get; protected set; }
- public int Damage { get; protected set; }
- public string Name { get; protected set; }
- public bool IsAlive { get; protected set; }
- public void Attack(IDamageable damageable)
- {
- damageable.TakeDamage(Damage);
- }
- public virtual void TakeDamage(int damage)
- {
- MakeSpecialAttack();
- Health -= damage;
- Console.WriteLine($"Warrior {Name} took {damage} damage");
- IsAlive = Health > 0;
- }
- public abstract void MakeSpecialAttack();
- public abstract Fighter CloneFighter();
- public void ShowHealth()
- {
- Health = Health > 0 ? Health : 0;
- Console.WriteLine($"Warrior {Name} {Health} health left");
- }
- public void SetIndex(int name)
- {
- Name = name + " " + Name;
- }
- private void SetStats()
- {
- int minHealth = 120;
- int maxHealth = 160;
- int health = UserUtils.GenerateRandomNumber(minHealth, maxHealth + 1);
- int minDamage = 18;
- int maxDamage = 23;
- int damage = UserUtils.GenerateRandomNumber(minDamage, maxDamage + 1);
- Health = health;
- Damage = damage;
- }
- }
- class UserUtils
- {
- private static Random s_random = new Random();
- public static int GenerateRandomNumber(int min, int max) => s_random.Next(min, max);
- public static void PrintGreenMessage(string message)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(message);
- Console.ResetColor();
- }
- }
- class DoubleDamageWarrior : Fighter
- {
- private int _simpleDamage;
- public DoubleDamageWarrior() : base("Double Damage Warrior")
- {
- _simpleDamage = Damage;
- }
- public override void MakeSpecialAttack()
- {
- int probability = 3;
- int minProbability = 0;
- int maxProbability = 9;
- if (UserUtils.GenerateRandomNumber(minProbability, maxProbability + 1) < probability)
- {
- int damageMultiplier = 2;
- Damage = _simpleDamage * damageMultiplier;
- UserUtils.PrintGreenMessage($"Warrior {Name} make Special Attack damage X{damageMultiplier}");
- }
- else
- {
- Damage = _simpleDamage;
- }
- }
- public override Fighter CloneFighter() => new DoubleDamageWarrior();
- }
- class TwiceStrikesWarrior : Fighter
- {
- private int _hitCount = 1;
- private int _simpleDamage;
- public TwiceStrikesWarrior() : base("Twice Strikes Warrior")
- {
- _simpleDamage = Damage;
- }
- public override void MakeSpecialAttack()
- {
- int damageMultiplier = 2;
- int criticalAttackPeriod = 3;
- if (_hitCount % criticalAttackPeriod == 0)
- {
- Damage = _simpleDamage * damageMultiplier;
- UserUtils.PrintGreenMessage($"Warrior {Name} make Special Attack damage X{damageMultiplier}");
- }
- else
- {
- Damage = _simpleDamage;
- }
- _hitCount++;
- }
- public override Fighter CloneFighter() => new TwiceStrikesWarrior();
- }
- class HealingWarrior : Fighter
- {
- private int _rage;
- private int _normalHealth;
- public HealingWarrior() : base("Healing Warrior")
- {
- _normalHealth = Health;
- }
- public override void MakeSpecialAttack()
- {
- int rageThreshold = 80;
- int healthRecovery = 30;
- _rage = _normalHealth - Health;
- if (_rage > rageThreshold && Health > 0)
- {
- Health += healthRecovery;
- _normalHealth = _normalHealth - rageThreshold + healthRecovery;
- UserUtils.PrintGreenMessage($"Warrior {Name} make Special Attack Health +{healthRecovery}");
- }
- }
- public override void TakeDamage(int damage)
- {
- Health -= damage;
- Console.WriteLine($"Warrior {Name} took {damage} damage");
- MakeSpecialAttack();
- IsAlive = Health > 0;
- }
- public override Fighter CloneFighter() => new HealingWarrior();
- }
- class MageWarrior : Fighter
- {
- private int _mana = 45;
- private int _mageDamage = 20;
- private int _spellCosts = 20;
- private int _simpleDamage;
- public MageWarrior() : base("Mage Warrior")
- {
- _simpleDamage = Damage;
- }
- public override void MakeSpecialAttack()
- {
- if (_mana > _spellCosts)
- {
- _mana -= _spellCosts;
- Damage = _simpleDamage + _mageDamage;
- UserUtils.PrintGreenMessage($"Warrior {Name} make Special Attack Fireball");
- }
- else
- {
- Damage = _simpleDamage;
- }
- }
- public override Fighter CloneFighter() => new MageWarrior();
- }
- class EvadingWarrior : Fighter
- {
- private bool _isEvading = false;
- private int _simpleDamage;
- public EvadingWarrior() : base("Evading Warrior")
- {
- _simpleDamage = Damage;
- }
- public override void TakeDamage(int damage)
- {
- MakeSpecialAttack();
- if (_isEvading)
- {
- damage = 0;
- UserUtils.PrintGreenMessage($"Warrior {Name} make Special Attack Evading");
- }
- Health -= damage;
- Console.WriteLine($"Warrior {Name} took {damage} damage");
- IsAlive = Health > 0;
- }
- public override void MakeSpecialAttack()
- {
- int probability = 3;
- int minProbability = 0;
- int maxProbability = 9;
- _isEvading = UserUtils.GenerateRandomNumber(minProbability, maxProbability + 1) < probability;
- }
- public override Fighter CloneFighter() => new EvadingWarrior();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement