From 890cbd138e2df4c72b46c837613488c05d88ff2d Mon Sep 17 00:00:00 2001 From: Egor_Shtyrkin Date: Sun, 14 Apr 2024 19:49:05 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MovementStrategy/IMoveableObject.cs | 30 ++++++++ .../MovementStrategy/MovementDirection.cs | 27 +++++++ .../MovementStrategy/ObjectParameters.cs | 72 +++++++++++++++++++ .../MovementStrategy/StrategyStatus.cs | 22 ++++++ 4 files changed, 151 insertions(+) create mode 100644 ProjectAircraftCarrier/ProjectAircraftCarrier/MovementStrategy/IMoveableObject.cs create mode 100644 ProjectAircraftCarrier/ProjectAircraftCarrier/MovementStrategy/MovementDirection.cs create mode 100644 ProjectAircraftCarrier/ProjectAircraftCarrier/MovementStrategy/ObjectParameters.cs create mode 100644 ProjectAircraftCarrier/ProjectAircraftCarrier/MovementStrategy/StrategyStatus.cs diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/MovementStrategy/IMoveableObject.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/MovementStrategy/IMoveableObject.cs new file mode 100644 index 0000000..aede2a9 --- /dev/null +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/MovementStrategy/IMoveableObject.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAircraftCarrier.MovementStrategy; + +/// +/// Интерфейс для работы с перемещаемым объектом +/// +public interface IMoveableObject +{ + /// + /// Получение координаты объекта + /// + ObjectParameters? GetObjectPosition { get; } + + /// + /// Шаг объекта + /// + int GetStep { get; } + + /// + /// Попытка переместить объект в указанном направлении + /// + /// Направление + /// true - объект перемещён, false - перемещение невозможно + bool TryMoveObject(MovementDirection direction); +} diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/MovementStrategy/MovementDirection.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/MovementStrategy/MovementDirection.cs new file mode 100644 index 0000000..920b974 --- /dev/null +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/MovementStrategy/MovementDirection.cs @@ -0,0 +1,27 @@ +namespace ProjectAircraftCarrier.MovementStrategy; + +/// +/// Направление перемещения +/// +public enum MovementDirection +{ + /// + /// Вверх + /// + Up = 1, + + /// + /// Вниз + /// + Down = 2, + + /// + /// Влево + /// + Left = 3, + + /// + /// Вправо + /// + Right = 4 +} diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/MovementStrategy/ObjectParameters.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/MovementStrategy/ObjectParameters.cs new file mode 100644 index 0000000..d8f9339 --- /dev/null +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/MovementStrategy/ObjectParameters.cs @@ -0,0 +1,72 @@ +namespace ProjectAircraftCarrier.MovementStrategy; + +/// +/// Параметры-координаты объекта +/// +public class ObjectParameters +{ + /// + /// Координата X + /// + private readonly int _x; + + /// + /// Координата Y + /// + private readonly int _y; + + /// + /// Ширина объекта + /// + private readonly int _width; + + /// + /// Высота объекта + /// + private readonly int _height; + + /// + /// Левая граница + /// + public int LeftBorder => _x; + + /// + /// Верхняя граница + /// + public int TopBorder => _y; + + /// + /// Правая граница + /// + public int RightBorder => _x + _width; + + /// + /// Нижняя граница + /// + public int DownBorder => _y + _height; + + /// + /// Середина объекта + /// + public int ObjectMiddleHorizontal => _x + _width / 2; + + /// + /// Середина объекта + /// + public int ObjectMiddleVertical => _y + _height / 2; + + /// + /// Конструктор + /// + /// Координата X + /// Координата Y + /// Ширина объекта + /// Высота объекта + public ObjectParameters(int x, int y, int width, int height) + { + _x = x; + _y = y; + _width = width; + _height = height; + } +} diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/MovementStrategy/StrategyStatus.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/MovementStrategy/StrategyStatus.cs new file mode 100644 index 0000000..87fe958 --- /dev/null +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/MovementStrategy/StrategyStatus.cs @@ -0,0 +1,22 @@ +namespace ProjectAircraftCarrier.MovementStrategy; + +/// +/// Статус выполнения операции перемещения +/// +public enum StrategyStatus +{ + /// + /// Всё готово к началу + /// + NotInit, + + /// + /// Выполняется + /// + InProgress, + + /// + /// Завершено + /// + Finish +}