SaNik74

UIElement

Mar 18th, 2023
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. using System;
  2.  
  3. internal class Program
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         string nameHealthBar = "Health";
  8.         string nameArmorBar = "Armor";
  9.         string nameStaminaBar = "Stamina";
  10.         string nameAmmoBar = "Ammo";
  11.         int percentHealth = 60;
  12.         int percentArmor = 100;
  13.         int percentStamina = 20;
  14.         int percentAmmo = 80;
  15.  
  16.         EditBar(nameHealthBar, percentHealth, ConsoleColor.Red, 0, 0);
  17.         EditBar(nameArmorBar, percentArmor, ConsoleColor.DarkYellow, 12, 0);
  18.         EditBar(nameStaminaBar, percentStamina, ConsoleColor.DarkBlue, 0, 3);
  19.         EditBar(nameAmmoBar, percentAmmo, ConsoleColor.DarkGray, 12, 3);
  20.     }
  21.  
  22.     static void EditBar(string nameBar, int precentOccupancy, ConsoleColor color, int positionX, int positionY, int maxValue = 10)
  23.     {
  24.         ConsoleColor defaultColour = Console.BackgroundColor;
  25.         string bar = "";
  26.         int occupancyValue = maxValue * precentOccupancy / 100;
  27.  
  28.         for (int i = 0; i < occupancyValue; i++)
  29.         {
  30.             bar += ' ';
  31.         }
  32.  
  33.         Console.SetCursorPosition(positionX, positionY);
  34.         Console.Write('[');
  35.         Console.BackgroundColor = color;
  36.         Console.Write(bar);
  37.         Console.BackgroundColor = defaultColour;
  38.  
  39.         bar = "";
  40.  
  41.         for (int i = occupancyValue; i < maxValue; i++)
  42.         {
  43.             bar += ' ';
  44.         }
  45.  
  46.         Console.Write($"{bar}]");
  47.         Console.SetCursorPosition(positionX + 3, positionY + 1);
  48.         Console.Write(nameBar);
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment