Advertisement
JohnJuly

Homework29

Jan 16th, 2024 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _29
  8. {
  9.     internal class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             float maxValueHealthBar = 10;
  14.  
  15.             DrawHealthBar(maxValueHealthBar);
  16.         }
  17.         static void DrawHealthBar(float maxValue)
  18.         {
  19.             float fullBarInPercent = 100;
  20.             float emptyBarInPercent = 0;
  21.  
  22.             Console.WriteLine("Вы в меню отрисовки Health bar!!!");
  23.             Console.WriteLine("Введите позицию отрисовки по оси X");
  24.             int positionHealthBarX = Convert.ToInt32(Console.ReadLine());
  25.  
  26.             Console.WriteLine("Введите позицию отрисовки по оси Y");
  27.             int positionHealthBarY = Convert.ToInt32(Console.ReadLine());
  28.  
  29.             Console.WriteLine("Введите на сколько процентов отрисовать healthbar: ");
  30.             float userInput = Convert.ToSingle(Console.ReadLine());
  31.             float userInputInPercent = (float)Math.Round((maxValue / fullBarInPercent) * userInput);
  32.  
  33.             string bar = "";
  34.             char fillSymbol = '#';
  35.             char emptySymbol = '_';
  36.             char openBracket = '[';
  37.             char closeBracket = ']';
  38.  
  39.             if (userInput >= emptyBarInPercent && userInput <= fullBarInPercent)
  40.             {
  41.                 for (float i = 0; i < userInputInPercent; i++)
  42.                 {
  43.                     bar += fillSymbol;
  44.                 }
  45.  
  46.                 Console.SetCursorPosition(positionHealthBarX, positionHealthBarY);
  47.                 Console.Write(openBracket);
  48.                 Console.Write(bar);
  49.  
  50.                 bar = "";
  51.  
  52.                 for (float i = userInputInPercent; i < maxValue; i++)
  53.                 {
  54.                     bar += emptySymbol;
  55.                 }
  56.  
  57.                 Console.WriteLine(bar + closeBracket);
  58.             }
  59.             else
  60.             {
  61.                 Console.WriteLine("Введено значение выходящее за пределы Healthbar!");
  62.             }
  63.         }
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement