kwest87

Untitled

Nov 7th, 2022
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. [StartCode]
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. /*
  8.  * Разработайте функцию, которая рисует некий бар (Healthbar, Manabar) в определённой позиции. Она также принимает некий закрашенный процент.
  9.  *
  10.  * При 40% бар выглядит так:
  11.  *
  12.  * [####______]
  13.  *
  14.  */
  15.  
  16.  
  17. namespace ConsoleApp1
  18. {
  19.     internal class Program
  20.     {
  21.         static void Main(string[] args)
  22.         {
  23.             int healthBar = 10, manaBar = 10;
  24.             int healthPoint = 8, manaPoint = 6;
  25.             int positionHealth = 0, positionMana = 12, barPosition = 1;
  26.             string health = "     HP", mana = "    MANA";
  27.             DrawResourse(health, ConsoleColor.Red, positionHealth);
  28.             DrawResourse(mana, ConsoleColor.Blue, positionMana);
  29.             DrawBar(healthBar, healthPoint, ConsoleColor.Red, positionHealth, barPosition);
  30.             DrawBar(manaBar, manaPoint, ConsoleColor.Blue, positionMana, barPosition);
  31.         }
  32.  
  33.         static void DrawResourse(string text, ConsoleColor color, int position)
  34.         {
  35.             Console.SetCursorPosition(position, 0);
  36.             Console.ForegroundColor = color;
  37.             Console.WriteLine("" + text);
  38.             Console.ForegroundColor = ConsoleColor.White;
  39.         }
  40.  
  41.         static void DrawBar(int maxValue, int value, ConsoleColor color, int position, int barPosition)
  42.         {
  43.             Console.SetCursorPosition(position, barPosition);
  44.             string bar = " ";
  45.             ConsoleColor defaultColor = Console.BackgroundColor;
  46.             Console.Write("[");
  47.             Console.BackgroundColor = color;
  48.  
  49.             for (int i = 0; i < value; i++)
  50.             {
  51.                 Console.Write(bar);
  52.             }
  53.  
  54.             Console.BackgroundColor = defaultColor;
  55.  
  56.             for (int i = value; i < maxValue; i++)
  57.             {
  58.                 Console.Write(bar);
  59.             }
  60.  
  61.             Console.WriteLine("]");
  62.         }
  63.     }
  64. }
  65. [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment