Advertisement
SnowPhoenix347

4.2

Nov 4th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Runtime.InteropServices;
  3.  
  4. namespace FifthProject
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.WriteLine("Введите X координату");
  11.             int x = ConvertToInt();
  12.             Console.WriteLine("Введите Y координату");
  13.             int y = ConvertToInt();
  14.             Console.WriteLine("Введите процент заполнения бара");
  15.             int health = ConvertToInt();
  16.             DrawHealthBar(x, y, health);
  17.         }
  18.  
  19.         static void DrawHealthBar(int x, int y, int health)
  20.         {
  21.             Console.SetCursorPosition(x, y);
  22.             Console.Write("[");
  23.             for (int i = 0; i < health / 10; i++)
  24.             {
  25.                 Console.Write("#");
  26.             }
  27.  
  28.             for (int i = 0; i < 10 - health / 10; i++)
  29.             {
  30.                 Console.Write("_");
  31.             }
  32.  
  33.             Console.Write("]");
  34.         }
  35.  
  36.  
  37.         static int ConvertToInt()
  38.         {
  39.             int output;
  40.             bool enterIsCorrect = false;
  41.             do
  42.             {
  43.                 string input = Console.ReadLine();
  44.                 enterIsCorrect = int.TryParse(input, out output);
  45.                 if (!enterIsCorrect)
  46.                 {
  47.                     Console.WriteLine("Ложное значение. Повторите попытку");
  48.                 }
  49.             } while (!enterIsCorrect);
  50.  
  51.             return output;
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement