Created
May 19, 2025 09:45
-
-
Save RaitonFan/39de752ce63e283901fdc5b6a06b1579 to your computer and use it in GitHub Desktop.
ДЗ: UIElement
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
using System; | |
class Program | |
{ | |
static void Main() | |
{ | |
int healthInLine = 10; | |
int manaInLine = 11; | |
float maxPercent = 100; | |
float maxHealth = ReadInt("Введите максимальное количество здоровья: "); | |
float health = (ReadInt("Введите текущее количество здоровья в %: ") / maxPercent) * maxHealth; | |
float maxMana = ReadInt("Введите максимальное количество маны: "); | |
float mana = (ReadInt("Введите текущее количество маны в %: ") / maxPercent) * maxMana; | |
DrawBar(health, maxHealth, ConsoleColor.Red, healthInLine, "Здоровье"); | |
DrawBar(mana, maxMana, ConsoleColor.Blue, manaInLine, "Мана"); | |
} | |
static void DrawBar(float value, float maxValue, ConsoleColor color, int position, string parametr) | |
{ | |
ConsoleColor defaultColor = Console.BackgroundColor; | |
string bar = ""; | |
Console.SetCursorPosition(0, position); | |
Console.Write('['); | |
for (int i = 0; i < maxValue; i++) | |
{ | |
if (i <= value) | |
{ | |
bar += "#"; | |
} | |
else | |
{ | |
bar += '_'; | |
} | |
} | |
Console.BackgroundColor = color; | |
Console.Write(bar); | |
Console.BackgroundColor = defaultColor; | |
Console.WriteLine(']' + parametr); | |
} | |
static int ReadInt(string text) | |
{ | |
string userInput = ""; | |
int number; | |
while (!int.TryParse(userInput, out number)) | |
{ | |
Console.Write(text); | |
userInput = Console.ReadLine(); | |
} | |
return number; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment