Last active
May 13, 2025 13:24
-
-
Save Strelok78/b39588990f4383c2a2b8c9a7df415543 to your computer and use it in GitHub Desktop.
Parametr Bar in console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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