Advertisement
Torgach

Создание бара

Jan 22nd, 2021 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 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 (Convert.ToInt32(Console.ReadLine()))
  20. {
  21. case 1:
  22. SetSettings(out int value, out int maxValue, out int barPositionX, out int barPositionY, out ConsoleColor color);
  23. DrawBar(value, maxValue, barPositionX, barPositionY, color);
  24. break;
  25. case 2:
  26. DefaultSettings(out value, out maxValue, out barPositionX, out barPositionY, out color);
  27. DrawBar(value, maxValue, barPositionX, barPositionY, color);
  28. break;
  29. case 3:
  30. isWork = false;
  31. break;
  32. default:
  33. Console.WriteLine("Повторите ввод!");
  34. break;
  35. }
  36. }
  37. }
  38. static void DefaultSettings(out int defaultValue, out int defaultMaxValue, out int defaultBarPositionX, out int defaultBarPositionY, out ConsoleColor defaultColor)
  39. {
  40. Random rand = new Random();
  41. defaultValue = rand.Next(1,15);
  42. defaultMaxValue = defaultValue + rand.Next(1, 15);
  43. defaultBarPositionX = rand.Next(0, 15);
  44. defaultBarPositionY = rand.Next(0, 15);
  45. defaultColor = ConsoleColor.Red;
  46.  
  47. Console.Clear();
  48. }
  49. static void SetSettings(out int value, out int maxValue, out int barPositionX, out int barPositionY, out ConsoleColor color)
  50. {
  51. DefaultSettings(out value, out maxValue, out barPositionX, out barPositionY, out color);
  52. bool breakOut = true;
  53. int colorIndex;
  54.  
  55. while (breakOut)
  56. {
  57. Console.Write("Введите начальное значение Полоски: ");
  58. value = Convert.ToInt32(Console.ReadLine());
  59.  
  60. Console.Write("Введите максимальное значение Полоски: ");
  61. maxValue = Convert.ToInt32(Console.ReadLine());
  62.  
  63. Console.Write("Укажите позицию Полоски - вертикаль: ");
  64. barPositionX = Convert.ToInt32(Console.ReadLine());
  65.  
  66. Console.Write("Укажите позицию Полоски - вертикаль: ");
  67. barPositionY = Convert.ToInt32(Console.ReadLine());
  68.  
  69. for (int i = 0; i < 3 && breakOut != false; ++i)
  70. {
  71. Console.Write("Укажите цвет Полоски от 1 до 16: ");
  72. colorIndex = (Convert.ToInt32(Console.ReadLine())) - 1;
  73.  
  74. if (colorIndex > 0 || colorIndex > 15)
  75. {
  76. color = (ConsoleColor)colorIndex;
  77. breakOut = false;
  78. }
  79. else
  80. {
  81. Console.WriteLine("Ошибка!");
  82. }
  83. }
  84. }
  85. Console.Clear();
  86. }
  87. static void DrawBar(int value, int maxValue, int barPositionX, int barPositionY, ConsoleColor color )
  88. {
  89. ConsoleColor defaultColor = Console.BackgroundColor;
  90.  
  91. string bar = "";
  92.  
  93. for (int i = 0; i < value; i++)
  94. {
  95. bar += '#';
  96. }
  97.  
  98. Console.SetCursorPosition(barPositionX, barPositionY);
  99.  
  100. Console.Write('[');
  101. Console.BackgroundColor = color;
  102. Console.Write(bar);
  103. Console.BackgroundColor = defaultColor;
  104.  
  105. bar = "";
  106.  
  107. for (int i = value; i < maxValue; i++)
  108. {
  109. bar += '_';
  110. }
  111.  
  112. Console.Write(bar + ']');
  113.  
  114. double precent = Convert.ToDouble(value) / Convert.ToDouble(maxValue) * 100;
  115. Console.WriteLine("\nПроцент: " + Math.Truncate(precent));
  116. }
  117. }
  118. }
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement