Garloon

4.2

Sep 2nd, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 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 CSLight2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int posX = 0, posY = 0;
  14.             float health = 10;
  15.  
  16.             Console.WriteLine("Введи координаты расположения бара!\n");
  17.             Console.Write("Сместить по горизонтали на (0 - 10): ");
  18.             posX = Convert.ToInt32(Console.ReadLine());
  19.             Console.Write("Сместить по вертикали на (0 - 10): ");
  20.             posY = Convert.ToInt32(Console.ReadLine());
  21.  
  22.             Console.Clear();
  23.            
  24.             HealthBar(posX, posY, health);
  25.         }
  26.  
  27.         static void HealthBar(int posX, int posY, float health)
  28.         {
  29.             int maxHealth = 10;
  30.             bool barOn = true;
  31.            
  32.             while(barOn == true)
  33.             {
  34.                 ConsoleColor defaultColor = Console.BackgroundColor;
  35.                 string healthStats = "";
  36.  
  37.                 for (int i = 0; i < health; i++)
  38.                 {
  39.                     healthStats += ' ';
  40.                 }
  41.  
  42.                 Console.SetCursorPosition(posX, posY);
  43.                
  44.                 Console.Write("[");
  45.                 Console.BackgroundColor = ConsoleColor.Green;
  46.                 Console.Write(healthStats);
  47.  
  48.                 healthStats = "";
  49.  
  50.                 for (float i = health; i < maxHealth; i++)
  51.                 {
  52.                     healthStats += ' ';
  53.                 }
  54.                 Console.BackgroundColor = defaultColor;
  55.                 Console.WriteLine(healthStats + "]" + (health * 10) + "%");
  56.  
  57.                 Console.Write("Сколько сейчас процентов здоровья (0; 0,1...9,9; 10)? ");
  58.                 health = Convert.ToSingle(Console.ReadLine());
  59.                 Console.Clear();
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment