Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Clight_18_UIElement_HealthBar
- {
- class Program
- {
- static void Main(string[] args)
- {
- int health = 40;
- int healthMax = 100;
- int lenghtBar = 10;
- while (true)
- {
- DrawBar(health, healthMax, lenghtBar);
- Console.SetCursorPosition(0, 3);
- Console.Write($"Введите значение жизни от 0 до {healthMax}: ");
- string numUser = Console.ReadLine();
- bool result = int.TryParse(numUser, out int goodHealth);
- if (result == true && (goodHealth <= healthMax && goodHealth >=0))
- {
- health = goodHealth;
- }
- else
- {
- Console.WriteLine("Введите корректное число");
- Console.ReadKey();
- }
- Console.Clear();
- }
- static void DrawBar(int value, int valueMax, int lenghtBar, char symbolHealth = '#', char symbolEmpty = '_')
- {
- float step = valueMax / lenghtBar;
- Console.Write("[");
- for (int i = 0; i < lenghtBar; i++)
- {
- if (value > i*step)
- {
- Console.Write(symbolHealth);
- }
- else
- {
- Console.Write(symbolEmpty);
- }
- }
- Console.Write("]");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement