Advertisement
trmaxa2820

CSharpTask

Feb 14th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 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 CSharpLightTask
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             char symbol = '#';
  14.             int value = 15;
  15.             int maxValue = 20;
  16.            
  17.             DrawBar(symbol, value, maxValue, 0, 10);
  18.             DrawBar('@', 11, 20, 0, 11, 50, color:ConsoleColor.Blue);
  19.             Console.ReadKey();
  20.         }
  21.         static void DrawBar(char symbol, int value, int maxValue, int x, int y, int coloredPercent = 100 , ConsoleColor color = ConsoleColor.Red)
  22.         {
  23.             ConsoleColor defaultColor = Console.ForegroundColor;
  24.             Console.SetCursorPosition(x, y);
  25.             Console.ForegroundColor = defaultColor;
  26.             Console.Write("[");
  27.             string[] bar = new string[maxValue];
  28.             for (int i = 0; i < bar.Length; i++)
  29.             {
  30.                 if(i < (Convert.ToSingle(Convert.ToSingle(maxValue) / 100) * coloredPercent) - 1)
  31.                 {
  32.                     Console.ForegroundColor = color;
  33.                 }
  34.                 else
  35.                 {
  36.                     Console.ForegroundColor = defaultColor;
  37.                 }
  38.  
  39.                 if (i < value)
  40.                 {
  41.                     Console.Write(symbol);
  42.                 }
  43.  
  44.                 else if (bar[i] == null)
  45.                 {
  46.                     Console.Write(" ");
  47.                 }
  48.             }
  49.             Console.ForegroundColor = defaultColor;
  50.             Console.Write("]");
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement