Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- char symbolHelthBar = ' ';
- int positionX = 10;
- int positionY = 10;
- double percentHP = 0;
- Console.WriteLine("Введите процент жизней.");
- percentHP = double.Parse(Console.ReadLine());
- Console.WriteLine("Введите позицию по X");
- positionX = int.Parse(Console.ReadLine());
- Console.WriteLine("Введите позицию по Y");
- positionY = int.Parse(Console.ReadLine());
- symbolHelthBar = GetSymbol();
- RenderHealthBar(percentHP, symbolHelthBar, positionX, positionY);
- }
- private static void RenderHealthBar(double percentHP, char symbolHealthBar, int positionX, int positionY, int lengthBar = 10, char openBracket = '[', char closeBracket = ']', char symbolEmptyCells = '_')
- {
- Console.Clear();
- Console.SetCursorPosition(positionX, positionY);
- string bar = string.Empty;
- int maxPercent = 100;
- int minPercent = 0;
- if (percentHP == 0)
- {
- bar = FillEmptyCells(bar,lengthBar);
- Console.WriteLine(openBracket + bar + closeBracket);
- }
- else if (percentHP > minPercent && percentHP <= maxPercent)
- {
- int countHP = (int)Math.Round(lengthBar * (percentHP / maxPercent));
- bar = FillEmptyCells(bar, countHP, symbolHealthBar);
- bar = FillEmptyCells(bar, lengthBar - bar.Length);
- Console.WriteLine(openBracket + bar + closeBracket);
- }
- else
- {
- Console.WriteLine("Вы ввели некорректное число");
- }
- }
- private static char GetSymbol()
- {
- char symbol = ' ';
- Console.WriteLine("Введите символ для Healthbar");
- while (!char.TryParse(Console.ReadLine(), out symbol))
- {
- Console.WriteLine("Неверный ввод");
- }
- return symbol;
- }
- private static string FillEmptyCells(string bar, int lengthBar, char symbolEmptyCells = '_')
- {
- for (int i = 0; i < count; i++)
- {
- bar += symbol;
- }
- return bar;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement