Skip to content

Instantly share code, notes, and snippets.

@StrikerXx798
Last active April 19, 2025 13:31
Show Gist options
  • Save StrikerXx798/6fea2a78b9e755546a10d58c69ab5a62 to your computer and use it in GitHub Desktop.
Save StrikerXx798/6fea2a78b9e755546a10d58c69ab5a62 to your computer and use it in GitHub Desktop.
ДЗ: UIElement
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