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 isWarriorsAlive = true;
- int turn = 1;
- int fighter1 = 0;
- int fighter2 = 1;
- while (isWarriorsAlive)
- {
- Console.WriteLine($"Turn {turn}");
- turn++;
- fighters[fighter2].Attack(fighters[fighter1]);
- fighters[fighter1].Attack(fighters[fighter2]);
- fighters[fighter1].ShowHealth();
- fighters[fighter2].ShowHealth();
- isWarriorsAlive = fighters[fighter1].IsAlive && fighters[fighter2].IsAlive;
- }
- if (!fighters[fighter1].IsAlive && !fighters[fighter2].IsAlive)
- {
- UserUtils.PrintGreenMessage($"\nDraw!");
- }
- else if (fighters[fighter1].IsAlive)
- {
- UserUtils.PrintGreenMessage($"\nWarrior {fighter1 + 1} wins!");
- }
- else if (fighters[fighter2].IsAlive)
- {
- UserUtils.PrintGreenMessage($"\nWarrior {fighter2 + 1} wins!");
- }
- Console.WriteLine("\nPress something");
- Console.ReadKey();
- 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 = 6;
- 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);
- int minHealth = 120;
- int maxHealth = 160;
- int health = UserUtils.GenerateRandomNumber(minHealth, maxHealth + 1);
- int minAttack = 18;
- int maxAttack = 23;
- int attack = UserUtils.GenerateRandomNumber(minAttack, maxAttack + 1);
- bool hasChosen = true;
- switch (fighterType)
- {
- case ChooseDoubleDamageWarrior:
- fighters.Add(new DoubleDamageWarrior(health, attack, UserUtils.MakeString(index, doubleDamageWarriorName)));
- break;
- case ChooseTwiceStrikesWarrior:
- fighters.Add(new TwiceStrikesWarrior(health, attack, UserUtils.MakeString(index, twiceStrikesWarriorName)));
- break;
- case ChooseHealingWarrior:
- fighters.Add(new HealingWarrior(health, attack, UserUtils.MakeString(index, healingWarriorName)));
- break;
- case ChooseMageWarrior:
- fighters.Add(new MageWarrior(health, attack, UserUtils.MakeString(index, mageWarriorName)));
- break;
- case ChooseEvadingWarrior:
- fighters.Add(new EvadingWarrior(health, attack, UserUtils.MakeString(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;
- }
- }
- public interface IDamageable
- {
- void TakeDamage(int damage);
- }
- abstract class Fighter : IDamageable
- {
- protected int Health;
- protected int Damage;
- protected string Name;
- protected Fighter(int health, int damage, string name)
- {
- Health = health;
- Damage = damage;
- Name = name;
- }
- 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 virtual void MakeSpecialAttack() { }
- public void ShowHealth()
- {
- Health = Health > 0 ? Health : 0;
- Console.WriteLine($"Warrior {Name} {Health} health left");
- }
- }
- 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();
- }
- public static string MakeString(int index, string message) => index + " " + message;
- }
- class DoubleDamageWarrior : Fighter
- {
- private int _simpleDamage;
- public DoubleDamageWarrior(int health, int damage, string name) : base(health, damage, name)
- {
- _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;
- }
- }
- }
- class TwiceStrikesWarrior : Fighter
- {
- private int _hitCount = 1;
- private int _simpleDamage;
- public TwiceStrikesWarrior(int health, int damage, string name) : base(health, damage, name)
- {
- _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++;
- }
- }
- class HealingWarrior : Fighter
- {
- private int _rage;
- private int _normalHealth;
- public HealingWarrior(int health, int damage, string name) : base(health, damage, name)
- {
- _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;
- }
- }
- class MageWarrior : Fighter
- {
- private int _mana = 45;
- private int _mageDamage = 20;
- private int _spellCosts = 20;
- private int _simpleDamage;
- public MageWarrior(int health, int damage, string name) : base(health, damage, name)
- {
- _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;
- }
- }
- }
- class EvadingWarrior : Fighter
- {
- private bool isEvading = false;
- private int _simpleDamage;
- public EvadingWarrior(int health, int damage, string name) : base(health, damage, name)
- {
- _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 damage = _simpleDamage;
- int probability = 3;
- int minProbability = 0;
- int maxProbability = 9;
- isEvading = UserUtils.GenerateRandomNumber(minProbability, maxProbability + 1) < probability;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement