Advertisement
MaoChessy

Task 20

Oct 30th, 2020 (edited)
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. namespace C_sharp_Light
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Bar(10, 50, 100, ConsoleColor.Red, 5, 5);
  10.             Bar(10, 8, 10, ConsoleColor.Blue, 6, 5);
  11.             Bar(15, 76, 100, ConsoleColor.Gray, 5, 20);
  12.             Bar(7, 45, 60, ConsoleColor.Green, 6, 20);
  13.             Console.ReadKey();
  14.         }
  15.         static void Bar(int size, int value, int maxValue, ConsoleColor color, int xPos, int yPos)
  16.         {
  17.             size++;
  18.             int filled = value * size / maxValue; // Перевод value в значение, которое должно быть закрашенным (обычная пропорция)
  19.             Console.SetCursorPosition(yPos, xPos);
  20.             for (int i = 0; i <= size; i++)
  21.             {
  22.                 if (i == 0)
  23.                 {
  24.                     Console.ForegroundColor = ConsoleColor.White;
  25.                     Console.Write('[');
  26.                 }
  27.                 else if (i == size)
  28.                 {
  29.                     Console.ForegroundColor = ConsoleColor.White;
  30.                     Console.Write(']');
  31.                 }
  32.                 else if (i <= filled)
  33.                 {
  34.                     Console.ForegroundColor = color;
  35.                     Console.Write('#');
  36.                 }
  37.                 else
  38.                 {
  39.                     Console.ForegroundColor = ConsoleColor.White;
  40.                     Console.Write('_');
  41.                 }
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement