Advertisement
Torgach

UIELEMNT

Jan 23rd, 2021 (edited)
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Bar
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             bool isWork = true;
  14.  
  15.             Console.WriteLine("1 - Создать собственную Полоску;\n2 - создать начальную Полоску;\n3 - Выход");
  16.             while (isWork)
  17.             {
  18.                 Console.Write("\nВвод: ");
  19.                 switch (Console.ReadLine())
  20.                 {
  21.                     case "1":
  22.                         SetSettings(out int value, out int maxValue, out int barPositionX, out int barPositionY, out ConsoleColor color, out int userPercent, out bool isUserPercentageOfPaintedBar);
  23.  
  24.                         if(isUserPercentageOfPaintedBar == false)
  25.                         {
  26.                             DrawUserValuesBar(value, maxValue, barPositionX, barPositionY, color, isUserPercentageOfPaintedBar, userPercent);
  27.                         }
  28.                         else
  29.                         {
  30.                             DrawUserPercentBar(maxValue, barPositionX, barPositionY, color, isUserPercentageOfPaintedBar, userPercent);
  31.                         }
  32.  
  33.                         break;
  34.                     case "2":
  35.                         DefaultSettings(out value, out maxValue, out barPositionX, out barPositionY, out color, out userPercent, out isUserPercentageOfPaintedBar);
  36.                         DrawUserValuesBar(value, maxValue, barPositionX, barPositionY, color, isUserPercentageOfPaintedBar, userPercent);
  37.                         break;
  38.                     case "3":
  39.                         isWork = false;
  40.                         break;
  41.                     default:
  42.                         Console.WriteLine("Повторите ввод!");
  43.                         break;
  44.                 }
  45.             }
  46.         }
  47.         static void DefaultSettings(out int defaultValue, out int defaultMaxValue, out int defaultBarPositionX, out int defaultBarPositionY, out ConsoleColor defaultColor, out int userPercent, out bool isUserPercentageOfPaintedBar)
  48.         {
  49.             Random rand = new Random();
  50.             defaultValue = rand.Next(1, 15);
  51.             defaultMaxValue = defaultValue + rand.Next(1, 15);
  52.             defaultBarPositionX = rand.Next(0, 15);
  53.             defaultBarPositionY = rand.Next(0, 15);
  54.             defaultColor = ConsoleColor.Red;
  55.             userPercent = 33;
  56.             isUserPercentageOfPaintedBar = false;
  57.  
  58.             Console.Clear();
  59.         }
  60.         static void SetSettings(out int value, out int maxValue, out int barPositionX, out int barPositionY, out ConsoleColor color, out int userPercent, out bool isUserPercentageOfPaintedBar)
  61.         {
  62.             DefaultSettings(out value, out maxValue, out barPositionX, out barPositionY, out color, out userPercent, out isUserPercentageOfPaintedBar);
  63.  
  64.             bool breakOut = true;
  65.             int colorIndex;
  66.  
  67.             while (breakOut)
  68.             {
  69.                 Console.Write("Введите максимальное значение Полоски: ");
  70.                 maxValue = Convert.ToInt32(Console.ReadLine());
  71.  
  72.                 Console.WriteLine("1 - Ввести начальное значение Полоски;\n2 - Ввести процент от максимального значения Полоски;");
  73.                 Console.Write("Ввод: ");
  74.                 switch (Console.ReadLine())
  75.                 {
  76.                     case "1":
  77.                         Console.Write("Введите начальное значение Полоски: ");
  78.                         value = Convert.ToInt32(Console.ReadLine());
  79.                         break;
  80.                     case "2":
  81.                         Console.Write("Введите процент от максимального значения Полоски: ");
  82.                         userPercent = Convert.ToInt32(Console.ReadLine());
  83.                         isUserPercentageOfPaintedBar = true;
  84.                         break;
  85.  
  86.                 }
  87.  
  88.                 Console.Write("Укажите позицию Полоски - горизонталь: ");
  89.                 barPositionX = Convert.ToInt32(Console.ReadLine());
  90.  
  91.                 Console.Write("Укажите позицию Полоски - вертикаль: ");
  92.                 barPositionY = Convert.ToInt32(Console.ReadLine());
  93.  
  94.                 for (int i = 0; i < 3 && breakOut != false; ++i)
  95.                 {
  96.                     Console.Write("Укажите цвет Полоски от 1 до 16: ");
  97.                     colorIndex = (Convert.ToInt32(Console.ReadLine())) - 1;
  98.  
  99.                     if (colorIndex > 0 || colorIndex > 15)
  100.                     {
  101.                         color = (ConsoleColor)colorIndex;
  102.                         breakOut = false;
  103.                     }
  104.                     else
  105.                     {
  106.                         Console.WriteLine("Ошибка!");
  107.                     }
  108.                 }
  109.             }
  110.             Console.Clear();
  111.         }
  112.         static void DrawUserValuesBar(int value, int maxValue, int barPositionX, int barPositionY, ConsoleColor color, bool isUserPercentageOfPaintedBar, int userPercent)
  113.         {
  114.             ConsoleColor defaultColor = Console.BackgroundColor;
  115.  
  116.             string bar = "";
  117.  
  118.             for (int i = 0; i < value; i++)
  119.             {
  120.                 bar += '#';
  121.             }
  122.  
  123.             Console.SetCursorPosition(barPositionX, barPositionY);
  124.  
  125.             Console.Write('[');
  126.             Console.BackgroundColor = color;
  127.             Console.Write(bar);
  128.  
  129.             Console.BackgroundColor = defaultColor;
  130.             bar = "";
  131.  
  132.             for (int i = value; i < maxValue; i++)
  133.             {
  134.                 bar += '_';
  135.             }
  136.  
  137.             Console.Write(bar + ']');
  138.  
  139.             double precent = Convert.ToDouble(value) / Convert.ToDouble(maxValue) * 100;
  140.             Console.SetCursorPosition(barPositionX, barPositionY + 1);
  141.             Console.WriteLine("Процент: " + Math.Truncate(precent));
  142.  
  143.         }
  144.         static void DrawUserPercentBar(int maxValue, int barPositionX, int barPositionY, ConsoleColor color, bool isUserPercentageOfPaintedBar, int userPercent)
  145.         {
  146.             ConsoleColor defaultColor = Console.BackgroundColor;
  147.  
  148.             string bar = "";
  149.  
  150.             int tempUserPercent = (maxValue * userPercent) / 100;
  151.  
  152.             for (int i = 0; i < tempUserPercent; i++)
  153.             {
  154.                 bar += '#';
  155.             }
  156.  
  157.             Console.SetCursorPosition(barPositionX, barPositionY);
  158.  
  159.             Console.Write('[');
  160.             Console.BackgroundColor = color;
  161.             Console.Write(bar);
  162.  
  163.             Console.BackgroundColor = defaultColor;
  164.             bar = "";
  165.  
  166.             for (int i = tempUserPercent; i < maxValue; i++)
  167.             {
  168.                 bar += '_';
  169.             }
  170.  
  171.             Console.Write(bar + ']');
  172.  
  173.  
  174.             Console.SetCursorPosition(barPositionX, barPositionY + 1);
  175.             Console.Write("Процент: " + userPercent);
  176.         }
  177.     }
  178. }
  179.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement