Advertisement
AlexStraga87

Healthbar

Feb 16th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement