Advertisement
RedFlys

CSharpLight_HomeWork20 - Bar

Nov 10th, 2020
948
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CSharpLight_HomeWork20___Bar
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.CursorVisible = false;
  10.  
  11.             int healt = 5;
  12.             int maxHealth = 10;
  13.             int mana = 2;
  14.             int maxMana = 15;
  15.                        
  16.             DrawBar(maxHealth, healt, ConsoleColor.Red, 1, 1);
  17.             DrawBar(maxMana, mana, ConsoleColor.Blue, 5 + maxHealth, 1);
  18.  
  19.             Console.ReadKey();
  20.         }
  21.  
  22.         static void DrawBar(int maxValue, int value, ConsoleColor color, int positionX, int positionY)
  23.         {
  24.             ConsoleColor defaultColor = Console.BackgroundColor;
  25.             string bar = "";
  26.  
  27.             for (int i = 0; i < value; i++)
  28.             {
  29.                 bar += ' ';
  30.             }
  31.  
  32.             Console.SetCursorPosition(positionX, positionY);
  33.  
  34.             Console.Write("[");
  35.             Console.BackgroundColor = color;
  36.             Console.Write(bar);
  37.             Console.BackgroundColor = defaultColor;
  38.  
  39.             bar = "";
  40.  
  41.             for (int i = value; i < maxValue; i++)
  42.             {
  43.                 bar += ' ';
  44.             }
  45.  
  46.             Console.Write(bar + "]");
  47.         }
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement