Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Task45
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string welcomeRing =
- "Добро пожаловать на ринг роботов!";
- string menu =
- "Start - выбрать бойцов и начать поединок." +
- "Exit -- уйти";
- bool isExit = false;
- Console.WriteLine(welcomeRing);
- while (isExit == false)
- {
- Ring ring = new Ring();
- Console.WriteLine(menu);
- string userInput = Console.ReadLine();
- switch (userInput)
- {
- case "Start":
- ring.Work();
- break;
- case "Exit":
- isExit = true;
- break;
- default:
- break;
- }
- }
- }
- }
- class Ring
- {
- private List<Robot> _robotsWarriors = new List<Robot>();
- public Ring()
- {
- _robotsWarriors.Add(new Ingenier("Инженер", "ремонт", "востанавливает 50 ед.здоровья", 200, 30, 60));
- _robotsWarriors.Add(new Miner("Шахтёр", "перегрев", "увеличивает показатели брони и урона на 1 раунд", 250, 45, 50));
- _robotsWarriors.Add(new Сop("Коп", "электрошок", "увеличивает на 10 процентов урон в течении 3 раундов", 200, 30, 45));
- _robotsWarriors.Add(new Defender("Защитник", "щит", "Создаёт щит, снижая урон на 35% и повышая защиту на 55%", 400, 25, 100));
- _robotsWarriors.Add(new Destroyer("Разрушитель", "второе дыхание", "Повышает урон на 50%, снижая броню на 50%", 150, 50, 60));
- }
- public void Work()
- {
- string requestChoiceRobots =
- "Выбери двух роботов бойцов: ";
- string requestFirstChoiceRobot =
- "Выбери первого: ";
- string requestSecondtChoiceRobot =
- "Выбери второго: ";
- bool isActive = true;
- while (isActive)
- {
- Robot firstRobot;
- Robot secondRobot;
- ShowInfo();
- Console.WriteLine(requestChoiceRobots);
- Console.WriteLine(requestFirstChoiceRobot);
- Choose(out firstRobot);
- Console.WriteLine(requestSecondtChoiceRobot);
- Choose(out secondRobot);
- Fight(firstRobot, secondRobot);
- isActive = false;
- }
- }
- private void ShowInfo()
- {
- string listRobots =
- "Список доступных роботов: ";
- Console.WriteLine(listRobots);
- for (int i = 0; i < _robotsWarriors.Count; i++)
- {
- _robotsWarriors[i].ShowCharacteristicsRobot();
- }
- Console.WriteLine();
- }
- private void Choose(out Robot robot)
- {
- robot = null;
- string requestNameRobot =
- "Введите имя робота, которого хотите выбрать: ";
- string errorFindRobot =
- "Такого робота нет в списке. Попробуй ещё раз.";
- string robotSelected =
- "Робот выбран.";
- bool robotFound = false;
- while (robotFound == false)
- {
- Robot findRobot;
- Console.Write(requestNameRobot);
- string userInput = Console.ReadLine();
- robotFound = TryGetRobot(userInput, out findRobot);
- if (robotFound)
- {
- robot = findRobot;
- _robotsWarriors.Remove(robot);
- }
- else
- {
- Console.WriteLine(errorFindRobot);
- }
- }
- Console.WriteLine(robotSelected);
- robot.ShowCharacteristicsRobot();
- Console.WriteLine();
- }
- private bool TryGetRobot(string userInput, out Robot findRobot)
- {
- findRobot = null;
- foreach (var warrior in _robotsWarriors)
- {
- if (userInput == warrior.Name)
- {
- findRobot = warrior;
- return true;
- }
- }
- return false;
- }
- private void Fight(Robot firstRobot, Robot secondRobot)
- {
- string startFight =
- "Роботы выбраны. Время начинать поединок! ";
- string draw =
- "Оба робота выведены из строя. Ничья.";
- string defeatedFirstRobot =
- "Второй робот не подаёт признаков жизни. Первый робот побеждает!";
- string defeatedSecondtRobot =
- "Первый робот не подаёт признаков жизни. Второй робот побеждает!";
- float originalDamageFirstRobot = firstRobot.Damage;
- float originalDamageSecondRobot = secondRobot.Damage;
- float originalArmorFirstRobot = firstRobot.Armor;
- float originalArmorSecondRobot = secondRobot.Armor;
- while (firstRobot.Health > 0 && secondRobot.Health > 0)
- {
- Console.WriteLine("\n" + startFight);
- if (firstRobot.Reload == 0)
- {
- firstRobot.UseSecondAbility();
- }
- if (firstRobot.WorkTime > 0)
- {
- firstRobot.ReduceWorkTime();
- }
- else
- {
- firstRobot.RevertOriginalState(firstRobot, originalDamageFirstRobot, originalArmorFirstRobot);
- }
- if (secondRobot.Reload == 0)
- {
- secondRobot.UseSecondAbility();
- }
- if (secondRobot.WorkTime > 0)
- {
- secondRobot.ReduceWorkTime();
- }
- else
- {
- secondRobot.RevertOriginalState(secondRobot, originalDamageSecondRobot, originalArmorSecondRobot);
- }
- firstRobot.TakeDamage(secondRobot.Damage);
- secondRobot.TakeDamage(firstRobot.Damage);
- firstRobot.ShowCharacteristicsRobot();
- secondRobot.ShowCharacteristicsRobot();
- firstRobot.SkipStep();
- secondRobot.SkipStep();
- if (firstRobot.Health <= 0 && secondRobot.Health <= 0)
- {
- Console.WriteLine(draw);
- }
- else if (firstRobot.Health <= 0)
- {
- Console.WriteLine(defeatedFirstRobot);
- }
- else
- {
- Console.WriteLine(defeatedSecondtRobot);
- }
- }
- }
- }
- class Robot
- {
- public string Name { get; protected set; }
- public string NameSecondAbility { get; protected set; }
- public string DescriptionAbility { get; protected set; }
- public float Health { get; protected set; }
- public float Damage { get; protected set; }
- public float Armor { get; protected set; }
- public int Reload { get; protected set; }
- public int WorkTime { get; protected set; }
- public Robot(string name, string nameSecondAbility,string descriptionAbility, int health, int damage, int armor)
- {
- Name = name;
- Health = health;
- Damage = damage;
- Armor = armor;
- NameSecondAbility = nameSecondAbility;
- DescriptionAbility = descriptionAbility;
- }
- public void ShowCharacteristicsRobot()
- {
- Console.WriteLine(
- $"Название ----------- {Name}\n" +
- $"Запас здоровья ----- {Health} ед.\n" +
- $"Наносимый урон ----- {Damage} ед.\n" +
- $"Запас брони -------- {Armor} ед. \n" +
- $"Вторая способность - {NameSecondAbility} - описание - {DescriptionAbility}\n" +
- $"=============================================");
- }
- public void TakeDamage(float damage)
- {
- if (Armor <= 100)
- {
- Health -= damage * (100 - Armor) / 100;
- }
- }
- public void RevertOriginalState(Robot robot, float originalDamage, float originalArmor)
- {
- robot.Damage = originalDamage;
- robot.Armor = originalArmor;
- }
- public void SkipStep()
- {
- Reload--;
- }
- public void ReduceWorkTime()
- {
- WorkTime--;
- }
- public virtual void UseSecondAbility() { }
- }
- class Ingenier : Robot
- {
- public Ingenier(string name, string nameSecondAbility, string descriptionAbility, int health, int damage, int armor) : base(name, nameSecondAbility, descriptionAbility, health, damage, armor) { }
- public override void UseSecondAbility()
- {
- string usesSkill =
- " - использует умение - ";
- Console.WriteLine(Name + usesSkill + NameSecondAbility);
- Repair();
- }
- private void Repair()
- {
- Health += 50;
- Armor *= 1.25f;
- Reload = 3;
- WorkTime = 0;
- }
- }
- class Miner : Robot
- {
- public Miner(string name, string nameSecondAbility, string descriptionAbility, int health, int damage, int armor) : base(name, nameSecondAbility, descriptionAbility, health, damage, armor) { }
- public override void UseSecondAbility()
- {
- string usesSkill =
- " - использует умение - ";
- Console.WriteLine(Name + usesSkill + NameSecondAbility);
- Overheat();
- }
- private void Overheat()
- {
- Damage *= 1.35f;
- Armor *= 1.1f;
- Reload = 4;
- WorkTime = 0;
- }
- }
- class Сop : Robot
- {
- public Сop(string name, string nameSecondAbility, string descriptionAbility, int health, int damage, int armor) : base(name, nameSecondAbility, descriptionAbility, health, damage, armor) { }
- public override void UseSecondAbility()
- {
- string usesSkill =
- " - использует умение - ";
- Console.WriteLine(Name + usesSkill + NameSecondAbility);
- ElectricShock();
- }
- private void ElectricShock()
- {
- Damage *= 1.1f;
- Reload = 5;
- WorkTime = 3;
- }
- }
- class Defender : Robot
- {
- public Defender(string name, string nameSecondAbility, string descriptionAbility, int health, int damage, int armor) : base(name, nameSecondAbility, descriptionAbility, health, damage, armor) { }
- public override void UseSecondAbility()
- {
- string usesSkill =
- " - использует умение - ";
- Console.WriteLine(Name + usesSkill + NameSecondAbility);
- Barrier();
- }
- private void Barrier()
- {
- Damage *= 0.65f;
- Armor *= 1.55f;
- Reload = 6;
- WorkTime = 2;
- }
- }
- class Destroyer : Robot
- {
- public Destroyer(string name, string nameSecondAbility, string descriptionAbility, int health, int damage, int armor) : base(name, nameSecondAbility, descriptionAbility, health, damage, armor) { }
- public override void UseSecondAbility()
- {
- string usesSkill =
- " - использует умение - ";
- Console.WriteLine(Name + usesSkill + NameSecondAbility);
- AdditionalPower();
- }
- private void AdditionalPower()
- {
- Damage *= 1.5f;
- Armor *= 0.5f;
- Reload = 6;
- WorkTime = 2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement