Advertisement
illiden

HealthManaBar

Dec 4th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 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 HealthManaBar
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int precentHealth = 40;
  14.             DrawBar(precentHealth, 1, ConsoleColor.Red);
  15.             Console.ReadKey();
  16.         }
  17.  
  18.         static void DrawBar(int precent, int position, ConsoleColor color, int maxValue = 10)
  19.         {
  20.             ConsoleColor defaultColor = Console.BackgroundColor;
  21.             string bar = "";
  22.             int value = maxValue * precent / 100;
  23.  
  24.             for (int i = 0; i < value; i++)
  25.             {
  26.                 bar += "#";
  27.             }
  28.  
  29.             Console.SetCursorPosition(0, position);
  30.             Console.Write("[");
  31.             Console.BackgroundColor = color;
  32.             Console.Write(bar);
  33.             Console.BackgroundColor = defaultColor;
  34.  
  35.             bar = "";
  36.  
  37.             for (int i = value; i < maxValue; i++)
  38.             {
  39.                 bar += "_";
  40.             }
  41.             Console.Write(bar + "]");
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement