Advertisement
LeRoY_Go

Untitled

Feb 1st, 2022
1,780
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.  
  3. namespace C_Sharp_Junior
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int health = 5;
  10.             while (health > 0)
  11.             {
  12.                 DrawBar("Жизни | ", health);
  13.                 Console.SetCursorPosition(0, 3);
  14.                 Console.Write("Сколько у вас жизни:");
  15.                 health = Convert.ToInt32(Console.ReadLine());
  16.                 Console.Clear();
  17.             }
  18.             Console.WriteLine("Вы мертвы.");
  19.             Console.ReadKey();
  20.         }
  21.         static void DrawBar(string text, int health)
  22.         {
  23.             int maxPercent = 100;
  24.             int percent = maxPercent * health / 100;
  25.             string bar = "";
  26.             for (int i = 0; i < percent && i < maxPercent; i++)
  27.             {
  28.                 bar += "#";
  29.             }
  30.             Console.Write($"{text} [ {bar}");
  31.             bar = "";
  32.             for (int i = percent; i < maxPercent; i++)
  33.             {
  34.                 bar += "_";
  35.             }
  36.             Console.Write($"{bar}]");
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement