MaoChessy

Task 20 - fix 2

Oct 31st, 2020 (edited)
125
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.             DrawBar(50, 10, ConsoleColor.Red, 5, 5);
  10.             DrawBar(10, 16, ConsoleColor.Green, 5, 6);
  11.             DrawBar(100, 20, ConsoleColor.Yellow, 5, 7);
  12.             Console.ReadKey();
  13.         }
  14.  
  15.         static void DrawBar(int fillingPercent, int sizeBar, ConsoleColor color, int xPos, int yPos)
  16.         {
  17.             if (fillingPercent > 100)
  18.                 fillingPercent = 100;
  19.             if (fillingPercent < 0)
  20.                 fillingPercent = 0;
  21.             int fillingPercentOfBar = sizeBar * fillingPercent / 100;
  22.             Console.SetCursorPosition(xPos, yPos);
  23.             for (int i = 0; i <= sizeBar + 1; i++)
  24.             {
  25.                 if (i == 0)
  26.                 {
  27.                     Console.ForegroundColor = ConsoleColor.White;
  28.                     Console.Write('[');
  29.                 }
  30.                 else if (i == sizeBar + 1)
  31.                 {
  32.                     Console.ForegroundColor = ConsoleColor.White;
  33.                     Console.Write(']');
  34.                 }
  35.                 else if (i <= fillingPercentOfBar)
  36.                 {
  37.                     Console.ForegroundColor = color;
  38.                     Console.Write('#');
  39.                 }
  40.                 else
  41.                 {
  42.                     Console.ForegroundColor = ConsoleColor.White;
  43.                     Console.Write('_');
  44.                 }
  45.             }
  46.         }
  47.     }
  48. }
Add Comment
Please, Sign In to add comment