Advertisement
pol9na

Untitled

Mar 23rd, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 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. namespace Study
  7. {
  8.     class Program
  9.    {
  10.         static void Main(string[] args)
  11.         {
  12.             int health = 4; int maxHealth = 10;
  13.             int mana = 3, maxMana = 10;
  14.             DrawBar(health, maxHealth, ConsoleColor.Red, 0, '#');
  15.             Console.WriteLine();
  16.             DrawBar(mana, maxMana, ConsoleColor.Blue, 1);
  17.         }
  18.         static void DrawBar(int value, int maxValue, ConsoleColor color, int position, char symbol = ' ')
  19.         {
  20.             ConsoleColor defaultColor = Console.BackgroundColor;
  21.             string bar = "";
  22.             for (int i = 0; i < value; i++)
  23.             {
  24.                 bar += symbol;
  25.             }
  26.             Console.SetCursorPosition(0, position);
  27.             Console.Write('[');
  28.             Console.BackgroundColor = color;
  29.             Console.Write(bar);
  30.             Console.BackgroundColor = defaultColor;
  31.             bar = "";
  32.             for (int i = value; i < maxValue; i++)
  33.             {
  34.                 bar += '_';
  35.             }
  36.             Console.Write(bar + ']');
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement