lovelyvook

Unit_28

Jun 28th, 2024 (edited)
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.59 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Ijunior
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int barLenght = 0;
  10.             int minBarLenght = 10;
  11.             int maxBarLenght = 100;
  12.             int minPercent = 1;
  13.             int maxPercent = 100;
  14.             int health = 0;
  15.             int mana = 0;
  16.             int barPosition = 0;
  17.             int percentResizeBar = 100;
  18.             string wordBar = "бар";
  19.             string wordHealth = "здоровье";
  20.             string wordMana = "мана";
  21.  
  22.             barLenght = GetUserInput(wordBar, barLenght, minBarLenght, maxBarLenght);
  23.             health = GetUserInput(wordHealth, health, minPercent, maxPercent);
  24.             mana = GetUserInput(wordMana, mana, minPercent, maxPercent);
  25.  
  26.             health = (health * barLenght) / percentResizeBar;
  27.             mana = (mana * barLenght) / percentResizeBar;
  28.  
  29.             DrawBar(health, barLenght, barPosition);
  30.             barPosition++;
  31.             DrawBar(mana, barLenght, barPosition);
  32.         }
  33.  
  34.         static int GetUserInput(string word, int value, int minValue, int maxValue)
  35.         {
  36.             while (value < minValue || value > maxValue)
  37.             {
  38.                 Console.Write($"Введите значение {word} больше {minValue} и меньше {maxValue}: ");
  39.                 value = ReadInt();
  40.             }
  41.  
  42.             Console.Clear();
  43.             return value;
  44.         }
  45.  
  46.         static int ReadInt()
  47.         {
  48.             int number;
  49.  
  50.             while (int.TryParse(Console.ReadLine(), out number) == false)
  51.             {
  52.                 Console.Write("Неккоректное значение. Введите положительное числовое значение: ");
  53.             }
  54.  
  55.             return number;
  56.         }
  57.  
  58.         static void DrawBar(int value, int totalValue, int barPosition)
  59.         {
  60.             char openFrame = '[';
  61.             char closeFrame = ']';
  62.             char barFilling = '#';
  63.             char barEmpty = ' ';
  64.             int firstIndex = 0;
  65.  
  66.             Console.SetCursorPosition(0, barPosition);
  67.             Console.Write(openFrame);
  68.  
  69.             FillBar(firstIndex, value, barFilling);
  70.             FillBar(value, totalValue, barEmpty);
  71.  
  72.             Console.Write(closeFrame);
  73.             Console.WriteLine();
  74.         }
  75.  
  76.         static void FillBar(int firstIndex, int lastIndex, char filling)
  77.         {
  78.             for (int i = firstIndex; i < lastIndex; i++)
  79.             {
  80.                 Console.Write(filling);
  81.             }
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment