Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CSLight
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int health = 3;
- int maxHealth = 10;
- int healthBarPositionX = 0;
- int healthBarPositionY = 0;
- int mana = 20;
- int maxMana = 100;
- int manaBarPositionX = 0;
- int manaBarPositionY = 1;
- DrawBar(health, maxHealth, ConsoleColor.Red, healthBarPositionX, healthBarPositionY);
- DrawBar(mana, maxMana, ConsoleColor.Blue, manaBarPositionX, manaBarPositionY);
- Console.ReadKey();
- }
- private static void DrawBar(int value, int maxValue, ConsoleColor color, int positionX, int positionY)
- {
- int barSize = 10;
- char barSymbol = ' ';
- ConsoleColor barColor = color;
- float maxPercent = 100;
- float valuePercent = Convert.ToSingle( value) / maxValue * maxPercent;
- float fulnessPercent = valuePercent / Convert.ToSingle(barSize);
- Console.Write("[");
- Console.BackgroundColor = barColor;
- DrawBarBlock(0, fulnessPercent, barSymbol);
- Console.ResetColor();
- DrawBarBlock(fulnessPercent, barSize, barSymbol);
- Console.ResetColor();
- Console.Write("]");
- Console.WriteLine();
- }
- private static void DrawBarBlock(float startDraw,float endDraw, char symbol)
- {
- for (float i = startDraw; i < endDraw; i++)
- {
- Console.Write(symbol);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement