Advertisement
MaoChessy

Task 20 - fix

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