Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _4._2
- {
- class Program
- {
- static void Main(string[] args)
- {
- drawBar(1, ConsoleColor.Magenta, 3, 1);
- drawBar(20, ConsoleColor.Yellow, 1, 2);
- drawBar(100, ConsoleColor.Green, 5, 3);
- drawBar(120, ConsoleColor.Yellow, 2, 4);
- }
- static void drawBar(int percentOfLive, ConsoleColor color, int positionX, int positionY)
- {
- if (percentOfLive >= 0 && percentOfLive <= 100)
- {
- int maxLife = 10;
- ConsoleColor defaultColor = Console.BackgroundColor;
- string bar = "";
- if (percentOfLive < 10)
- {
- percentOfLive = 1;
- }
- else if (percentOfLive > 10)
- {
- percentOfLive /= 10;
- }
- for (int i = 0; i < percentOfLive; i++)
- {
- bar += " ";
- }
- Console.SetCursorPosition(positionX, positionY);
- Console.BackgroundColor = defaultColor;
- Console.Write("[");
- Console.BackgroundColor = color;
- Console.Write(bar);
- bar = "";
- for (int i = percentOfLive; i < maxLife; i++)
- {
- bar += " ";
- }
- Console.BackgroundColor = defaultColor;
- Console.Write(bar + "]");
- }
- else
- {
- Console.WriteLine("\nОшибка ввода");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement