Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace Delegates
- {
- class Program
- {
- static void Main(string[] args)
- {
- int maxHelath = 1000;
- int health = 400;
- DrawBar(health, maxHelath, 0, 0, ConsoleColor.Red);
- }
- static void DrawBar(int currentValue, int maxValue, int posX, int posY, ConsoleColor color, char barChar = '#')
- {
- // Делю максимальное значение на 10 тем самым узнаю сколько процентно занимает одна десятая хелсбара
- // После чего делю заполненную часть бара на это число для того чтобы узнать сколько десяток она занимает
- // И приравниваю максимальное значение к десяти.
- currentValue = currentValue / (maxValue / 10);
- maxValue = 10;
- ConsoleColor defaultColor = Console.BackgroundColor;
- Console.BackgroundColor = color;
- string bar = "";
- for (int i = 0; i < currentValue; i++)
- bar += barChar;
- Console.SetCursorPosition(posX, posY);
- Console.BackgroundColor = defaultColor;
- Console.Write("[");
- Console.BackgroundColor = color;
- Console.Write(bar);
- bar = "";
- barChar = '_';
- for (int i = currentValue; i < maxValue; i++)
- bar += barChar;
- Console.BackgroundColor = defaultColor;
- Console.Write(bar + "]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement