Anonim_999

Bar

Feb 15th, 2021 (edited)
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.67 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. namespace ConsoleApp2
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int maxHealth = 10;
  10.             int maxMana = 10;
  11.             string userInput;
  12.             bool isContinue = true;
  13.  
  14.             while (isContinue)
  15.             {
  16.                 WritedColored("\nНажмите любую клавишу...");
  17.                 Console.ReadKey();
  18.                 Console.Clear();
  19.  
  20.                 try
  21.                 {
  22.                     WritedColored("команды:\nexit\nsetBar: ", ConsoleColor.Green);
  23.                     userInput = Console.ReadLine();
  24.                     switch (userInput)
  25.                     {
  26.                         case "exit":
  27.                             isContinue = false;
  28.                             WritedColored("Нажмите любую клавишу...", ConsoleColor.Red);
  29.                             Console.ReadKey();
  30.                             break;
  31.                         case "setBar":
  32.                             WritedColored("\nВведите значения здоровья в процентах: ");
  33.                             int health = Convert.ToInt32(Math.Floor(Convert.ToDouble(Console.ReadLine()) / 10));
  34.                             WritedColored("\nВведите значения маны в процентах: ");
  35.                             int mana = Convert.ToInt32(Math.Floor(Convert.ToDouble(Console.ReadLine()) / 10));
  36.                            
  37.                             if (health < 0 || health > maxHealth || mana < 0 || mana > maxMana)
  38.                             {
  39.                                 WritedColored("Ошибка ввода, впишите значение от 0 до 100", ConsoleColor.Red);
  40.                             }
  41.                             else
  42.                             {
  43.                                 Console.Clear();
  44.                                 DrawBar(health, maxHealth, 0, 0, '#', ConsoleColor.Red);
  45.                                 DrawBar(mana, maxMana, 0, 2, '#', ConsoleColor.Blue);
  46.                             }
  47.                             break;
  48.                         default:
  49.                             WritedColored("Я не знаю такую команду \\_(*_*)_/", ConsoleColor.Red);
  50.                             break;
  51.                     }
  52.                 }
  53.                 catch (Exception)
  54.                 {
  55.                     WritedColored("Произошла ошибка ввода \\_(*_*)_/", ConsoleColor.Red);
  56.                 }
  57.             }
  58.         }
  59.  
  60.         static private void DrawBar(int value, int maxValue, int positionX,int positionY, char symbol = ' ', ConsoleColor color = ConsoleColor.Yellow)
  61.         {
  62.             string bar = "";
  63.  
  64.             for (int i = 0; i < value; i++)
  65.             {
  66.                 bar += symbol;
  67.             }
  68.  
  69.             Console.SetCursorPosition(positionX,positionY);
  70.             WritedColored("\n[");
  71.             WritedBackColored($"{bar}", color);
  72.             bar = "";
  73.  
  74.             for (int i = value; i < maxValue; i++)
  75.             {
  76.                 bar += " ";
  77.             }
  78.  
  79.             WritedColored($"{bar}]");
  80.         }
  81.  
  82.         static private void WritedColored(string text, ConsoleColor color = ConsoleColor.Yellow)
  83.         {
  84.             Console.ForegroundColor = color;
  85.             Console.Write(text);
  86.             Console.ResetColor();
  87.         }
  88.  
  89.         static private void WritedBackColored(string text, ConsoleColor color = ConsoleColor.Yellow)
  90.         {
  91.             Console.BackgroundColor = color;
  92.             Console.Write(text);
  93.             Console.ResetColor();
  94.         }
  95.     }
  96. }
  97.  
Add Comment
Please, Sign In to add comment