ranee

бар здоровья

Jul 8th, 2020 (edited)
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.Specialized;
  4. using System.Diagnostics.CodeAnalysis;
  5. using System.Dynamic;
  6. using System.Globalization;
  7. using System.Linq;
  8. using System.Runtime.Serialization;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. namespace CSLight
  13. {
  14.     class Program
  15.     {
  16.         static void Main(string[] args)
  17.         {
  18.             int health = 45322, maxHealth = 52348;
  19.             int mana = 195, maxMana = 321;
  20.             DrawBAr(health, maxHealth, ConsoleColor.Red, 0);
  21.             DrawBAr(mana, maxMana, ConsoleColor.Blue, 1);
  22.         }
  23.         static void DrawBAr(int value, int maxValue, ConsoleColor color, int position)
  24.         {
  25.             int percent = (((value * 100) / maxValue) / 10);
  26.             ConsoleColor defaultColor = Console.BackgroundColor;
  27.             string bar = "";
  28.             for(int i = 0; i < percent; i++)
  29.             {
  30.                 bar += '#';
  31.             }
  32.             Console.SetCursorPosition(0, position);
  33.             Console.Write('[');
  34.             Console.BackgroundColor = color;
  35.             Console.Write(bar);
  36.             Console.BackgroundColor = defaultColor;
  37.             bar = "";
  38.             for(int i = 0; i < (10- percent); i++)
  39.             {
  40.                 bar += '_';
  41.             }
  42.             Console.Write(bar + ']');
  43.         }
  44.     }
  45. }
Add Comment
Please, Sign In to add comment