Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Bar
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool isWork = true;
- Console.WriteLine("1 - Создать собственную Полоску;\n2 - создать начальную Полоску;\n3 - Выход");
- while (isWork)
- {
- Console.Write("\nВвод: ");
- switch (Console.ReadLine())
- {
- case "1":
- SetSettings(out int value, out int maxValue, out int barPositionX, out int barPositionY, out ConsoleColor color, out int userProcent, out bool isUserPercentageOfPaintedBar);
- DrawBar(value, maxValue, barPositionX, barPositionY, color, isUserPercentageOfPaintedBar, userProcent);
- break;
- case "2":
- DefaultSettings(out value, out maxValue, out barPositionX, out barPositionY, out color, out userProcent, out isUserPercentageOfPaintedBar);
- DrawBar(value, maxValue, barPositionX, barPositionY, color, isUserPercentageOfPaintedBar, userProcent);
- break;
- case "3":
- isWork = false;
- break;
- default:
- Console.WriteLine("Повторите ввод!");
- break;
- }
- }
- }
- static void DefaultSettings(out int defaultValue, out int defaultMaxValue, out int defaultBarPositionX, out int defaultBarPositionY, out ConsoleColor defaultColor, out int userProcent, out bool isUserPercentageOfPaintedBar)
- {
- Random rand = new Random();
- defaultValue = rand.Next(1, 15);
- defaultMaxValue = defaultValue + rand.Next(1, 15);
- defaultBarPositionX = rand.Next(0, 15);
- defaultBarPositionY = rand.Next(0, 15);
- defaultColor = ConsoleColor.Red;
- userProcent = 33;
- isUserPercentageOfPaintedBar = false;
- Console.Clear();
- }
- static void SetSettings(out int value, out int maxValue, out int barPositionX, out int barPositionY, out ConsoleColor color, out int userProcent, out bool isUserPercentageOfPaintedBar)
- {
- DefaultSettings(out value, out maxValue, out barPositionX, out barPositionY, out color, out userProcent, out isUserPercentageOfPaintedBar);
- bool breakOut = true;
- int colorIndex;
- while (breakOut)
- {
- Console.Write("Введите максимальное значение Полоски: ");
- maxValue = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("1 - Ввести начальное значение Полоски;\n2 - Ввести процент от максимального значения Полоски;");
- Console.Write("Ввод: ");
- switch (Console.ReadLine())
- {
- case "1":
- Console.Write("Введите начальное значение Полоски: ");
- value = Convert.ToInt32(Console.ReadLine());
- break;
- case "2":
- Console.Write("Введите процент от максимального значения Полоски: ");
- userProcent = Convert.ToInt32(Console.ReadLine());
- isUserPercentageOfPaintedBar = true;
- break;
- }
- Console.Write("Укажите позицию Полоски - горизонталь: ");
- barPositionX = Convert.ToInt32(Console.ReadLine());
- Console.Write("Укажите позицию Полоски - вертикаль: ");
- barPositionY = Convert.ToInt32(Console.ReadLine());
- for (int i = 0; i < 3 && breakOut != false; ++i)
- {
- Console.Write("Укажите цвет Полоски от 1 до 16: ");
- colorIndex = (Convert.ToInt32(Console.ReadLine())) - 1;
- if (colorIndex > 0 || colorIndex > 15)
- {
- color = (ConsoleColor)colorIndex;
- breakOut = false;
- }
- else
- {
- Console.WriteLine("Ошибка!");
- }
- }
- }
- Console.Clear();
- }
- static void DrawBar(int value, int maxValue, int barPositionX, int barPositionY, ConsoleColor color, bool isUserPercentageOfPaintedBar, int userProcent)
- {
- ConsoleColor defaultColor = Console.BackgroundColor;
- string bar = "";
- for (int i = 0; i < value; i++)
- {
- bar += '#';
- }
- Console.SetCursorPosition(barPositionX, barPositionY);
- Console.Write('[');
- Console.BackgroundColor = color;
- Console.Write(bar);
- Console.BackgroundColor = defaultColor;
- bar = "";
- for (int i = value; i < maxValue; i++)
- {
- bar += '_';
- }
- Console.Write(bar + ']');
- if (isUserPercentageOfPaintedBar == false)
- {
- double precent = Convert.ToDouble(value) / Convert.ToDouble(maxValue) * 100;
- Console.SetCursorPosition(barPositionX, barPositionY + 1);
- Console.WriteLine("Процент: " + Math.Truncate(precent));
- }
- else
- {
- Console.SetCursorPosition(barPositionX, barPositionY + 1);
- Console.Write("Процент: " + userProcent);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment