Advertisement
Torgach

tempTempWorkWithProperties

Mar 24th, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 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 = renderer.IsCoordinateValid(out int positionX, inputError);
  23.  
  24.                 Console.Write("Введите положение по оси Y: ");
  25.                 inputError = renderer.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.  
  43.     class Player
  44.     {
  45.         public int X { get; private set; }
  46.  
  47.         public int Y { get; private set; }
  48.  
  49.         public Player()
  50.         {
  51.             X = 2;
  52.             Y = 2;
  53.         }
  54.  
  55.         public Player(int x, int y)
  56.         {
  57.             X = x;
  58.             Y = y;
  59.         }      
  60.     }
  61.  
  62.     class Renderer
  63.     {
  64.         public bool IsCoordinateValid(out int coordinate, bool InputError)
  65.         {
  66.             if (int.TryParse(Console.ReadLine(), out coordinate) == false
  67.                 || (coordinate < 0 || coordinate > 100))
  68.                 InputError = true;
  69.  
  70.             return InputError;
  71.         }
  72.  
  73.         public void ShowPlayer(int x, int y, char character = 'V')
  74.         {
  75.             Console.Clear();
  76.             Console.SetCursorPosition(x, y);
  77.             Console.WriteLine(character);
  78.         }
  79.     }
  80.  
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement