Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Homework29
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- /*Разработайте функцию, которая рисует некий бар(Healthbar, Manabar)
- * в определённой позиции.
- * Она также принимает некий закрашенный процент.
- При 40 % бар выглядит так:
- [####______] */
- //char[] chars = new char[10];
- int health = 5;
- int maxHealth = 10;
- int mana = 7;
- int maxMana = 10;
- while (true)
- {
- DrawBar(health, maxHealth, ConsoleColor.Green, 0, '|');
- DrawBar(mana, maxMana, ConsoleColor.Blue, 1);
- Console.SetCursorPosition(0,5);
- Console.WriteLine("Введите число на которое изменятся жизни: ");
- health += Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Введите число на которое изменится мана: ");
- mana += Convert.ToInt32(Console.ReadLine());
- Console.ReadKey();
- Console.Clear();
- }
- }
- static void DrawBar(int value, int maxValue, ConsoleColor color, int position, char symbol = '_')
- {
- ConsoleColor defaultColor = Console.BackgroundColor;
- string bar = "";
- for (int i = 0; i < value; i++)
- {
- bar += symbol;
- }
- Console.SetCursorPosition(0, position);
- Console.Write("[");
- Console.BackgroundColor = color;
- Console.Write(bar);
- Console.BackgroundColor = defaultColor;
- bar = "";
- for (int i = value; i < maxValue; i++)
- {
- bar += symbol;
- }
- Console.Write(bar + "]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement