Advertisement
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 (Convert.ToInt32(Console.ReadLine()))
- {
- case 1:
- SetSettings(out int value, out int maxValue, out int barPositionX, out int barPositionY, out ConsoleColor color);
- DrawBar(value, maxValue, barPositionX, barPositionY, color);
- break;
- case 2:
- DefaultSettings(out value, out maxValue, out barPositionX, out barPositionY, out color);
- DrawBar(value, maxValue, barPositionX, barPositionY, color);
- 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)
- {
- 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;
- Console.Clear();
- }
- static void SetSettings(out int value, out int maxValue, out int barPositionX, out int barPositionY, out ConsoleColor color)
- {
- DefaultSettings(out value, out maxValue, out barPositionX, out barPositionY, out color);
- bool breakOut = true;
- int colorIndex;
- while (breakOut)
- {
- Console.Write("Введите начальное значение Полоски: ");
- value = Convert.ToInt32(Console.ReadLine());
- Console.Write("Введите максимальное значение Полоски: ");
- maxValue = Convert.ToInt32(Console.ReadLine());
- 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 )
- {
- 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 + ']');
- double precent = Convert.ToDouble(value) / Convert.ToDouble(maxValue) * 100;
- Console.WriteLine("\nПроцент: " + Math.Truncate(precent));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement