Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Clight_26_OOP_GladiaotorFight
- {
- class Program
- {
- static void Main(string[] args)
- {
- int maxArmor = 100;
- int textVersion;
- int weightDamage;
- int randomForce1;
- int randomForce2;
- int randomBlock1;
- int randomBlock2;
- Random random = new Random();
- while (true)
- {
- Console.CursorVisible = false;
- Gladiator gladiator1 = new Gal("Нормус", 500, 80, 20, maxArmor);
- Gladiator gladiator2 = new Velit("Кникс", 500, 50, 40, maxArmor);
- Gladiator gladiator3 = new Gal("Галей", 500, 100, 10, maxArmor);
- Gladiator gladiator4 = new Velit("Бомбус", 500, 40, 50, maxArmor);
- Gladiator gladiator5 = new Velit("Фергнус", 500, 45, 45, maxArmor);
- Gladiators gladiators = new Gladiators(new Gladiator[] { gladiator1, gladiator2, gladiator3, gladiator4, gladiator5 });
- Console.WriteLine("Номер Тип Имя Жизни Сила Броня\n");
- gladiators.ShowAllGladiators();
- int firstNumGladiator = checkUserInput("\nВыберите первого бойца для поединка", gladiators);
- int secondNumGladiator = checkUserInput("\nВыберите второго бойца для поединка", gladiators, firstNumGladiator);
- Gladiator firstGladiator = gladiators.GetGladiator(firstNumGladiator);
- Gladiator secondGladiator = gladiators.GetGladiator(secondNumGladiator);
- while (firstGladiator.GetHealth() > 0 && secondGladiator.GetHealth() > 0)
- {
- Console.WriteLine();
- Console.ForegroundColor = ConsoleColor.Red;
- textVersion = random.Next(0, 4);
- weightDamage = random.Next(-20, 21);
- randomForce1 = random.Next(1, 3);
- randomForce2 = random.Next(1, 3);
- randomBlock1 = random.Next(0, 2);
- randomBlock2 = random.Next(0, 2);
- secondGladiator.TakeHealth(firstGladiator.GiveDamage(textVersion, weightDamage, randomForce1, randomForce2), randomBlock1, randomBlock2, maxArmor);
- Console.ForegroundColor = ConsoleColor.Green;
- textVersion = random.Next(0, 4);
- weightDamage = random.Next(-20, 21);
- randomForce1 = random.Next(1, 3);
- randomForce2 = random.Next(1, 3);
- randomBlock1 = random.Next(0, 2);
- randomBlock2 = random.Next(0, 2);
- firstGladiator.TakeHealth(secondGladiator.GiveDamage(textVersion, weightDamage, randomForce1, randomForce2), randomBlock1, randomBlock2, maxArmor);
- Console.ForegroundColor = ConsoleColor.White;
- firstGladiator.ShowCutInfo();
- secondGladiator.ShowCutInfo();
- Console.WriteLine();
- System.Threading.Thread.Sleep(500);
- }
- Console.WriteLine();
- if (firstGladiator.GetHealth() < 0 && secondGladiator.GetHealth() < 0)
- {
- Console.WriteLine("Ничья");
- }
- else if (firstGladiator.GetHealth() >= 0 && secondGladiator.GetHealth() < 0)
- {
- Console.WriteLine($"Выиграл гладиотор {firstGladiator.GetName()}");
- }
- else if (firstGladiator.GetHealth() < 0 && secondGladiator.GetHealth() >= 0)
- {
- Console.WriteLine($"Выиграл гладиотор {secondGladiator.GetName()}");
- }
- else
- {
- Console.WriteLine("Произошло не понятное и бой прервался на самом интересном месте");
- }
- bool isPlay = true;
- char userInput = checkUserInput("\nХотите сыграть еще?\nY - да, N - нет", ref isPlay);
- if (isPlay)
- {
- Console.Clear();
- }
- else
- {
- Console.WriteLine("\nПока!");
- Console.ReadKey();
- Environment.Exit(0);
- }
- }
- }
- static int checkUserInput(string text, Gladiators gladiators)
- {
- bool successCheck = false;
- int successNum = 0;
- while (successCheck == false)
- {
- Console.SetCursorPosition(0, gladiators.GetLenghtGladiators() + 2);
- Console.Write(text + ": ");
- string currentNumGladiator = Console.ReadLine();
- bool success = Int32.TryParse(currentNumGladiator, out int num);
- if (success != true || num > gladiators.GetLenghtGladiators() || num <= 0)
- {
- Console.Write("Укажите корректный номер гладиатора");
- Console.ReadKey();
- Console.SetCursorPosition(0, gladiators.GetLenghtGladiators() + 3);
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- }
- else
- {
- successNum = num - 1;
- successCheck = true;
- }
- }
- return successNum;
- }
- static int checkUserInput(string text, Gladiators gladiators, int numEnemy)
- {
- bool successCheck = false;
- int successNum = 0;
- while (successCheck == false)
- {
- Console.SetCursorPosition(0, gladiators.GetLenghtGladiators() + 3);
- Console.Write(text + ": ");
- string currentNumGladiator = Console.ReadLine();
- bool success = Int32.TryParse(currentNumGladiator, out int num);
- if (numEnemy == num - 1)
- {
- string duplicateName = gladiators.GetGladiator(numEnemy).GetName();
- Console.Write($"Гладиатор по имени {duplicateName} уже выбран");
- Console.ReadKey();
- Console.SetCursorPosition(0, gladiators.GetLenghtGladiators() + 4);
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- }
- else if (success != true || num > gladiators.GetLenghtGladiators() || num <= 0)
- {
- Console.Write("Укажите корректный номер гладиатора");
- Console.ReadKey();
- Console.SetCursorPosition(0, gladiators.GetLenghtGladiators() + 4);
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- }
- else
- {
- successNum = num - 1;
- successCheck = true;
- }
- }
- return successNum;
- }
- static char checkUserInput(string text, ref bool isPlay)
- {
- bool goodCheck = false;
- char symbolUser = ' ';
- while (goodCheck != true)
- {
- Console.Write(text + ": ");
- string currentNumGladiator = Console.ReadLine();
- bool success = Char.TryParse(currentNumGladiator, out char symbol);
- if (success != true)
- {
- Console.WriteLine("\nНе понятно");
- }
- else if (symbol == 'Y' || symbol == 'y' || symbol == 'Н' || symbol == 'н')
- {
- symbolUser = 'Y';
- goodCheck = true;
- }
- else if (symbol == 'N' || symbol == 'n' || symbol == 'Т' || symbol == 'т')
- {
- symbolUser = 'N';
- isPlay = false;
- goodCheck = true;
- }
- else
- {
- Console.WriteLine("\nПромахнулись по нужной клавише");
- }
- }
- return symbolUser;
- }
- }
- class Gladiator
- {
- protected string _name;
- protected double _health;
- protected int _damage;
- protected double _armor;
- public Gladiator(string name, double health, int damage, double armor, int maxArmor)
- {
- _name = name;
- _health = health;
- _damage = damage;
- if (armor > maxArmor)
- {
- _armor = maxArmor;
- }
- else
- {
- _armor = armor;
- }
- }
- public void ShowInfo()
- {
- Console.WriteLine($"{_name} {_health} {_damage} {_armor}");
- }
- public void ShowCutInfo()
- {
- Console.WriteLine($"{_name} {_health}");
- }
- public virtual void TakeHealth(double damage, int randomBlock1, int randomBlock2, int maxArmor)
- {
- double currentArmor = 1 - (_armor / maxArmor);
- _health -= Math.Round(damage * currentArmor, 0);
- }
- public virtual double GiveDamage(int textVersion, int weightDamage, int randomForce1, int randomForce2)
- {
- double currentDamage = _damage + _damage * weightDamage / 100;
- if (textVersion == 0)
- {
- Console.WriteLine($"{_name} нанес удар");
- }
- else if (textVersion == 1)
- {
- Console.WriteLine($"{_name} ударил в торс");
- }
- else if (textVersion == 2)
- {
- Console.WriteLine($"попал {_name} по голове");
- }
- else
- {
- Console.WriteLine($"{_name} провел удар");
- }
- return currentDamage;
- }
- public double GetHealth()
- {
- return _health;
- }
- public string GetName()
- {
- return _name;
- }
- }
- class Gal : Gladiator
- {
- Random random = new Random();
- public Gal(string name, double health, int damage, double armor, int maxArmor) : base(name, health, damage, armor, maxArmor)
- { }
- public override double GiveDamage(int textVersion, int weightDamage, int randomForce1, int randomForce2)
- {
- double currentDamage;
- int randomForce3 = random.Next(1, 3);
- if (randomForce1 == 2 && randomForce2 == 2 && randomForce3 == 2)
- {
- currentDamage = _damage * randomForce1;
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine($"{_name} нанес удар с двойной силой");
- Console.ForegroundColor = ConsoleColor.White;
- }
- else
- {
- currentDamage = _damage + _damage * weightDamage / 100;
- int text = random.Next(0, 4);
- if (text == 0)
- {
- Console.WriteLine($"{_name} нанес удар");
- }
- else if (text == 1)
- {
- Console.WriteLine($"{_name} ударил в торс");
- }
- else if (text == 2)
- {
- Console.WriteLine($"попал {_name} по голове");
- }
- else
- {
- Console.WriteLine($"{_name} провел удар");
- }
- }
- return currentDamage;
- }
- }
- class Velit : Gladiator
- {
- Random random = new Random(333);
- public Velit(string name, double health, int damage, double armor, int maxArmor) : base(name, health, damage, armor, maxArmor)
- { }
- public override void TakeHealth(double damage, int randomBlock1, int randomBlock2, int maxArmor)
- {
- int randomBlock3 = random.Next(0, 2);
- int block = 1;
- if (randomBlock1 == 0 && randomBlock2 == 0 && randomBlock3 == 0)
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine($"{_name} поставил блок");
- Console.ForegroundColor = ConsoleColor.White;
- block = 0;
- }
- double currentArmor = (1 - (_armor / maxArmor)) * block;
- _health -= Math.Round(damage * currentArmor, 0);
- }
- }
- class Gladiators
- {
- protected Gladiator[] _gladiators;
- public Gladiators(Gladiator[] gladiators)
- {
- _gladiators = gladiators;
- }
- public void ShowAllGladiators()
- {
- for (int i = 0; i < _gladiators.Length; i++)
- {
- Console.Write($"{i + 1} {_gladiators[i].GetType().Name} ");
- _gladiators[i].ShowInfo();
- }
- }
- public Gladiator GetGladiator(int num)
- {
- return _gladiators[num];
- }
- public int GetLenghtGladiators()
- {
- return _gladiators.Length;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement