Advertisement
Comrade_Sharikov

Bar

Mar 26th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int health = 0, maxHealth = 10;
  10.             int mana = 0, maxMana = 10;
  11.             bool isOpen = true;
  12.  
  13.             while (isOpen)
  14.             {            
  15.                 Console.WriteLine("Введите количество жизней");
  16.                 health = Convert.ToInt32(Console.ReadLine());
  17.                 if(health.ToString() == "")
  18.                 {
  19.                     break;
  20.                 }
  21.  
  22.                 Console.WriteLine("Введите количество маны");
  23.                 mana = Convert.ToInt32(Console.ReadLine());
  24.  
  25.                 DrawBar(health, maxHealth, ConsoleColor.Red, 5, '#');
  26.                 Console.Write("   <- Жизни");
  27.  
  28.                 DrawBar(mana, maxMana, ConsoleColor.Blue, 7, '*');
  29.                 Console.Write("   <- Мана\n");
  30.  
  31.                 Console.WriteLine("\nДля выхода введите любой символ");
  32.  
  33.                 if(Console.ReadLine() != "")
  34.                 {
  35.                     isOpen = false;
  36.                 }
  37.  
  38.                 Console.Clear();
  39.             }
  40.         }
  41.  
  42.         private static void DrawBar(int value, int maxValue, ConsoleColor color, int position, char symbol = '_')
  43.         {
  44.             ConsoleColor defaultColor = Console.BackgroundColor;
  45.             string bar = "";
  46.  
  47.             for (int i = 0; i < value; i++)
  48.             {
  49.                 bar += symbol;
  50.             }
  51.  
  52.             Console.SetCursorPosition(0, position);
  53.             Console.Write("[");
  54.             Console.BackgroundColor = color;
  55.             Console.Write(bar);
  56.             Console.BackgroundColor = defaultColor;
  57.            
  58.             bar = "";
  59.  
  60.             for (int i = value; i < maxValue; i++)
  61.             {
  62.                 bar += '_';
  63.             }
  64.             Console.Write(bar + "]");
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement