NikaBang

ДЗ: UIElement

Oct 23rd, 2025 (edited)
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | Gaming | 0 0
  1. using System;
  2.  
  3. internal class Program
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         DrawBar(26, 10, ConsoleColor.Green, 0, 0);
  8.         DrawBar(50, 15, ConsoleColor.Blue, 20, 0);
  9.         Console.ReadKey();
  10.     }
  11.  
  12.     static void DrawBar(int percent, int barLength, ConsoleColor color, int positionX, int positionY)
  13.     {
  14.         ConsoleColor defaultColor = Console.ForegroundColor;
  15.         int minPercent = 0;
  16.         int maxPercent = 100;
  17.         char fillChar = '#';
  18.         char emptyChar = '_';
  19.  
  20.         if (percent > maxPercent)
  21.         {
  22.             percent = maxPercent;
  23.         }
  24.  
  25.         if (percent < minPercent)
  26.         {
  27.             percent = minPercent;
  28.         }
  29.  
  30.         int filledCount = percent * barLength / maxPercent;
  31.         int emptyCount = barLength - filledCount;
  32.  
  33.         Console.SetCursorPosition(positionX, positionY);
  34.         Console.ForegroundColor = color;
  35.         Console.Write('[');
  36.        
  37.         for (int i = 0; i < filledCount; i++)
  38.         {
  39.             Console.Write(fillChar);
  40.         }
  41.  
  42.         for (int i = 0; i < emptyCount; i++)
  43.         {
  44.             Console.Write(emptyChar);
  45.         }
  46.  
  47.         Console.Write(']');
  48.         Console.ForegroundColor = defaultColor;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment