Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save niklib-go/ba5e5ba3ecd8f0d1150707e0ec5052aa to your computer and use it in GitHub Desktop.
Save niklib-go/ba5e5ba3ecd8f0d1150707e0ec5052aa to your computer and use it in GitHub Desktop.
using System;
namespace CLa
{
class Program
{
static void Main()
{
int healthbarPosX = 30;
int healthbarPosY = 1;
int healthbarLength = 10;
int healthbarPercentValue = 40;
RenderHealthdar(healthbarPercentValue, healthbarLength, healthbarPosX, healthbarPosY);
}
static void RenderHealthdar(int healthbarPercentValue, int healthbarLength, int healthbarPosX, int healthbarPosY)
{
ConsoleColor defalutBackgroundColor = Console.BackgroundColor;
ConsoleColor defaultForegroundColor = Console.ForegroundColor;
int filledLngth = healthbarPercentValue * healthbarLength / 100;
Console.SetCursorPosition(healthbarPosX, healthbarPosY);
Console.Write("[");
Console.BackgroundColor = ConsoleColor.Red;
Console.ForegroundColor = ConsoleColor.White;
for (int i = 0; i < filledLngth; i++)
{
Console.Write("#");
}
Console.BackgroundColor = ConsoleColor.DarkGray;
for (int i = 0; i < healthbarLength - filledLngth; i++)
{
Console.Write("_");
}
Console.BackgroundColor = defalutBackgroundColor;
Console.ForegroundColor = defaultForegroundColor;
Console.Write("]");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment