SHOW:
|
|
- or go back to the newest paste.
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); |
9 | + | DrawBar(50, 10, ConsoleColor.Red, 5, 5); |
10 | - | Bar(10, 8, 10, ConsoleColor.Blue, 6, 5); |
10 | + | DrawBar(10, 16, ConsoleColor.Green, 5, 6); |
11 | - | Bar(15, 76, 100, ConsoleColor.Gray, 5, 20); |
11 | + | DrawBar(100, 20, ConsoleColor.Yellow, 5, 7); |
12 | - | Bar(7, 45, 60, ConsoleColor.Green, 6, 20); |
12 | + | |
13 | } | |
14 | static void DrawBar(int FillingPercent, int sizeBar, ConsoleColor color, int xPos, int yPos) | |
15 | - | static void Bar(int size, int value, int maxValue, ConsoleColor color, int xPos, int yPos) |
15 | + | |
16 | if (FillingPercent > 100) | |
17 | - | size++; |
17 | + | FillingPercent = 100; |
18 | - | int filled = value * size / maxValue; // Перевод value в значение, которое должно быть закрашенным (обычная пропорция) |
18 | + | if (FillingPercent < 0) |
19 | - | Console.SetCursorPosition(yPos, xPos); |
19 | + | FillingPercent = 0; |
20 | - | for (int i = 0; i <= size; i++) |
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 | - | else if (i == size) |
27 | + | |
28 | } | |
29 | else if (i == sizeBar+1) | |
30 | { | |
31 | Console.ForegroundColor = ConsoleColor.White; | |
32 | - | else if (i <= filled) |
32 | + | |
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 | } |