Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace C_sharp_Light
- {
- class Program
- {
- static void Main(string[] args)
- {
- Bar(10, 50, 100, ConsoleColor.Red, 5, 5);
- Bar(10, 8, 10, ConsoleColor.Blue, 6, 5);
- Bar(15, 76, 100, ConsoleColor.Gray, 5, 20);
- Bar(7, 45, 60, ConsoleColor.Green, 6, 20);
- Console.ReadKey();
- }
- static void Bar(int size, int value, int maxValue, ConsoleColor color, int xPos, int yPos)
- {
- size++;
- int filled = value * size / maxValue; // Перевод value в значение, которое должно быть закрашенным (обычная пропорция)
- Console.SetCursorPosition(yPos, xPos);
- for (int i = 0; i <= size; i++)
- {
- if (i == 0)
- {
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write('[');
- }
- else if (i == size)
- {
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write(']');
- }
- else if (i <= filled)
- {
- Console.ForegroundColor = color;
- Console.Write('#');
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write('_');
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement