Advertisement
VoVfe

Untitled

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