kwest87

Untitled

Nov 9th, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 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;
  24.             int manaBar = 10;
  25.             int healthPoint = 8;
  26.             int manaPoint = 6;
  27.             int positionHealth = 0;
  28.             int positionMana = 12;
  29.             int barPosition = 1;
  30.             string health = "     HP";
  31.             string mana = "    MANA";
  32.             DrawResourse(health, ConsoleColor.Red, positionHealth);
  33.             DrawResourse(mana, ConsoleColor.Blue, positionMana);
  34.             DrawBar(healthBar, healthPoint, ConsoleColor.Red, positionHealth, barPosition);
  35.             DrawBar(manaBar, manaPoint, ConsoleColor.Blue, positionMana, barPosition);
  36.         }
  37.  
  38.         static void DrawResourse(string text, ConsoleColor color, int position)
  39.         {
  40.             Console.SetCursorPosition(position, 0);
  41.             Console.ForegroundColor = color;
  42.             Console.WriteLine("" + text);
  43.             Console.ForegroundColor = ConsoleColor.White;
  44.         }
  45.  
  46.         static void DrawBar(int maxValue, int value, ConsoleColor color, int position, int barPosition)
  47.         {
  48.             Console.SetCursorPosition(position, barPosition);
  49.             string bar = " ";
  50.             ConsoleColor defaultColor = Console.BackgroundColor;
  51.             Console.Write("[");
  52.             Console.BackgroundColor = color;
  53.  
  54.             for (int i = 0; i < value; i++)
  55.             {
  56.                 Console.Write(bar);
  57.             }
  58.  
  59.             Console.BackgroundColor = defaultColor;
  60.  
  61.             for (int i = value; i < maxValue; i++)
  62.             {
  63.                 Console.Write(bar);
  64.             }
  65.  
  66.             Console.WriteLine("]");
  67.         }
  68.     }
  69. }
  70. [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment