Advertisement
Guest User

4.2

a guest
May 23rd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 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 Lessen4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int health;
  14.             int maxHealth = 10;
  15.             while(true)
  16.             {
  17.                 Console.Write("Введите количество жизней (0...100): ");
  18.                 health = Convert.ToInt32(Console.ReadLine());
  19.                 Console.WriteLine();
  20.                 Drawbar(health, maxHealth, 1, 1, ConsoleColor.Magenta);
  21.                 Console.ReadKey();
  22.                 Console.Clear();
  23.             }
  24.  
  25.  
  26.         }
  27.         static void Drawbar(int health, int maxValue, int posX, int posY, ConsoleColor color, char barChar =' ' )
  28.         {
  29.             if (health % 10 == 0)
  30.                 health = health / 10;
  31.             else
  32.                 health = health / 10+1;
  33.             ConsoleColor defaultColor = Console.BackgroundColor;
  34.             Console.BackgroundColor = color;
  35.             string bar = "";
  36.  
  37.             for(int i =0; i< health; i++)
  38.             {
  39.                 bar += barChar;
  40.             }
  41.  
  42.             Console.SetCursorPosition(posX, posY);
  43.  
  44.             Console.BackgroundColor = defaultColor;
  45.             Console.Write("[");
  46.             Console.BackgroundColor = color;
  47.             Console.Write(bar);
  48.             bar = "";
  49.  
  50.             for(int i = health; i<maxValue;i++)
  51.             {
  52.                 bar += barChar;
  53.             }
  54.             Console.BackgroundColor = defaultColor;
  55.             Console.Write(bar+"]");            
  56.         }
  57.  
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement