Torgach

tempWorkWithProperties

Mar 21st, 2021 (edited)
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 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 WorkWithProperties
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             bool isRun = true;
  14.             bool inputError = false;
  15.  
  16.             Renderer renderer = new Renderer();
  17.             Player player = new Player();
  18.  
  19.             while (isRun)
  20.             {
  21.                 Console.Write("Введите положение по оси X: ");
  22.                 inputError = IsCoordinateValid(out int positionX, inputError);
  23.  
  24.                 Console.Write("Введите положение по оси Y: ");
  25.                 inputError = IsCoordinateValid(out int positionY, inputError);
  26.  
  27.                 if (inputError == false)
  28.                 {
  29.                     player = new Player(positionX, positionY);
  30.                     renderer.ShowPlayer(player.X, player.Y);
  31.                 }
  32.                 else
  33.                 {
  34.                     Console.WriteLine("Ошибка! Введите число повторно.");
  35.                     Console.ReadKey();
  36.  
  37.                     renderer.ShowPlayer(player.X, player.Y);
  38.                 }
  39.             }
  40.         }
  41.  
  42.         static bool IsCoordinateValid(out int coordinate, bool InputError)
  43.         {
  44.             if (int.TryParse(Console.ReadLine(), out coordinate) == false
  45.                 || (coordinate < 0 || coordinate > 100))
  46.                 InputError = true;
  47.  
  48.             return InputError;
  49.         }
  50.  
  51.     }
  52.  
  53.     class Player
  54.     {
  55.         public int X { get; private set; }
  56.  
  57.         public int Y { get; private set; }
  58.  
  59.         public Player()
  60.         {
  61.             X = 2;
  62.             Y = 2;
  63.         }
  64.  
  65.         public Player(int x, int y)
  66.         {
  67.             X = x;
  68.             Y = y;
  69.         }      
  70.     }
  71.  
  72.     class Renderer
  73.     {
  74.         public void ShowPlayer(int x, int y, char character = 'V')
  75.         {
  76.             Console.Clear();
  77.             Console.SetCursorPosition(x, y);
  78.             Console.WriteLine(character);
  79.         }
  80.     }
  81.  
  82. }
  83.  
Add Comment
Please, Sign In to add comment