Advertisement
loleckek228

4.2

Sep 15th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _4._2
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             drawBar(1, ConsoleColor.Magenta, 3, 1);
  10.             drawBar(20, ConsoleColor.Yellow, 1, 2);
  11.             drawBar(100, ConsoleColor.Green, 5, 3);
  12.             drawBar(120, ConsoleColor.Yellow, 2, 4);
  13.         }
  14.  
  15.         static void drawBar(int percentOfLive, ConsoleColor color, int positionX, int positionY)
  16.         {
  17.             if (percentOfLive >= 0 && percentOfLive <= 100)
  18.             {
  19.                 int maxLife = 10;
  20.                 ConsoleColor defaultColor = Console.BackgroundColor;
  21.                 string bar = "";
  22.  
  23.                 if (percentOfLive < 10)
  24.                 {
  25.                     percentOfLive = 1;
  26.                 }
  27.                 else if (percentOfLive > 10)
  28.                 {
  29.                     percentOfLive /= 10;
  30.                 }
  31.  
  32.                 for (int i = 0; i < percentOfLive; i++)
  33.                 {
  34.                     bar += " ";
  35.                 }
  36.                 Console.SetCursorPosition(positionX, positionY);
  37.                 Console.BackgroundColor = defaultColor;
  38.                 Console.Write("[");
  39.                 Console.BackgroundColor = color;
  40.                 Console.Write(bar);
  41.  
  42.                 bar = "";
  43.  
  44.                 for (int i = percentOfLive; i < maxLife; i++)
  45.                 {
  46.                     bar += " ";
  47.                 }
  48.                 Console.BackgroundColor = defaultColor;
  49.                 Console.Write(bar + "]");
  50.             }
  51.             else
  52.             {
  53.                 Console.WriteLine("\nОшибка ввода");
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement