Advertisement
bonumopus

drawbar

Apr 17th, 2020
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace healthbar
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int health = 5, maxHealth = 10;
  14.             int mana = 3, maxMana = 10;
  15.  
  16.             while (true)
  17.             {
  18.                 DrawBar(health, maxHealth, ConsoleColor.Red, 0, '#','_');
  19.                 DrawBar(mana, maxMana, ConsoleColor.Blue, 1, '#', '_');
  20.  
  21.                 Console.SetCursorPosition(0, 5);
  22.  
  23.                 Console.Write("Введите число, на которое изменятся жизни: ");
  24.                 health += Convert.ToInt32(Console.ReadLine());
  25.                 Console.Write("Введите число, на которое изменится мана: ");
  26.                 mana += Convert.ToInt32(Console.ReadLine());
  27.  
  28.                 Console.ReadKey();
  29.                 Console.Clear();
  30.             }
  31.         }
  32.  
  33.         static void DrawBar(int value, int maxValue, ConsoleColor color, int position, char symbolFull = ' ', char symbolEmpty = ' ')
  34.         {
  35.             ConsoleColor defaultColor = Console.BackgroundColor;
  36.             string bar = "";
  37.  
  38.             for(int i = 0; i < value; i++)
  39.             {
  40.                 bar += symbolFull;
  41.             }
  42.  
  43.             Console.SetCursorPosition(0, position);
  44.             Console.Write('[');
  45.             Console.BackgroundColor = color;
  46.             Console.Write(bar);
  47.             Console.BackgroundColor = defaultColor;
  48.  
  49.             bar = "";
  50.  
  51.             for (int i = value; i < maxValue; i++)
  52.             {
  53.                 bar += symbolEmpty;
  54.             }
  55.             Console.Write(bar + ']');
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement