Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Ijunior
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int barLenght = 0;
- int minBarLenght = 10;
- int maxBarLenght = 100;
- int minPercent = 1;
- int maxPercent = 100;
- int health = 0;
- int mana = 0;
- int barPosition = 0;
- int percentResizeBar = 100;
- string wordBar = "бар";
- string wordHealth = "здоровье";
- string wordMana = "мана";
- barLenght = GetUserInput(wordBar, barLenght, minBarLenght, maxBarLenght);
- health = GetUserInput(wordHealth, health, minPercent, maxPercent);
- mana = GetUserInput(wordMana, mana, minPercent, maxPercent);
- health = (health * barLenght) / percentResizeBar;
- mana = (mana * barLenght) / percentResizeBar;
- DrawBar(health, barLenght, barPosition);
- barPosition++;
- DrawBar(mana, barLenght, barPosition);
- }
- static int GetUserInput(string word, int value, int minValue, int maxValue)
- {
- while (value < minValue || value > maxValue)
- {
- Console.Write($"Введите значение {word} больше {minValue} и меньше {maxValue}: ");
- value = ReadInt();
- }
- Console.Clear();
- return value;
- }
- static int ReadInt()
- {
- int number;
- while (int.TryParse(Console.ReadLine(), out number) == false)
- {
- Console.Write("Неккоректное значение. Введите положительное числовое значение: ");
- }
- return number;
- }
- static void DrawBar(int value, int totalValue, int barPosition)
- {
- char openFrame = '[';
- char closeFrame = ']';
- char barFilling = '#';
- char barEmpty = ' ';
- int firstIndex = 0;
- Console.SetCursorPosition(0, barPosition);
- Console.Write(openFrame);
- FillBar(firstIndex, value, barFilling);
- FillBar(value, totalValue, barEmpty);
- Console.Write(closeFrame);
- Console.WriteLine();
- }
- static void FillBar(int firstIndex, int lastIndex, char filling)
- {
- for (int i = firstIndex; i < lastIndex; i++)
- {
- Console.Write(filling);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment