Last active
March 25, 2024 20:18
-
-
Save kyzalex/e43dd4d1124d7fd0ea9aeb85a605c316 to your computer and use it in GitHub Desktop.
UIElement
This file contains 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
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int maxPercent = 100; | |
Console.Write("Введите количество процентов для здоровья : "); | |
double percentOfHealth = Convert.ToDouble(Console.ReadLine()); | |
Console.Write("Введите количество процентов для манны : "); | |
double percentOfManna = Convert.ToDouble(Console.ReadLine()); | |
Console.Write("Введите количество здоровья всего: "); | |
double maxHealth = Convert.ToDouble(Console.ReadLine()); | |
Console.Write("Введите количество манны всего: "); | |
double maxMana = Convert.ToDouble(Console.ReadLine()); | |
double percent = 100.0; | |
double health = CalculateThePercentage(percentOfHealth, maxHealth, percent); | |
DrawBar(health, maxHealth, ConsoleColor.Red, 5, percentOfHealth, maxPercent); | |
double mana = CalculateThePercentage(percentOfManna, maxMana, percent); | |
DrawBar(mana, maxMana, ConsoleColor.Blue, 6, percentOfManna, maxPercent); | |
Console.ReadKey(); | |
} | |
static void DrawBar(double size, double maxSize, ConsoleColor color, int position, double percentOfValue, int maxPercent) | |
{ | |
if (percentOfValue > 0 && percentOfValue <= maxPercent) | |
{ | |
string bar = ""; | |
ConsoleColor defaultColore = Console.BackgroundColor; | |
bar = WriteLoopBar(0, size, '%'); | |
Console.SetCursorPosition(0, position); | |
Console.Write('['); | |
Console.BackgroundColor = color; | |
Console.Write(bar); | |
Console.BackgroundColor = defaultColore; | |
bar = ""; | |
bar = WriteLoopBar(size, maxSize, '_'); | |
Console.Write(bar + "]"); | |
} | |
else | |
{ | |
Console.WriteLine("Вы ввели не правильно число"); | |
} | |
} | |
static string WriteLoopBar(double value, double maxValue, char symbol) | |
{ | |
string bar = ""; | |
for (double i = value; i < maxValue; i++) | |
{ | |
bar += symbol; | |
} | |
return bar; | |
} | |
static double CalculateThePercentage(double number, double maxNumber, double percent) | |
{ | |
double value; | |
value = (maxNumber / percent) * number; | |
return value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment