-
-
Save StrikerXx798/6fea2a78b9e755546a10d58c69ab5a62 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
using System; | |
using System.Text; | |
namespace ConsoleApp1 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.InputEncoding = Encoding.Unicode; | |
Console.OutputEncoding = Encoding.Unicode; | |
int maxHealth = 100; | |
int health = 120; | |
int maxMana = 50; | |
int mana = 50; | |
ConsoleColor healthColor = ConsoleColor.Red; | |
ConsoleColor manaColor = ConsoleColor.Blue; | |
DrawBar(health, maxHealth, healthColor); | |
Console.WriteLine(); | |
DrawBar(mana, maxMana, manaColor); | |
} | |
static void DrawBar(int value, int maxValue, ConsoleColor color) | |
{ | |
Console.ForegroundColor = color; | |
Console.Write("["); | |
int clampedValue = Math.Min(value, maxValue); | |
DrawBarSegment(clampedValue, '#'); | |
DrawBarSegment(maxValue - clampedValue, '_'); | |
Console.Write("]"); | |
Console.ForegroundColor = ConsoleColor.White; | |
} | |
static void DrawBarSegment(int length, char symbol) | |
{ | |
for (int i = 0; i < length; i++) | |
{ | |
Console.Write(symbol); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment