Advertisement
VoVfe

Untitled

May 11th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 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 _4t464
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Random rand = new Random();
  14.             int barSize = 10;
  15.             string hp = "Health -";
  16.             string mg = "Mana   -";
  17.             int percent = rand.Next(0, 11);
  18.             DrowBar(hp,percent,barSize,ConsoleColor.Red, 0, '_');
  19.             percent = rand.Next(0, 11);
  20.             DrowBar(mg,percent,barSize,ConsoleColor.DarkGreen, 1, '_');
  21.             Console.ReadKey();
  22.         }
  23.  
  24.         static void DrowBar(string name,int percent, int barSize,ConsoleColor color, int position,char symbol = ' ')
  25.         {
  26.             ConsoleColor defaultColor = Console.BackgroundColor;
  27.             string bar = "";
  28.             for (int i = 0; i < percent; i++)
  29.             {
  30.                 bar += symbol;
  31.             }
  32.             Console.SetCursorPosition(0, position);
  33.             Console.Write(name);
  34.             Console.Write('[');
  35.             Console.BackgroundColor = color;
  36.             Console.Write(bar);
  37.             Console.BackgroundColor = defaultColor;
  38.             bar = "";
  39.             for (int j = percent; j < barSize; j++)
  40.             {
  41.                 bar += symbol;
  42.             }
  43.             Console.Write($"{bar}]");
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement