Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Home_Work
- {
- class Program
- {
- static void Main(string[] args)
- {
- int maxHealth = 100;
- int health = 55;
- int healthPositionY = 0;
- ConsoleColor healthColor = ConsoleColor.Red;
- int maxMana = 200;
- int mana = 2000;
- int manaPositionY = 1;
- ConsoleColor manaColor = ConsoleColor.Blue;
- DrawBar(health, maxHealth, healthPositionY, healthColor);
- DrawBar(mana, maxMana, manaPositionY, manaColor);
- Console.ReadKey();
- }
- static void DrawBar(int value, int maxValue, int positionY, ConsoleColor backgroundColor)
- {
- Console.SetCursorPosition(0, positionY);
- if (CheckValueInvalid(value, maxValue))
- {
- Console.WriteLine("Ошибка данных!");
- return;
- }
- string bar;
- ConsoleColor defaulthColor = Console.BackgroundColor;
- int percentValue = value * 10 / maxValue;
- bar = CalculateBar(0, percentValue);
- Console.Write("[");
- Console.BackgroundColor = backgroundColor;
- Console.Write(bar);
- bar = CalculateBar(percentValue, 10);
- Console.BackgroundColor = defaulthColor;
- Console.Write(bar);
- Console.Write("]");
- }
- static string CalculateBar (int startValue, int endValue)
- {
- string bar = "";
- char barElement = ' ';
- for (int i = startValue; i < endValue; i++)
- {
- bar += barElement;
- }
- return bar;
- }
- static bool CheckValueInvalid(int value, int maxValue)
- {
- if (value < 0 || value > maxValue)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement