Advertisement
Briotar

Homework 4.2

May 16th, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 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.             float maxBar = 100;
  26.             int currentBarValue = Convert.ToInt32(maxBar / 100 * percent);
  27.             ConsoleColor defaultColor = Console.BackgroundColor;
  28.  
  29.             Console.Write("[");
  30.             Console.BackgroundColor = color;
  31.             for (int i = 0; i < currentBarValue; i++)
  32.             {
  33.                 Console.Write("#");
  34.             }
  35.             Console.BackgroundColor = defaultColor;
  36.             for (int i = currentBarValue; i < maxBar; i++)
  37.             {
  38.                 Console.Write("_");
  39.             }
  40.             Console.Write("]\n");
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement