Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace OOPTask8Fighting
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Colosseum colosseum = new Colosseum();
- colosseum.Work();
- }
- }
- public class Colosseum
- {
- private List<Fighter> _fighters = new List<Fighter>();
- private Fighter _fighter1;
- private Fighter _fighter2;
- public Colosseum()
- {
- Fill();
- }
- public void Work()
- {
- const string CommandShowHelloMessage = "1";
- const string CommandInitiateFighting = "2";
- const string CommandExit = "3";
- bool isWorking = true;
- string userInput;
- while (isWorking)
- {
- Console.WriteLine("Добро пожаловать в Колизей!");
- Console.WriteLine($"{CommandShowHelloMessage} - приветственное сообщение");
- Console.WriteLine($"{CommandInitiateFighting} - начать схватку");
- Console.WriteLine($"{CommandExit} - покинуть арену");
- Console.WriteLine("\nВведите команду: ");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case CommandShowHelloMessage:
- ShowHelloMessage();
- break;
- case CommandInitiateFighting:
- InitiateFighting();
- break;
- case CommandExit:
- isWorking = false;
- break;
- default:
- Console.WriteLine("Неизвестная команда");
- break;
- }
- Console.WriteLine("\nДля продолжения нажмите любую кнопку");
- Console.ReadKey();
- Console.Clear();
- }
- }
- private void InitiateFighting()
- {
- ChooseFighters();
- ShowStartFightingInfo();
- ShowFighting();
- ShowFinishFightingInfo();
- }
- private void ShowFighting()
- {
- while (_fighter1.Health > 0 && _fighter2.Health > 0)
- {
- Console.ReadKey();
- Console.WriteLine("Боец 1 атакует:");
- _fighter1.Attack(_fighter2);
- Console.WriteLine("Боец 2 атакует:");
- _fighter2.Attack(_fighter1);
- Console.Write("\nБоец 1: ");
- _fighter1.ShowShortInfo();
- Console.Write("Боец 2: ");
- _fighter2.ShowShortInfo();
- Console.WriteLine();
- }
- }
- private void ShowStartFightingInfo()
- {
- Console.Clear();
- Console.WriteLine("\nСегодня бьюьются не на жизнь, а на смерть:\n");
- Console.Write("Боец 1: ");
- _fighter1.ShowInfo();
- Console.Write("Боец 2: ");
- _fighter2.ShowInfo();
- Console.WriteLine("\nДля продолжения битвы нажимайте любую клавишу\n");
- }
- private void ShowFinishFightingInfo()
- {
- if (_fighter1.Health < 0 && _fighter2.Health < 0)
- {
- Console.WriteLine("\nНичья\nОба бойца получили ранения несовместимые с жизнью");
- }
- else if (_fighter1.Health < 0)
- {
- Console.WriteLine("\nБоец 2 победил:");
- _fighter2.ShowInfo();
- }
- else if (_fighter2.Health < 0)
- {
- Console.WriteLine("\nБоец 1 победил:");
- _fighter1.ShowInfo();
- }
- Console.WriteLine();
- }
- private void ChooseFighters()
- {
- ShowAllFighters();
- Console.Write("\nВведите номер первого бойца: ");
- _fighter1 = (Fighter)GetFighter().Clone();
- Console.Write("\nВведите номер второго бойца: ");
- _fighter2 = (Fighter)GetFighter().Clone();
- }
- private Fighter GetFighter()
- {
- int indexFighter = 0;
- bool isCorrectIndexValue = false;
- while (isCorrectIndexValue == false)
- {
- indexFighter = ReadInt() - 1;
- if (indexFighter >= 0 && indexFighter < _fighters.Count)
- {
- isCorrectIndexValue = true;
- }
- else
- {
- Console.Write("Некорректный номер бойца, попробуйте еще: ");
- }
- }
- return _fighters[indexFighter];
- }
- private int ReadInt()
- {
- int inputNumber;
- while (int.TryParse(Console.ReadLine(), out inputNumber) == false)
- {
- Console.Write("Это не число, попробуйте еще раз: ");
- }
- return inputNumber;
- }
- private void Fill()
- {
- const int MinimumHealth = 1000;
- const int MaximumHealth = 1500;
- const int MinimumArmor = 100;
- const int MaximumArmor = 200;
- const int MinimumDamage = 150;
- const int MaximumDamage = 300;
- _fighters.Add(new LuckyDamager(UserUtils.GenerateRandomNumber(MinimumHealth, MaximumHealth),
- UserUtils.GenerateRandomNumber(MinimumArmor, MaximumArmor),
- UserUtils.GenerateRandomNumber(MinimumDamage, MaximumDamage)));
- _fighters.Add(new LuckyDamager(UserUtils.GenerateRandomNumber(MinimumHealth, MaximumHealth),
- UserUtils.GenerateRandomNumber(MinimumArmor, MaximumArmor),
- UserUtils.GenerateRandomNumber(MinimumDamage, MaximumDamage)));
- _fighters.Add(new StableDamager(UserUtils.GenerateRandomNumber(MinimumHealth, MaximumHealth),
- UserUtils.GenerateRandomNumber(MinimumArmor, MaximumArmor),
- UserUtils.GenerateRandomNumber(MinimumDamage, MaximumDamage)));
- _fighters.Add(new StableDamager(UserUtils.GenerateRandomNumber(MinimumHealth, MaximumHealth),
- UserUtils.GenerateRandomNumber(MinimumArmor, MaximumArmor),
- UserUtils.GenerateRandomNumber(MinimumDamage, MaximumDamage)));
- _fighters.Add(new Healer(UserUtils.GenerateRandomNumber(MinimumHealth, MaximumHealth),
- UserUtils.GenerateRandomNumber(MinimumArmor, MaximumArmor),
- UserUtils.GenerateRandomNumber(MinimumDamage, MaximumDamage)));
- _fighters.Add(new Healer(UserUtils.GenerateRandomNumber(MinimumHealth, MaximumHealth),
- UserUtils.GenerateRandomNumber(MinimumArmor, MaximumArmor),
- UserUtils.GenerateRandomNumber(MinimumDamage, MaximumDamage)));
- _fighters.Add(new FireBallDamager(UserUtils.GenerateRandomNumber(MinimumHealth, MaximumHealth),
- UserUtils.GenerateRandomNumber(MinimumArmor, MaximumArmor),
- UserUtils.GenerateRandomNumber(MinimumDamage, MaximumDamage)));
- _fighters.Add(new FireBallDamager(UserUtils.GenerateRandomNumber(MinimumHealth, MaximumHealth),
- UserUtils.GenerateRandomNumber(MinimumArmor, MaximumArmor),
- UserUtils.GenerateRandomNumber(MinimumDamage, MaximumDamage)));
- _fighters.Add(new Nimble(UserUtils.GenerateRandomNumber(MinimumHealth, MaximumHealth),
- UserUtils.GenerateRandomNumber(MinimumArmor, MaximumArmor),
- UserUtils.GenerateRandomNumber(MinimumDamage, MaximumDamage)));
- _fighters.Add(new Nimble(UserUtils.GenerateRandomNumber(MinimumHealth, MaximumHealth),
- UserUtils.GenerateRandomNumber(MinimumArmor, MaximumArmor),
- UserUtils.GenerateRandomNumber(MinimumDamage, MaximumDamage)));
- }
- private void ShowAllFighters()
- {
- int fighterNumber = 1;
- Console.WriteLine("Эти величайшие гладиаторы готовы отдать жизнь за твое настроение!\n");
- foreach (Fighter fighter in _fighters)
- {
- Console.Write($"{fighterNumber++} - ");
- fighter.ShowInfo();
- }
- }
- private void ShowHelloMessage()
- {
- Console.Clear();
- Console.WriteLine("Добро пожаловать в Колизей!");
- Console.WriteLine("Здесь собрались самые сильные гладиаторы!");
- Console.WriteLine("И пусть начнется бой и прольется кровь!");
- }
- }
- public interface IDamagable
- {
- void TakeDamage(int damage);
- }
- public class Fighter : IDamagable
- {
- protected string Title;
- protected string Description;
- public Fighter(int health, int armor, int damage)
- {
- Health = health;
- Armor = armor;
- Damage = damage;
- }
- public int Health { get; protected set; }
- public int Armor { get; protected set; }
- public int Damage { get; protected set; }
- public virtual void Attack(IDamagable fighter)
- {
- Console.WriteLine($"Боец \"{Title}\" наносит урон: {Damage}");
- fighter.TakeDamage(Damage);
- }
- public virtual void TakeDamage(int damage)
- {
- int takenDamage = GetTakenDamage(damage);
- Console.WriteLine($"Боец \"{Title}\" защищается и получает урон: {takenDamage}");
- Health -= takenDamage;
- }
- private int GetTakenDamage(int damage)
- {
- int takenDamage = damage - Armor;
- if (takenDamage < 0)
- takenDamage = 0;
- return takenDamage;
- }
- public virtual void ShowInfo()
- {
- Console.WriteLine($"\"{Title}\" - {Description}, здоровье: {Health}, броня: {Armor}, атака: {Damage}");
- }
- public void ShowShortInfo()
- {
- Console.WriteLine($"\"{Title}\" здоровье: {Health}");
- }
- public virtual Fighter Clone()
- {
- return new Fighter(Health, Armor, Damage);
- }
- }
- public class LuckyDamager : Fighter
- {
- private const int DamageMultiplier = 2;
- public LuckyDamager(int health, int armor, int damage) : base(health, armor, damage)
- {
- Title = "Счастливый кулак";
- Description = $"имеет шанс нанесения урона умноженного на {DamageMultiplier}";
- }
- public override void Attack(IDamagable fighter)
- {
- if (UserUtils.IsLuckyTime())
- {
- int damage = Damage * DamageMultiplier;
- Console.WriteLine($"Бойцу \"{Title}\" повезло, он наносит урон умноженный на {DamageMultiplier} урон: {damage}");
- fighter.TakeDamage(damage);
- }
- else
- {
- base.Attack(fighter);
- }
- }
- public override Fighter Clone()
- {
- return new LuckyDamager(Health, Armor, Damage);
- }
- }
- public class StableDamager : Fighter
- {
- private const int SuperAttackCount = 3;
- private const int SuperAttackTimes = 2;
- private int _attackCount = 1;
- public StableDamager(int health, int armor, int damage) : base(health, armor, damage)
- {
- Title = "Крепкий кулак";
- Description = "каждый третий удар дважды атакует";
- }
- public override void Attack(IDamagable fighter)
- {
- if (_attackCount++ == SuperAttackCount)
- {
- _attackCount = 1;
- Console.WriteLine($"Боец \"{Title}\" накопил сил и бьет {SuperAttackTimes} раз с уроном: {Damage}");
- for (int i = 0; i < SuperAttackTimes; i++)
- {
- fighter.TakeDamage(Damage);
- }
- }
- else
- {
- base.Attack(fighter);
- }
- }
- public override Fighter Clone()
- {
- return new StableDamager(Health, Armor, Damage);
- }
- }
- public class Healer : Fighter
- {
- private const int MinimumAngerLevel = 20;
- private const int MaximumAngerLevel = 50;
- private const int MinimumTakenAnger = 5;
- private const int MaximumTakenAnger = 10;
- private int _anger = 0;
- private int _maxHealth;
- public Healer(int health, int armor, int damage, int angerLevel = 0) : base(health, armor, damage)
- {
- Title = "Лекарь";
- Description = "при получении урона накапливает ярость и лечится";
- _maxHealth = health;
- if (angerLevel == 0)
- {
- angerLevel = UserUtils.GenerateRandomNumber(MinimumAngerLevel, MaximumAngerLevel);
- }
- AngerLevel = angerLevel;
- }
- public int AngerLevel { get; private set; }
- public override void TakeDamage(int damage)
- {
- base.TakeDamage(damage);
- if(Health > 0)
- {
- int takenAnger = UserUtils.GenerateRandomNumber(MinimumTakenAnger, MaximumTakenAnger);
- _anger += takenAnger;
- Console.WriteLine($"Боец {Title} получает заряд ярости: {takenAnger}");
- if (_anger >= AngerLevel)
- {
- int takenHealth = UserUtils.GenerateRandomNumber(0, Health);
- Console.WriteLine($"Уровень ярости бойца \"{Title}\" достиг максимума: {AngerLevel}, и его здоровье улучшается на: {takenHealth}");
- Health += takenHealth;
- _anger -= AngerLevel;
- if (Health > _maxHealth)
- {
- Health = _maxHealth;
- Console.WriteLine($"Боец {Title} полностью восстановил свое здоровье");
- }
- }
- }
- }
- public override void ShowInfo()
- {
- Console.WriteLine($"\"{Title}\" - {Description}, здоровье: {Health}, броня: {Armor}, атака: {Damage}, пик ярости: {AngerLevel}");
- }
- public override Fighter Clone()
- {
- return new Healer(Health, Armor, Damage, AngerLevel);
- }
- }
- public class FireBallDamager : Fighter
- {
- private const int MinimumMana = 50;
- private const int MaximumMana = 100;
- private const int MinimumFireBallMana = 15;
- private const int MaximumFireBallMana = 30;
- private const int MinimumPercentFireBallDamage = 110;
- private const int MaximumPercentFireBallDamage = 150;
- private const int ScalePercent = 100;
- public FireBallDamager(int health, int armor, int damage, int mana = 0) : base(health, armor, damage)
- {
- Title = "Огненный шар";
- Description = "метает огненные шары, пока не израсходует всю ману";
- if (mana == 0)
- {
- mana = UserUtils.GenerateRandomNumber(MinimumMana, MaximumMana);
- }
- Mana = mana;
- }
- public int Mana { get; private set; }
- public override void Attack(IDamagable fighter)
- {
- int fireBallMana = UserUtils.GenerateRandomNumber(MinimumFireBallMana, MaximumFireBallMana);
- if (fireBallMana <= Mana)
- {
- int damage = Damage * UserUtils.GenerateRandomNumber(MinimumPercentFireBallDamage, MaximumPercentFireBallDamage) / ScalePercent;
- Console.WriteLine($"Бойцу \"{Title}\" на огненный шар понадобилось {fireBallMana} маны и он наносит урон: {damage}");
- fighter.TakeDamage(damage);
- Mana -= fireBallMana;
- }
- else
- {
- base.Attack(fighter);
- }
- }
- public override void ShowInfo()
- {
- Console.WriteLine($"\"{Title}\" - {Description}, здоровье: {Health}, броня: {Armor}, атака: {Damage}, мана: {Mana}");
- }
- public override Fighter Clone()
- {
- return new FireBallDamager(Health, Armor, Damage, Mana);
- }
- }
- public class Nimble : Fighter
- {
- public Nimble(int health, int armor, int damage) : base(health, armor, damage)
- {
- Title = "Шустрый";
- Description = "имеет шанс уклониться от удара";
- }
- public override void TakeDamage(int damage)
- {
- if ( UserUtils.IsLuckyTime())
- {
- Console.WriteLine($"Боец {Title} ловко уклоняется от удара");
- }
- else
- {
- base.TakeDamage(damage);
- }
- }
- public override Fighter Clone()
- {
- return new Nimble(Health, Armor, Damage);
- }
- }
- public class UserUtils
- {
- private const int MinimumPercent = 0;
- private const int MaximumPercent = 100;
- private const int HalfPercent = 50;
- private static Random s_random = new Random();
- public static int GenerateRandomNumber(int minimumNumber, int maximumNumber)
- {
- return s_random.Next(minimumNumber, maximumNumber);
- }
- public static bool IsLuckyTime()
- {
- return s_random.Next(MinimumPercent, MaximumPercent) > HalfPercent;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement