Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace CSLight
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Arena arena = new Arena();
- arena.Fight();
- }
- }
- class Arena
- {
- private List<Fighter> _fighters = new List<Fighter>();
- public Arena()
- {
- _fighters.Add(new Warrior());
- _fighters.Add(new Barbarian());
- _fighters.Add(new Paladin());
- _fighters.Add(new Mage());
- _fighters.Add(new Scout());
- }
- public void Fight()
- {
- List<Fighter> fighters = new List<Fighter>();
- int firstFighterId = 0;
- int secondFighterId = 1;
- ConsoleColor firstTeamColor = ConsoleColor.Green;
- ConsoleColor secondTeamColor = ConsoleColor.Blue;
- Console.ForegroundColor = firstTeamColor;
- Console.WriteLine("Выбери первого бойца");
- fighters.Add(GetFighter());
- Console.ForegroundColor = secondTeamColor;
- Console.WriteLine("Выбери второго бойца");
- fighters.Add(GetFighter());
- Console.ResetColor();
- bool isFighting = true;
- while (isFighting)
- {
- foreach (Fighter fighter in fighters)
- {
- Console.WriteLine($"У {fighter.Name} осталось {fighter.Health} здоровья");
- }
- Console.WriteLine($"======================");
- Console.ForegroundColor = firstTeamColor;
- fighters[firstFighterId].Attack(fighters[secondFighterId]);
- Console.ForegroundColor = secondTeamColor;
- fighters[secondFighterId].Attack(fighters[firstFighterId]);
- if (TryStopFight(fighters[firstFighterId], fighters[secondFighterId]))
- {
- isFighting = false;
- }
- Console.ResetColor();
- Console.ReadKey();
- }
- if (TrySelectWinner(fighters, out Fighter winner))
- {
- Console.WriteLine($"Бой окончен. Победил {winner.Name}");
- }
- else
- {
- Console.WriteLine($"Бой окончен. Ничья");
- }
- Console.ReadLine();
- }
- private Fighter GetFighter()
- {
- bool isSelecting = true;
- Fighter fighter = null;
- while (isSelecting)
- {
- for (int i = 0; i < _fighters.Count; i++)
- {
- Console.WriteLine($"{i} - {_fighters[i].Name}");
- }
- string userInput = Console.ReadLine();
- if (int.TryParse(userInput, out int id) && id >= 0 && id < _fighters.Count)
- {
- isSelecting = false;
- fighter = _fighters[id].Clone();
- }
- else
- {
- Console.WriteLine("Неверный ввод");
- }
- }
- return fighter;
- }
- private bool TryStopFight(Fighter firstFighter, Fighter secondFighter)
- {
- return firstFighter.Health <= 0 || secondFighter.Health <= 0;
- }
- private bool TrySelectWinner(List<Fighter> fighters, out Fighter winner)
- {
- winner = null;
- foreach (Fighter fighter in fighters)
- {
- if (fighter.Health > 0)
- {
- winner = fighter;
- return true;
- }
- }
- return false;
- }
- }
- class Fighter
- {
- public Fighter()
- {
- Health = 100;
- MaxHealth = Health;
- }
- protected int MaxHealth { get; private set; }
- public string Name { get; protected set; }
- public int Health { get; protected set; }
- public int AttackPower { get; protected set; }
- public virtual Fighter Clone()
- {
- return new Fighter();
- }
- public virtual void Attack(Fighter enemy)
- {
- enemy.TakeDamage(AttackPower);
- Console.WriteLine($"{Name} атакует {enemy.Name} и наносит {AttackPower} урона");
- }
- public virtual void TakeDamage(int damage)
- {
- if (damage >= 0)
- {
- Health -= damage;
- }
- }
- protected bool TryActivateSkill(int chance)
- {
- int percent = UserUtils.GenerateRandomValue(chance);
- if (percent <= chance)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- class Warrior : Fighter
- {
- private int _chanceToActivateSkillDoubleAttack;
- public override Fighter Clone()
- {
- return new Warrior();
- }
- public Warrior() : base()
- {
- Name = "Warrior";
- AttackPower = 10;
- _chanceToActivateSkillDoubleAttack = 20;
- }
- public override void Attack(Fighter enemy)
- {
- if (TryActivateSkill(_chanceToActivateSkillDoubleAttack))
- {
- ActivateSkillDoubleDamage(enemy);
- }
- else
- {
- base.Attack(enemy);
- }
- }
- private void ActivateSkillDoubleDamage(Fighter enemy)
- {
- int powerMultiplyer = 2;
- enemy.TakeDamage(AttackPower * powerMultiplyer);
- Console.WriteLine($"{Name} активирует скилл и наносит двойной урон");
- }
- }
- class Barbarian : Fighter
- {
- private int _skillDoubleAttackChargesCapacity;
- private int _skillDoubleAttackCharges;
- public Barbarian() : base()
- {
- Name = "Barbarian";
- Health = 120;
- AttackPower = 10;
- _skillDoubleAttackChargesCapacity = 3;
- _skillDoubleAttackCharges = 0;
- }
- public override Fighter Clone()
- {
- return new Barbarian();
- }
- public override void Attack(Fighter enemy)
- {
- if (GetSkillDoubleAttackStatus())
- {
- ActivateSkillDoubleAttack(enemy);
- }
- else
- {
- base.Attack(enemy);
- _skillDoubleAttackCharges += ChargeSkill();
- }
- }
- private void ActivateSkillDoubleAttack(Fighter enemy)
- {
- base.Attack(enemy);
- base.Attack(enemy);
- _skillDoubleAttackCharges = 0;
- Console.WriteLine($"{Name} активирует скилл и производит две атаки");
- }
- private bool GetSkillDoubleAttackStatus()
- {
- return _skillDoubleAttackCharges >= _skillDoubleAttackChargesCapacity;
- }
- private int ChargeSkill()
- {
- int chargesCount = 1;
- Console.WriteLine($"{Name} заряжает скилл");
- return chargesCount; ;
- }
- }
- class Paladin : Fighter
- {
- private int _skillRageChargesCapacity;
- private int _skillRageCharges;
- public Paladin() : base()
- {
- Name = "Paladin";
- Health = 90;
- AttackPower = 7;
- _skillRageChargesCapacity = 5;
- _skillRageCharges = 0;
- }
- public override Fighter Clone()
- {
- return new Paladin();
- }
- public override void TakeDamage(int damage)
- {
- base.TakeDamage(damage);
- _skillRageCharges += ChargeSkill();
- if (GetSkillRageStatus())
- {
- ActivateSkillRage(this);
- }
- }
- private void ActivateSkillRage(Fighter enemy)
- {
- int maxHealPower = 30;
- int healPower = UserUtils.GenerateRandomValue(maxHealPower);
- Health += healPower;
- if (Health > MaxHealth)
- {
- Health = MaxHealth;
- }
- Console.WriteLine($"{Name} активирует скилл и лечит себя на {healPower}");
- }
- private bool GetSkillRageStatus()
- {
- return _skillRageCharges >= _skillRageChargesCapacity;
- }
- protected int ChargeSkill()
- {
- int chargesCount = 1;
- Console.WriteLine($"{Name} заряжает скилл");
- return chargesCount; ;
- }
- }
- class Mage : Fighter
- {
- private int _mana;
- private int _fireballManaCost;
- public Mage()
- {
- Name = "Mage";
- Health = 70;
- AttackPower = 3;
- _mana = 60;
- _fireballManaCost = 20;
- }
- public override Fighter Clone()
- {
- return new Mage();
- }
- public override void Attack(Fighter enemy)
- {
- if (_mana >= _fireballManaCost)
- {
- ActivateSkillFireball(enemy);
- }
- else
- {
- enemy.TakeDamage(AttackPower);
- }
- }
- private void ActivateSkillFireball(Fighter enemy)
- {
- int fireballPower = 15;
- enemy.TakeDamage(fireballPower);
- Console.WriteLine($"{Name} запускает фаерболл и наносит {fireballPower} урона");
- }
- }
- class Scout : Fighter
- {
- private int _chanceToActivateSkillDodge;
- public Scout()
- {
- Name = "Scout";
- Health = 85;
- _chanceToActivateSkillDodge = 40;
- AttackPower = 4;
- }
- public override Fighter Clone()
- {
- return new Scout();
- }
- public override void TakeDamage(int damage)
- {
- if (TryActivateSkill(_chanceToActivateSkillDodge) == false)
- {
- base.TakeDamage(damage);
- }
- }
- }
- static class UserUtils
- {
- public static int GenerateRandomValue(int maxValue)
- {
- Random random = new Random();
- return random.Next(maxValue);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement