Advertisement
pol9na

Untitled

Mar 22nd, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 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 Study
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int health = 4; int maxHealth = 10;
  14.             int mana = 3, maxMana = 10;
  15.  
  16.             DrawBar(health, maxHealth, ConsoleColor.Red, 0, '#');
  17.             DrawBar(mana, maxMana, ConsoleColor.Blue, 1);
  18.            
  19.            
  20.         }
  21.         static void DrawBar(int value, int maxValue, ConsoleColor color,int position, char symbol= ' ') {
  22.             ConsoleColor defaultColor = Console.BackgroundColor;
  23.             string bar = "";
  24.             for (int i = 0; i < value; i++) {
  25.                 bar += symbol;
  26.             }
  27.  
  28.             Console.SetCursorPosition(0, position);
  29.             Console.Write('[');
  30.             Console.BackgroundColor = color;
  31.             Console.Write(bar);
  32.             Console.BackgroundColor = defaultColor;
  33.             bar = "";
  34.             for (int i = value; i < maxValue; i++) {
  35.                 bar += '_';
  36.             }
  37.             Console.Write(bar + ']');
  38.  
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement