Skip to content

Instantly share code, notes, and snippets.

@FleamRus
Last active May 16, 2024 06:40
Show Gist options
  • Save FleamRus/45a8c2003219d941716ea585752219a2 to your computer and use it in GitHub Desktop.
Save FleamRus/45a8c2003219d941716ea585752219a2 to your computer and use it in GitHub Desktop.
UIElement
using System;
namespace UIElement
{
internal class Program
{
static void Main(string[] args)
{
int percentOfHp = 50;
int percentOfMana = 80;
int maxBarLenght = 20;
DrawStatusBar(maxBarLenght, percentOfHp, ConsoleColor.Green, 0);
DrawStatusBar(maxBarLenght, percentOfMana, ConsoleColor.Blue, 1);
}
static void DrawStatusBar(int barLengh, int percent, ConsoleColor color, int position, char symbol = '|')
{
ConsoleColor defaultColor = Console.BackgroundColor;
string bar = "";
int percentRatio = 100;
int filledLenght = barLengh * percent / percentRatio;
bar = FillTheBar(0, filledLenght, '@');
Console.SetCursorPosition(0, position);
Console.Write('[');
Console.BackgroundColor = color;
Console.Write(bar);
Console.BackgroundColor = defaultColor;
bar = FillTheBar(filledLenght, barLengh, '#');
Console.WriteLine(bar + ']');
}
static string FillTheBar(int startValue, int finishValue, char symbol)
{
string bar = "";
for (int i = startValue; i < finishValue; i++)
{
bar += symbol;
}
return bar;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment