Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- internal class Program
- {
- static void Main(string[] args)
- {
- string nameHealthBar = "Health";
- string nameArmorBar = "Armor";
- string nameStaminaBar = "Stamina";
- string nameAmmoBar = "Ammo";
- int percentHealth = 60;
- int percentArmor = 100;
- int percentStamina = 20;
- int percentAmmo = 80;
- EditBar(nameHealthBar, percentHealth, ConsoleColor.Red, 0, 0);
- EditBar(nameArmorBar, percentArmor, ConsoleColor.DarkYellow, 12, 0);
- EditBar(nameStaminaBar, percentStamina, ConsoleColor.DarkBlue, 0, 3);
- EditBar(nameAmmoBar, percentAmmo, ConsoleColor.DarkGray, 12, 3);
- }
- static void EditBar(string nameBar, int precentOccupancy, ConsoleColor color, int positionX, int positionY, int maxValue = 10)
- {
- ConsoleColor defaultColour = Console.BackgroundColor;
- string bar = "";
- int occupancyValue = maxValue * precentOccupancy / 100;
- for (int i = 0; i < occupancyValue; i++)
- {
- bar += ' ';
- }
- Console.SetCursorPosition(positionX, positionY);
- Console.Write('[');
- Console.BackgroundColor = color;
- Console.Write(bar);
- Console.BackgroundColor = defaultColour;
- bar = "";
- for (int i = occupancyValue; i < maxValue; i++)
- {
- bar += ' ';
- }
- Console.Write($"{bar}]");
- Console.SetCursorPosition(positionX + 3, positionY + 1);
- Console.Write(nameBar);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment