Skip to content

Instantly share code, notes, and snippets.

@Strelok78
Last active May 13, 2025 13:24
Show Gist options
  • Save Strelok78/b39588990f4383c2a2b8c9a7df415543 to your computer and use it in GitHub Desktop.
Save Strelok78/b39588990f4383c2a2b8c9a7df415543 to your computer and use it in GitHub Desktop.
Parametr Bar in console
namespace iJuniorPractice
{
class Program
{
static void Main(string[] args)
{
float healthCurrentRate = 80;
float manaCurrentRate = 40;
int barLength = 10;
Console.WriteLine("Health ");
DrawBar(healthCurrentRate, barLength);
Console.WriteLine("Mana ");
DrawBar(manaCurrentRate, barLength);
}
static void DrawBar(float filledRate, int barLength)
{
string barLine = "";
char barFillElement = '#';
char barEmptyElement = '_';
char barOpen = '[';
char barClose = ']';
int maxRate = 100;
float filledValue = filledRate / maxRate * barLength;
barLine += FillBar(barFillElement, (int)filledValue);
barLine += FillBar(barEmptyElement, barLength - (int)filledValue);
Console.Write(barOpen + barLine + barClose + "\n");
}
static string FillBar(char fillElement, int fillLength)
{
string result = "";
for (int i = 0; i < fillLength; i++)
{
result += fillElement;
}
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment