Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- DrawBar(nameHealthBar, percentHealth, ConsoleColor.Red, 0, 0);
- DrawBar(nameArmorBar, percentArmor, ConsoleColor.DarkYellow, 12, 0);
- DrawBar(nameStaminaBar, percentStamina, ConsoleColor.DarkBlue, 0, 3);
- DrawBar(nameAmmoBar, percentAmmo, ConsoleColor.DarkGray, 12, 3);
- }
- static void DrawBar(string nameBar, int precentOccupancy, ConsoleColor color, int positionX, int positionY, int maxValue = 10)
- {
- int fullLineInPercent = 100;
- int startingLinePosition = 0;
- if (precentOccupancy > fullLineInPercent)
- {
- precentOccupancy = fullLineInPercent;
- }
- if (precentOccupancy < 0)
- {
- precentOccupancy = startingLinePosition;
- }
- ConsoleColor defaultColour = Console.BackgroundColor;
- string bar = "";
- int occupancyValue = maxValue * precentOccupancy / fullLineInPercent;
- DrawBitOfBar(startingLinePosition, occupancyValue, ref bar);
- Console.SetCursorPosition(positionX, positionY);
- Console.Write('[');
- Console.BackgroundColor = color;
- Console.Write(bar);
- Console.BackgroundColor = defaultColour;
- bar = "";
- DrawBitOfBar(occupancyValue, maxValue, ref bar);
- Console.Write($"{bar}]");
- Console.SetCursorPosition(positionX + 3, positionY + 1);
- Console.Write(nameBar);
- }
- static void DrawBitOfBar(int startingPositionOfLine, int endOfLine, ref string bar)
- {
- for (int i = startingPositionOfLine; i < endOfLine; i++)
- {
- bar += ' ';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement