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;
- /*
- * Разработайте функцию, которая рисует некий бар (Healthbar, Manabar) в определённой позиции. Она также принимает некий закрашенный процент.
- *
- * При 40% бар выглядит так:
- *
- * [####______]
- *
- */
- namespace ConsoleApp1
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int healthBar = 10;
- int manaBar = 10;
- int healthPoint = 8;
- int manaPoint = 6;
- int positionHealth = 0;
- int positionMana = 12;
- int barPosition = 1;
- string health = " HP";
- string mana = " MANA";
- DrawResourse(health, ConsoleColor.Red, positionHealth);
- DrawResourse(mana, ConsoleColor.Blue, positionMana);
- DrawBar(healthBar, healthPoint, ConsoleColor.Red, positionHealth, barPosition);
- DrawBar(manaBar, manaPoint, ConsoleColor.Blue, positionMana, barPosition);
- }
- static void DrawResourse(string text, ConsoleColor color, int position)
- {
- Console.SetCursorPosition(position, 0);
- Console.ForegroundColor = color;
- Console.WriteLine("" + text);
- Console.ForegroundColor = ConsoleColor.White;
- }
- static void DrawBar(int maxValue, int value, ConsoleColor color, int position, int barPosition)
- {
- Console.SetCursorPosition(position, barPosition);
- string bar = " ";
- ConsoleColor defaultColor = Console.BackgroundColor;
- Console.Write("[");
- Console.BackgroundColor = color;
- for (int i = 0; i < value; i++)
- {
- Console.Write(bar);
- }
- Console.BackgroundColor = defaultColor;
- for (int i = value; i < maxValue; i++)
- {
- Console.Write(bar);
- }
- Console.WriteLine("]");
- }
- }
- }
Add Comment
Please, Sign In to add comment