Advertisement
JohnJuly

HealthBar

Jan 16th, 2024
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Homework29
  8. {
  9.     internal class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             /*Разработайте функцию, которая рисует некий бар(Healthbar, Manabar)
  14.              * в определённой позиции.
  15.              * Она также принимает некий закрашенный процент.  
  16.             При 40 % бар выглядит так:
  17.             [####______] */
  18.  
  19.             //char[] chars = new char[10];
  20.             int health = 5;
  21.             int maxHealth = 10;
  22.             int mana = 7;
  23.             int maxMana = 10;
  24.             while (true)
  25.             {
  26.                 DrawBar(health, maxHealth, ConsoleColor.Green, 0, '|');
  27.                 DrawBar(mana, maxMana, ConsoleColor.Blue, 1);
  28.  
  29.                 Console.SetCursorPosition(0,5);
  30.                 Console.WriteLine("Введите число на которое изменятся жизни: ");
  31.                 health += Convert.ToInt32(Console.ReadLine());
  32.                 Console.WriteLine("Введите число на которое изменится мана: ");
  33.                 mana += Convert.ToInt32(Console.ReadLine());
  34.  
  35.                 Console.ReadKey();
  36.                 Console.Clear();
  37.             }
  38.  
  39.         }
  40.         static void DrawBar(int value, int maxValue, ConsoleColor color, int position, char symbol = '_')
  41.         {
  42.             ConsoleColor defaultColor = Console.BackgroundColor;
  43.  
  44.             string bar = "";
  45.  
  46.             for (int i = 0; i < value; i++)
  47.             {
  48.                 bar += symbol;
  49.             }
  50.  
  51.             Console.SetCursorPosition(0, position);
  52.             Console.Write("[");
  53.             Console.BackgroundColor = color;
  54.             Console.Write(bar);
  55.             Console.BackgroundColor = defaultColor;
  56.  
  57.             bar = "";
  58.  
  59.             for (int i = value; i < maxValue; i++)
  60.             {
  61.                 bar += symbol;
  62.             }
  63.  
  64.             Console.Write(bar + "]");
  65.         }
  66.     }
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement