Advertisement
junniorrkaa

UIElement

Dec 16th, 2024 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | Source Code | 0 0
  1. using System;
  2.  
  3. namespace CSLight
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int healthPercent = 0;
  10.             int manaPercent = 0;
  11.             int maxValue = 10;
  12.             int maxPercent = 100;
  13.  
  14.             while (maxPercent >= healthPercent && maxPercent >= manaPercent)
  15.             {
  16.                 DrawnBar(maxValue, healthPercent, 0);
  17.                 DrawnBar(maxValue, manaPercent, 2);
  18.  
  19.                 Console.SetCursorPosition(0, 4);
  20.  
  21.                 Console.WriteLine("Введите желаемый процент(%) жизни (от 0 до 100): ");
  22.                 healthPercent = Convert.ToInt32(Console.ReadLine());
  23.                 Console.WriteLine("Введите желаемый процент(%) маны (от 0 до 100): ");
  24.                 manaPercent = Convert.ToInt32(Console.ReadLine());
  25.  
  26.                 Console.ReadKey();
  27.                 Console.Clear();
  28.             }
  29.         }
  30.  
  31.         static void DrawnBar(int maxValue, int percent, int position)
  32.         {
  33.             string tempBar;
  34.  
  35.             char openSymbol = '[';
  36.             char closeSymbol = ']';
  37.             char percentSymbol = '#';
  38.             char excessSymbol = '_';
  39.  
  40.             int percentLength = percent / maxValue; ;
  41.             int excessLength = maxValue - percentLength;
  42.  
  43.             Console.SetCursorPosition(0, position);
  44.  
  45.             tempBar = FillLine(percentLength, symbol: percentSymbol);
  46.             Console.Write(openSymbol + tempBar);
  47.  
  48.             tempBar = FillLine(excessLength, symbol: excessSymbol);
  49.             Console.Write(tempBar + closeSymbol);
  50.         }
  51.  
  52.         static string FillLine(int value, char symbol)
  53.         {
  54.             string bar = "";
  55.  
  56.             for (int i = 0; i < value; i++)
  57.             {
  58.                 bar += symbol;
  59.             }
  60.  
  61.             return bar;
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement