Advertisement
SnowPhoenix347

4.2

Nov 4th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 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(Console.ReadLine());
  12.             Console.WriteLine("Введите Y координату");
  13.             int y = ConvertToInt(Console.ReadLine());
  14.             Console.WriteLine("Введите процент заполнения бара");
  15.             int health = ConvertToInt(Console.ReadLine());
  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.             for (int i = 0; i < 10 - health/10; i++)
  28.             {
  29.                 Console.Write("_");
  30.             }
  31.             Console.Write("]");
  32.         }
  33.        
  34.         static int ConvertToInt(string input)
  35.         {
  36.             int output;
  37.             bool enterIsCorrect = int.TryParse(input, out output);
  38.             do
  39.             {
  40.                 if (!enterIsCorrect)
  41.                 {
  42.                     Console.WriteLine("Ложное значение.");
  43.                 }
  44.             } while (!enterIsCorrect);
  45.  
  46.             return output;
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement