Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Clight_21_OOP_ClassPlayer
- {
- class Program
- {
- static void Main(string[] args)
- {
- Player playerTeamA = new Player();
- int heightPlayerStats = 7;
- while (true)
- {
- playerTeamA.ShowStat();
- int stepDamage;
- int stepArmor;
- stepDamage = checkInputUser("Введите силу удара", 100, heightPlayerStats, 0);
- stepArmor = checkInputUser("Введите степень защиты", 100, heightPlayerStats, 1);
- playerTeamA.Armor = stepArmor;
- playerTeamA.TakeDamage(stepDamage);
- if (playerTeamA.Health <= 0)
- {
- Console.SetCursorPosition(0, 11);
- Console.WriteLine("Вы победили соперника в неравном бою. Пока!");
- Console.ReadKey();
- Environment.Exit(0);
- }
- Console.Clear();
- }
- }
- public static int checkInputUser(string text, int maxValue, int cursorY, int plusY)
- {
- bool goodInputUser = false;
- bool badCheckInput = true;
- int value = 0;
- while (badCheckInput)
- {
- Console.SetCursorPosition(0, cursorY + plusY);
- Console.Write($"{text}. Максимум {maxValue}: ");
- goodInputUser = Int32.TryParse(Console.ReadLine(), out int goodValue);
- if (goodInputUser != true)
- {
- Console.SetCursorPosition(0, cursorY + 5);
- Console.Write("Введите корректное число.");
- Console.ReadKey();
- Console.SetCursorPosition(0, cursorY + plusY);
- Console.Write(" ");
- Console.SetCursorPosition(0, cursorY + 5);
- Console.Write(" ");
- }
- else if (goodInputUser && goodValue > maxValue)
- {
- value = maxValue;
- badCheckInput = false;
- }
- else if (goodInputUser)
- {
- value = goodValue;
- badCheckInput = false;
- }
- }
- return value;
- }
- }
- class Player
- {
- public string Name;
- public char Avatar;
- public float Health;
- public int Armor;
- public int Damage;
- public Player(string name, char avatar, int healht, int armor, int damage)
- {
- Name = name;
- Avatar = avatar;
- Health = healht;
- Armor = armor;
- Damage = damage;
- }
- public Player()
- {
- Name = "Player";
- Avatar = '#';
- Health = 300;
- Armor = 30;
- Damage = 100;
- }
- public void ShowStat()
- {
- Console.WriteLine($"Жизни: {Health}\nИгрок: {Name}\nАватар: {Avatar}\nЗащита: {Armor}\nУрон: {Damage}\n");
- }
- public void TakeDamage(int damage)
- {
- float armorWeight = 1 - Convert.ToSingle(Armor) / 100;
- Health -= damage * armorWeight;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement