Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp3
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- int health = 20;
- int maxHealth = 1000;
- while(true)
- HealthBar(health, maxHealth, 3, 3, ConsoleColor.Red);
- }
- public static void HealthBar(int currentValue, int maxValue, int posX, int posY, ConsoleColor color, char barchar = ' ')
- {
- ConsoleColor defaultColor = Console.BackgroundColor;
- Console.BackgroundColor = color;
- string bar = "", hpChar = Convert.ToString(currentValue * 100 / maxValue);
- int barLength = 10;
- for(int i = 0; i < currentValue * barLength/maxValue; i++)
- {
- if (i == barLength / 2)
- {
- bar += hpChar + '%';
- }
- else
- {
- bar += barchar;
- }
- }
- Console.SetCursorPosition(posX, posY);
- Console.BackgroundColor = defaultColor;
- Console.Write('[');
- Console.BackgroundColor = color;
- Console.Write(bar);
- bar = "";
- for (int i = currentValue * barLength/maxValue; i < barLength; i++)
- {
- if (i == barLength / 2)
- {
- bar += hpChar + '%';
- }
- bar += barchar;
- }
- Console.BackgroundColor = defaultColor;
- Console.Write(bar);
- Console.Write(']');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement