Advertisement
CrewLab

day 04_2

May 23rd, 2019
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace Delegates
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int maxHelath = 1000;
  11.             int health = 400;
  12.  
  13.             DrawBar(health, maxHelath, 0, 0, ConsoleColor.Red);
  14.         }
  15.  
  16.         static void DrawBar(int currentValue, int maxValue, int posX, int posY, ConsoleColor color, char barChar = '#')
  17.         {
  18.             // Делю максимальное значение на 10 тем самым узнаю сколько процентно занимает одна десятая хелсбара
  19.             // После чего делю заполненную часть бара на это число для того чтобы узнать сколько десяток она занимает
  20.             // И приравниваю максимальное значение к десяти.
  21.             currentValue = currentValue / (maxValue / 10);
  22.             maxValue = 10;
  23.  
  24.             ConsoleColor defaultColor = Console.BackgroundColor;
  25.             Console.BackgroundColor = color;
  26.             string bar = "";
  27.  
  28.             for (int i = 0; i < currentValue; i++)
  29.                 bar += barChar;
  30.             Console.SetCursorPosition(posX, posY);
  31.  
  32.             Console.BackgroundColor = defaultColor;
  33.             Console.Write("[");
  34.             Console.BackgroundColor = color;
  35.             Console.Write(bar);
  36.  
  37.             bar = "";
  38.             barChar = '_';
  39.             for (int i = currentValue; i < maxValue; i++)
  40.                 bar += barChar;
  41.  
  42.             Console.BackgroundColor = defaultColor;
  43.             Console.Write(bar + "]");
  44.         }
  45.  
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement