Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- int maxHealth = 10;
- int maxMana = 10;
- string userInput;
- bool isContinue = true;
- while (isContinue)
- {
- WritedColored("\nНажмите любую клавишу...");
- Console.ReadKey();
- Console.Clear();
- try
- {
- WritedColored("команды:\nexit\nsetBar: ", ConsoleColor.Green);
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "exit":
- isContinue = false;
- WritedColored("Нажмите любую клавишу...", ConsoleColor.Red);
- Console.ReadKey();
- break;
- case "setBar":
- WritedColored("\nВведите значения здоровья в процентах: ");
- int health = Convert.ToInt32(Math.Floor(Convert.ToDouble(Console.ReadLine()) / 10));
- WritedColored("\nВведите значения маны в процентах: ");
- int mana = Convert.ToInt32(Math.Floor(Convert.ToDouble(Console.ReadLine()) / 10));
- if (health < 0 || health > maxHealth || mana < 0 || mana > maxMana)
- {
- WritedColored("Ошибка ввода, впишите значение от 0 до 100", ConsoleColor.Red);
- }
- else
- {
- Console.Clear();
- DrawBar(health, maxHealth, 0, 0, '#', ConsoleColor.Red);
- DrawBar(mana, maxMana, 0, 2, '#', ConsoleColor.Blue);
- }
- break;
- default:
- WritedColored("Я не знаю такую команду \\_(*_*)_/", ConsoleColor.Red);
- break;
- }
- }
- catch (Exception)
- {
- WritedColored("Произошла ошибка ввода \\_(*_*)_/", ConsoleColor.Red);
- }
- }
- }
- static private void DrawBar(int value, int maxValue, int positionX,int positionY, char symbol = ' ', ConsoleColor color = ConsoleColor.Yellow)
- {
- string bar = "";
- for (int i = 0; i < value; i++)
- {
- bar += symbol;
- }
- Console.SetCursorPosition(positionX,positionY);
- WritedColored("\n[");
- WritedBackColored($"{bar}", color);
- bar = "";
- for (int i = value; i < maxValue; i++)
- {
- bar += " ";
- }
- WritedColored($"{bar}]");
- }
- static private void WritedColored(string text, ConsoleColor color = ConsoleColor.Yellow)
- {
- Console.ForegroundColor = color;
- Console.Write(text);
- Console.ResetColor();
- }
- static private void WritedBackColored(string text, ConsoleColor color = ConsoleColor.Yellow)
- {
- Console.BackgroundColor = color;
- Console.Write(text);
- Console.ResetColor();
- }
- }
- }
Add Comment
Please, Sign In to add comment