SHARE
TWEET

Healthbar

AlexStraga87 Feb 16th, 2020 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             DrawBar(3, 0, 30);
  14.             DrawBar(3, 1, 50, ConsoleColor.Blue);
  15.  
  16.             Console.ReadKey();
  17.         }
  18.  
  19.         static void DrawBar(int posX, int posY, int percent, ConsoleColor color = ConsoleColor.Red)
  20.         {
  21.             Console.SetCursorPosition(posX, posY);
  22.             string bar = "";
  23.             percent /= 10;
  24.             for (int i = 0; i < percent; i++)
  25.             {
  26.                 bar += "#";
  27.             }
  28.             Console.Write("[");
  29.  
  30.             ConsoleColor prevColor = Console.BackgroundColor;            
  31.             Console.BackgroundColor = color;
  32.             Console.Write(bar);
  33.             Console.BackgroundColor = prevColor;
  34.  
  35.             bar = "";
  36.             for (int i = percent; i < 11; i++)
  37.             {
  38.                 bar += "_";
  39.             }
  40.  
  41.             bar += "]";
  42.             Console.Write(bar);
  43.         }
  44.  
  45.     }
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top