Advertisement
Briotar

Homework 4.1

May 14th, 2021
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Homework4
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int percentHealth;
  10.             int percentMana;
  11.  
  12.             Console.SetCursorPosition(0, 20);
  13.             Console.Write("Введите процент здоровья - ");
  14.             percentHealth = Convert.ToInt32(Console.ReadLine());
  15.             Console.Write("Введите процент маны - ");
  16.             percentMana = Convert.ToInt32(Console.ReadLine());
  17.  
  18.             Console.SetCursorPosition(0, 0);
  19.             DrawBar(percentHealth, ConsoleColor.Red);
  20.             DrawBar(percentMana, ConsoleColor.Blue);
  21.         }
  22.  
  23.         static void DrawBar(int percent, ConsoleColor color)
  24.         {
  25.             int currentBarValue = percent / 10;
  26.             ConsoleColor defaultColor = Console.BackgroundColor;
  27.  
  28.             Console.Write("[");
  29.             Console.BackgroundColor = color;
  30.             for (int i = 0; i < currentBarValue; i++)
  31.             {
  32.                 Console.Write("#");
  33.             }
  34.             Console.BackgroundColor = defaultColor;
  35.             for (int i = currentBarValue; i < 10; i++)
  36.             {
  37.                 Console.Write("_");
  38.             }
  39.             Console.Write("]\n");
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement