Всем Хай! Сегодня мы добавим цвета в нашу жизнь. А точнее в нашу консоль. Задание у нас будет не сложное, но визуально будет выглядеть прикольно. Сделаем мы отображение жизней и манны, как у персонажа в игре. Ну, там где красной полоской отображается жизнь, а синей мана. В общем, не буду затягивать. Смотрим код. static void Stat(int value, int maxValue, ConsoleColor color, int position, char simvol) { ConsoleColor defoltColor = Console.BackgroundColor; Console.SetCursorPosition(0, position); Console.Write("["); Console.BackgroundColor = color; for (int i = 0; i < value; i++) { Console.Write(simvol); } Console.BackgroundColor = defoltColor; maxValue -= value; for (int i = 0; i < maxValue; i++) { Console.Write("#"); } Console.Write("]\n"); } static void Main(string[] args) { int health = 5; int maxHealth = 10; int mana = 5; int maxMana = 10; while (true) { Console.WriteLine("Параметры игрока"); Stat(health, maxHealth, ConsoleColor.Red, 2, '_'); Stat(mana, maxMana, ConsoleColor.Blue, 3, '
Программирование с нуля. Делаем Health Bar в консоли через функцию.
23 октября 202223 окт 2022
30
3 мин