Advertisement
nikitaTheSlayer

Lesson: HealtBar

Apr 17th, 2020
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CSLight_4._2
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int health, maxHealth = 10;
  10.             int cursPosX, cursPosY;
  11.  
  12.             while (true)
  13.             {
  14.                 Console.WriteLine("Введите координаты положения курсора: ");
  15.                 cursPosX = Convert.ToInt32(Console.ReadLine());
  16.                 cursPosY = Convert.ToInt32(Console.ReadLine());
  17.  
  18.                 Console.WriteLine("Введите значение здоровья ");
  19.                 health = Convert.ToInt32(Console.ReadLine());
  20.  
  21.                 DrawBar(health, maxHealth, ConsoleColor.Red, cursPosX, cursPosY);
  22.  
  23.                 Console.ReadKey();
  24.                 Console.Clear();
  25.             }
  26.         }
  27.  
  28.         static void DrawBar(int value, int maxValue, ConsoleColor color, int positionX, int positionY)
  29.         {
  30.             ConsoleColor defaultColor = Console.BackgroundColor;
  31.             string bar = "";
  32.  
  33.             for (int i = 0; i < value; i++)
  34.             {
  35.                 bar += "#";
  36.             }
  37.  
  38.             Console.SetCursorPosition(positionX, positionY);
  39.             Console.Write("[");
  40.             Console.BackgroundColor = color;
  41.             Console.Write(bar);
  42.  
  43.             bar = "";
  44.  
  45.             for (int i = value; i < maxValue; i++)
  46.             {
  47.                 bar += " ";
  48.             }
  49.  
  50.             Console.Write(bar);
  51.             Console.BackgroundColor = defaultColor;
  52.             Console.Write("]");
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement