Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace WorkWithProperties
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool isRun = true;
- bool inputError = false;
- Renderer renderer = new Renderer();
- Player player = new Player();
- while (isRun)
- {
- Console.Write("Введите положение по оси X: ");
- inputError = IsCoordinateValid(out int positionX, inputError);
- Console.Write("Введите положение по оси Y: ");
- inputError = IsCoordinateValid(out int positionY, inputError);
- if (inputError == false)
- {
- player = new Player(positionX, positionY);
- renderer.ShowPlayer(player.X, player.Y);
- }
- else
- {
- Console.WriteLine("Ошибка! Введите число повторно.");
- Console.ReadKey();
- renderer.ShowPlayer(player.X, player.Y);
- }
- }
- }
- static bool IsCoordinateValid(out int coordinate, bool InputError)
- {
- if (int.TryParse(Console.ReadLine(), out coordinate) == false
- || (coordinate < 0 || coordinate > 100))
- InputError = true;
- return InputError;
- }
- }
- class Player
- {
- public int X { get; private set; }
- public int Y { get; private set; }
- public Player()
- {
- X = 2;
- Y = 2;
- }
- public Player(int x, int y)
- {
- X = x;
- Y = y;
- }
- }
- class Renderer
- {
- public void ShowPlayer(int x, int y, char character = 'V')
- {
- Console.Clear();
- Console.SetCursorPosition(x, y);
- Console.WriteLine(character);
- }
- }
- }
Add Comment
Please, Sign In to add comment