diff --git a/HoistingCrane/HoistingCrane.sln b/HoistingCrane/HoistingCrane.sln
index 11c2632..ef28e41 100644
--- a/HoistingCrane/HoistingCrane.sln
+++ b/HoistingCrane/HoistingCrane.sln
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34221.43
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HoistingCrane", "HoistingCrane\HoistingCrane.csproj", "{915BDF62-D64D-4AB9-BA2D-8E228E803B7F}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HoistingCrane", "HoistingCrane\HoistingCrane.csproj", "{915BDF62-D64D-4AB9-BA2D-8E228E803B7F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/HoistingCrane/HoistingCrane/DirectionType.cs b/HoistingCrane/HoistingCrane/Drawning/DirectionType.cs
similarity index 60%
rename from HoistingCrane/HoistingCrane/DirectionType.cs
rename to HoistingCrane/HoistingCrane/Drawning/DirectionType.cs
index ffff269..a9f0e52 100644
--- a/HoistingCrane/HoistingCrane/DirectionType.cs
+++ b/HoistingCrane/HoistingCrane/Drawning/DirectionType.cs
@@ -1,10 +1,14 @@
-namespace HoistingCrane;
+namespace HoistingCrane.Drawning;
-public enum DirectionType : byte //Создали не класс(class), а перечисление (enum)
+public enum DirectionType //Создали не класс(class), а перечисление (enum)
{
//Перечислим основные траектории движния нашего автомобиля. Сразу же зададим значения.
///
- /// Вверх1
+ /// Неизвестное направление
+ ///
+ Unknow = -1,
+ ///
+ /// Вверх
///
Up = 1,
///
diff --git a/HoistingCrane/HoistingCrane/Drawning/DrawningHoistingCrane.cs b/HoistingCrane/HoistingCrane/Drawning/DrawningHoistingCrane.cs
new file mode 100644
index 0000000..2023b34
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Drawning/DrawningHoistingCrane.cs
@@ -0,0 +1,84 @@
+using HoistingCrane.Entities;
+using System.Configuration;
+
+namespace HoistingCrane.Drawning;
+
+//В данном классе мы будем думать над полем игры, размерами персонажа, размерами объектов и т.д.
+public class DrawningHoistingCrane : DrawningTrackedVehicle
+{
+
+ ///
+ /// Ширина окна
+ ///
+ private int? _pictureWidth;
+
+ ///
+ /// Высота окна
+ ///
+ private int? _pictureHeight;
+
+ ///
+ /// Ширина прорисовки автомобиля
+ ///
+ private readonly int _drawingCarWidth = 115;
+
+ ///
+ /// Высота прорисовки автомобиля
+ ///
+ private readonly int _drawingCarHeight = 63;
+
+
+ ///
+ /// конструктор класса отрисовки крана
+ ///
+ /// Дополнительный цвет
+ /// Противовес
+ /// Платформа
+ public DrawningHoistingCrane(int speed, int weight, Color bodyColor, Color additionalColor, bool counterweight, bool platform) : base(115, 63)
+ {
+ EntityTrackedVehicle = new EntityHoistingCrane(speed, weight, bodyColor, additionalColor, counterweight, platform);
+ }
+
+ ///
+ /// Метод отрисовки объекта
+ ///
+ ///
+ public override void DrawTransport(Graphics gr)
+ {
+ if (EntityTrackedVehicle == null || EntityTrackedVehicle is not EntityHoistingCrane EntityHoistingCrane || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+
+ base.DrawTransport(gr);
+ Brush b = new SolidBrush(EntityHoistingCrane.AdditionalColor);
+ Pen pen = new Pen(EntityHoistingCrane.AdditionalColor);
+ Pen penBase = new Pen(EntityHoistingCrane.BodyColor);
+ if (EntityHoistingCrane.Counterweight)
+ {
+ //противовес
+
+ gr.DrawRectangle(pen, _startPosX.Value + 69, _startPosY.Value + 3, 10, 10);
+ gr.DrawLine(pen, _startPosX.Value + 68, _startPosY.Value + 3, _startPosX.Value + 78, _startPosY.Value + 12);
+ gr.DrawLine(pen, _startPosX.Value + 68, _startPosY.Value + 7, _startPosX.Value + 78, _startPosY.Value + 3);
+ }
+
+ if (EntityHoistingCrane.Platform) {
+ //Наличие спусковой платформы
+
+ gr.FillRectangle(b, _startPosX.Value + 101, _startPosY.Value + 40, 15, 5);
+ gr.FillRectangle(b, _startPosX.Value + 116, _startPosY.Value + 35, 4, 5);
+ gr.FillRectangle(b, _startPosX.Value + 97, _startPosY.Value + 35, 4, 5);
+ }
+
+
+ //Отрисовка крана, на котором держится платформа и противовес
+ gr.FillRectangle(b, _startPosX.Value + 65, _startPosY.Value, 5, 26);
+ gr.FillRectangle(b, _startPosX.Value + 65, _startPosY.Value, 50, 4);
+ gr.DrawLine(penBase, _startPosX.Value + 115, _startPosY.Value + 4, _startPosX.Value + 108, _startPosY.Value + 40);
+
+ }
+
+}
+
+
diff --git a/HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs b/HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs
new file mode 100644
index 0000000..29846b3
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs
@@ -0,0 +1,263 @@
+using HoistingCrane.Entities;
+
+namespace HoistingCrane.Drawning
+{
+ //В данном классе мы будем думать над полем игры, размерами персонажа, размерами объектов и т.д.
+ public class DrawningTrackedVehicle
+ {
+
+ ///
+ /// Класс - сущность
+ ///
+ public EntityTrackedVehicle? EntityTrackedVehicle { get; protected set; }
+
+ ///
+ /// Ширина окна
+ ///
+ private int? _pictureWidth;
+
+ ///
+ /// Высота окна
+ ///
+ private int? _pictureHeight;
+
+ ///
+ /// Стартовая позиция по х
+ ///
+ protected int? _startPosX;
+ ///
+ /// Стартовая позиция по у
+ ///
+ protected int? _startPosY;
+
+ ///
+ /// Ширина прорисовки автомобиля
+ ///
+ private readonly int _drawingCarWidth = 83;
+ ///
+ /// Высота прорисовки автомобиля
+ ///
+ private readonly int _drawingCarHeight = 63;
+
+ public int? GetPosX => _startPosX;
+ public int? GetPosY => _startPosY;
+ public int GetWidth => _drawingCarWidth;
+ public int GetHeight => _drawingCarHeight;
+
+
+ ///
+ /// Конструктор класса, который принимает параметры автомобиля(скорость, вес и цвет) и создает объект класса с данными параметрами
+ ///
+ /// Скорость
+ /// Вес
+ /// Цвет
+ public DrawningTrackedVehicle(int speed, double weight, Color bodyColor) : this()
+ {
+ EntityTrackedVehicle = new EntityTrackedVehicle(speed, weight, bodyColor);
+ }
+
+
+ ///
+ /// Конструктор, при вызове которого можем менять границы транспорта
+ ///
+ /// Ширина прорисовки автомобиля
+ /// Высота прорисовки автомобиля
+ protected DrawningTrackedVehicle(int _drawingCarWidth, int _drawingCarHeight) : this()
+ {
+ this._drawingCarWidth = _drawingCarWidth;
+ this._drawingCarHeight = _drawingCarHeight;
+ }
+
+
+ ///
+ /// Приватный конструктор, который делает значения границ окна = null и стартовую позицию = null
+ ///
+ private DrawningTrackedVehicle()
+ {
+ _pictureWidth = null;
+ _pictureHeight = null;
+ _startPosX = null;
+ _startPosY = null;
+ }
+
+
+ ///
+ /// Метод отрисовки игрового поля
+ ///
+ /// Ширина поля
+ /// Высота поля
+ ///
+
+ public bool SetPictureSize(int width, int height)
+ {
+ // TODO проверка, что объект "влезает" в размеры поля
+ // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена ✔
+
+ if (_drawingCarHeight > height || _drawingCarWidth > width)
+ {
+ return false;
+ }
+
+ _pictureHeight = height;
+ _pictureWidth = width;
+
+ if (_startPosX.HasValue && _startPosX.Value + _drawingCarWidth > _pictureWidth)
+ {
+ _startPosX = _pictureWidth - _drawingCarWidth;
+ }
+
+ if (_startPosY.HasValue && _startPosY.Value + _drawingCarHeight > _pictureHeight)
+ {
+ _startPosY = _pictureHeight - _drawingCarHeight;
+ }
+ return true;
+
+ }
+
+ ///
+ /// Установим позицию игрока
+ ///
+ /// Координата по Х
+ /// Координата по У
+ public void SetPosition(int x, int y)
+ {
+ //Если размеры были заданы, то присваиваем х и у, иначе выходим из метода
+
+ if (x < 0)
+ x = -x;
+ if (y < 0)
+ y = -y;
+ if (x + _drawingCarWidth > _pictureWidth)
+ {
+ _startPosX = _pictureWidth - _drawingCarWidth;
+ }
+ else
+ {
+ _startPosX = x;
+ }
+ if (y + _drawingCarHeight > _pictureHeight)
+ {
+ _startPosY = _pictureHeight - _drawingCarHeight;
+ }
+ else
+ {
+ _startPosY = y;
+ }
+
+ }
+
+ ///
+ /// Перемещение машины
+ ///
+ ///
+ ///
+
+ public bool MoveTransport(DirectionType direction) //Подключили модив\фикатор virtual для переопределения в дочернем классе
+ {
+ if (EntityTrackedVehicle == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return false;
+ }
+
+ switch (direction)
+ {
+ //влево
+ case DirectionType.Left:
+ if (_startPosX.Value - EntityTrackedVehicle.Step > 0)
+ {
+ _startPosX -= (int)EntityTrackedVehicle.Step;
+ }
+
+ return true;
+ //вверх
+ case DirectionType.Up:
+ if (_startPosY.Value - EntityTrackedVehicle.Step > 0)
+ {
+ _startPosY -= (int)EntityTrackedVehicle.Step;
+ }
+ return true;
+
+ //вправо
+ case DirectionType.Right:
+ if (_startPosX.Value + EntityTrackedVehicle.Step + _drawingCarWidth < _pictureWidth)
+ {
+ _startPosX += (int)EntityTrackedVehicle.Step;
+ }
+ return true;
+
+ //вниз
+ case DirectionType.Down:
+ if (_startPosY.Value + EntityTrackedVehicle.Step + _drawingCarHeight < _pictureHeight)
+ {
+ _startPosY += (int)EntityTrackedVehicle.Step;
+ }
+ return true;
+
+ default: return false;
+
+
+ }
+ }
+
+
+ ///
+ /// Метод отрисовки объекта
+ ///
+ ///
+ public virtual void DrawTransport(Graphics gr)
+ {
+ if (EntityTrackedVehicle == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+ Pen pen = new Pen(Color.Black);
+
+
+ //границы
+ gr.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 25, 75, 20);
+ gr.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 25, 25);
+ gr.DrawRectangle(pen, _startPosX.Value + 4, _startPosY.Value + 4, 17, 17);
+ gr.DrawRectangle(pen, _startPosX.Value + 52, _startPosY.Value + 7, 6, 18);
+ gr.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 45, 20, 20);
+ gr.DrawEllipse(pen, _startPosX.Value + 63, _startPosY.Value + 45, 20, 20);
+ gr.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 45, 68, 20);
+ gr.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 46, 18, 18);
+ gr.DrawEllipse(pen, _startPosX.Value + 62, _startPosY.Value + 46, 18, 18);
+ gr.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 53, 10, 10);
+ gr.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 53, 10, 10);
+ gr.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 53, 10, 10);
+ gr.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 45, 4, 6);
+ gr.DrawRectangle(pen, _startPosX.Value + 45, _startPosY.Value + 45, 4, 6);
+
+ //корпус
+ Brush br = new SolidBrush(EntityTrackedVehicle.BodyColor);
+ gr.FillRectangle(br, _startPosX.Value, _startPosY.Value + 25, 75, 25);
+ gr.FillRectangle(br, _startPosX.Value, _startPosY.Value, 25, 25);
+
+
+ //окно
+ Brush brq = new SolidBrush(Color.AliceBlue);
+ gr.FillRectangle(brq, _startPosX.Value + 4, _startPosY.Value + 4, 17, 17);
+
+
+ //выхлопная труба
+ Brush brBlack = new SolidBrush(Color.Black);
+ gr.FillRectangle(brBlack, _startPosX.Value + 52, _startPosY.Value + 7, 6, 18);
+
+
+ //гусеница
+ Brush brDarkGray = new SolidBrush(Color.DarkGray);
+ gr.FillEllipse(brDarkGray, _startPosX.Value - 5, _startPosY.Value + 45, 20, 20);
+ gr.FillEllipse(brDarkGray, _startPosX.Value + 63, _startPosY.Value + 45, 20, 20);
+ gr.FillRectangle(brDarkGray, _startPosX.Value + 5, _startPosY.Value + 45, 68, 20);
+
+ gr.FillEllipse(brq, _startPosX.Value - 1, _startPosY.Value + 46, 18, 18);
+ gr.FillEllipse(brq, _startPosX.Value + 62, _startPosY.Value + 46, 18, 18);
+ gr.FillEllipse(brq, _startPosX.Value + 20, _startPosY.Value + 53, 10, 10);
+ gr.FillEllipse(brq, _startPosX.Value + 35, _startPosY.Value + 53, 10, 10);
+ gr.FillEllipse(brq, _startPosX.Value + 50, _startPosY.Value + 53, 10, 10);
+ gr.FillRectangle(brq, _startPosX.Value + 30, _startPosY.Value + 45, 4, 6);
+ gr.FillRectangle(brq, _startPosX.Value + 45, _startPosY.Value + 45, 4, 6);
+ }
+ }
+}
\ No newline at end of file
diff --git a/HoistingCrane/HoistingCrane/DrawningHoistingCrane.cs b/HoistingCrane/HoistingCrane/DrawningHoistingCrane.cs
deleted file mode 100644
index 0bf8c35..0000000
--- a/HoistingCrane/HoistingCrane/DrawningHoistingCrane.cs
+++ /dev/null
@@ -1,278 +0,0 @@
-
-namespace HoistingCrane;
-
-//В данном классе мы будем думать над полем игры, размерами персонажа, размерами объектов и т.д.
-public class DrawningHoistingCrane
-{
- ///
- /// Класс - сущность
- ///
- public EntityHoistingCrane? EntityHoistingCrane { get; private set; }
-
- ///
- /// Ширина окна
- ///
- private int? _pictureWidth;
-
- ///
- /// Высота окна
- ///
- private int? _pictureHeight;
-
- ///
- /// Стартовая позиция по х
- ///
- private int? _startPosX;
- ///
- /// Стартовая позиция по у
- ///
- private int? _startPosY;
-
- ///
- /// Ширина прорисовки автомобиля
- ///
- private readonly int _drawingCarWidth = 115;
- ///
- /// Высота прорисовки автомобиля
- ///
- private readonly int _drawingCarHeight = 63;
-
-
- public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool counterweight, bool platform)
- {
- EntityHoistingCrane = new EntityHoistingCrane();
- EntityHoistingCrane.Init(speed, weight, bodyColor, additionalColor, counterweight, platform);
- _pictureWidth = null;
- _pictureHeight = null;
- _startPosX = null;
- _startPosY = null;
-
- }
-
-
-
-
- ///
- /// Метод отрисовки игрового поля
- ///
- /// Ширина поля
- /// Высота поля
- ///
-
- public bool SetPictureSize(int width, int height)
- {
- // TODO проверка, что объект "влезает" в размеры поля
- // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена ✔
-
- if (_drawingCarHeight > height || _drawingCarWidth > width)
- {
- return false;
- }
-
- _pictureHeight = height;
- _pictureWidth = width;
-
- if(_startPosX.HasValue && (_startPosX.Value + _drawingCarWidth > _pictureWidth))
- {
- _startPosX =_pictureWidth - _drawingCarWidth;
- }
-
- if(_startPosY.HasValue && (_startPosY.Value + _drawingCarHeight > _pictureHeight))
- {
- _startPosY = _pictureHeight - _drawingCarHeight;
- }
- return true;
-
- }
-
-
-
- ///
- /// Установим позицию игрока
- ///
- /// Координата по Х
- /// Координата по У
- public void SetPosition(int x, int y)
- {
- //Если размеры были заданы, то присваиваем х и у, иначе выходим из метода
-
- if (x < 0)
- x = -x;
- if (y < 0)
- y = -y;
- if(x + _drawingCarWidth > _pictureWidth)
- {
- _startPosX = _pictureWidth - _drawingCarWidth;
- }
- else
- {
- _startPosX = x;
- }
- if (y + _drawingCarHeight > _pictureHeight)
- {
- _startPosY = _pictureHeight - _drawingCarHeight;
- }
- else
- {
- _startPosY = y;
- }
-
-
- }
-
- ///
- /// Перемещение машины
- ///
- ///
- ///
- public bool MoveTransport(DirectionType direction)
- {
- if (EntityHoistingCrane == null || !_startPosX.HasValue || !_startPosY.HasValue)
- {
- return false;
- }
-
- switch (direction)
- {
- //влево
- case DirectionType.Left:
- if (_startPosX.Value - EntityHoistingCrane.Step > 0)
- {
- _startPosX -= (int)EntityHoistingCrane.Step;
- }
-
- return true;
- //вверх
- case DirectionType.Up:
- if (_startPosY.Value - EntityHoistingCrane.Step > 0)
- {
- _startPosY -= (int)EntityHoistingCrane.Step;
- }
- return true;
-
- //вправо
- case DirectionType.Right:
- if (_startPosX.Value + EntityHoistingCrane.Step + _drawingCarWidth < _pictureWidth)
- {
- _startPosX += (int)EntityHoistingCrane.Step;
- }
- return true;
-
- //вниз
- case DirectionType.Down:
- if (_startPosY.Value + EntityHoistingCrane.Step + _drawingCarHeight < _pictureHeight)
- {
- _startPosY += (int)EntityHoistingCrane.Step;
- }
- return true;
-
- default: return false;
-
-
- }
-
-
-
-
- }
-
- ///
- /// Метод отрисовки объекта
- ///
- ///
- public void DrawTransport(Graphics gr)
- {
- if (EntityHoistingCrane == null || !_startPosX.HasValue || !_startPosY.HasValue)
- {
- return;
- }
- Pen pen = new Pen(Color.Black);
-
-
-
-
-
-
- //границы
- gr.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 25, 75, 20);
- gr.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 25, 25);
- gr.DrawRectangle(pen, _startPosX.Value + 4, _startPosY.Value + 4, 17, 17);
- gr.DrawRectangle(pen, _startPosX.Value + 52, _startPosY.Value + 7, 6, 18);
- gr.DrawEllipse(pen, _startPosX.Value - 5, _startPosY.Value + 45, 20, 20);
- gr.DrawEllipse(pen, _startPosX.Value + 63, _startPosY.Value + 45, 20, 20);
- gr.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 45, 68, 20);
- gr.DrawEllipse(pen, _startPosX.Value - 1, _startPosY.Value + 46, 18, 18);
- gr.DrawEllipse(pen, _startPosX.Value + 62, _startPosY.Value + 46, 18, 18);
- gr.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 53, 10, 10);
- gr.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 53, 10, 10);
- gr.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 53, 10, 10);
- gr.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 45, 4, 6);
- gr.DrawRectangle(pen, _startPosX.Value + 45, _startPosY.Value + 45, 4, 6);
-
-
-
-
-
-
- //корпус
- Brush br = new SolidBrush(EntityHoistingCrane.BodyColor);
- gr.FillRectangle(br, _startPosX.Value, _startPosY.Value + 25, 75, 25);
- gr.FillRectangle(br, _startPosX.Value, _startPosY.Value, 25, 25);
-
- //кран
- Brush bb = new SolidBrush(EntityHoistingCrane.BodyColor);
- gr.FillRectangle(bb, _startPosX.Value + 65, _startPosY.Value, 7, 25);
- gr.FillRectangle(br, _startPosX.Value + 62, _startPosY.Value + 2, 45, 5);
- gr.DrawLine(pen, _startPosX.Value + 105, _startPosY.Value + 2, _startPosX.Value + 107, _startPosY.Value + 40);
-
-
- //окно
- Brush brq = new SolidBrush(EntityHoistingCrane.AdditionalColor);
- gr.FillRectangle(brq, _startPosX.Value + 4, _startPosY.Value + 4, 17, 17);
-
-
-
- //выхлопная труба
- Brush brBlack = new SolidBrush(Color.Black);
- gr.FillRectangle(brBlack, _startPosX.Value + 52, _startPosY.Value + 7, 6, 18);
-
-
- //гусеница
- Brush brDarkGray = new SolidBrush(Color.DarkGray);
- gr.FillEllipse(brDarkGray, _startPosX.Value - 5, _startPosY.Value + 45, 20, 20);
- gr.FillEllipse(brDarkGray, _startPosX.Value + 63, _startPosY.Value + 45, 20, 20);
- gr.FillRectangle(brDarkGray, _startPosX.Value + 5, _startPosY.Value + 45, 68, 20);
-
-
- gr.FillEllipse(brq, _startPosX.Value - 1, _startPosY.Value + 46, 18, 18);
- gr.FillEllipse(brq, _startPosX.Value + 62, _startPosY.Value + 46, 18, 18);
- gr.FillEllipse(brq, _startPosX.Value + 20, _startPosY.Value + 53, 10, 10);
- gr.FillEllipse(brq, _startPosX.Value + 35, _startPosY.Value + 53, 10, 10);
- gr.FillEllipse(brq, _startPosX.Value + 50, _startPosY.Value + 53, 10, 10);
- gr.FillRectangle(brq, _startPosX.Value + 30, _startPosY.Value + 45, 4, 6);
- gr.FillRectangle(brq, _startPosX.Value + 45, _startPosY.Value + 45, 4, 6);
-
- //противовес
- if (EntityHoistingCrane.Counterweight)
- {
- Brush b = new SolidBrush(EntityHoistingCrane.AdditionalColor);
- gr.FillRectangle(b, _startPosX.Value + 68, _startPosY.Value + 5, 10, 10);
- }
-
-
- //Наличие спусковой платформы
- if (EntityHoistingCrane.Platform)
- {
- Pen n = new Pen(EntityHoistingCrane.AdditionalColor);
- gr.DrawRectangle(pen, _startPosX.Value + 101, _startPosY.Value + 40, 15, 5);
- }
-
- }
-
-
-
-
-
-}
-
-
diff --git a/HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs b/HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs
new file mode 100644
index 0000000..809ac3f
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs
@@ -0,0 +1,41 @@
+namespace HoistingCrane.Entities;
+
+
+///
+/// - ( )
+///
+public class EntityHoistingCrane : EntityTrackedVehicle
+{
+
+ ///
+ ///
+ ///
+ public Color AdditionalColor { get; protected set; }
+
+ ///
+ ///
+ ///
+ public bool Counterweight { get; protected set; }
+ ///
+ ///
+ ///
+ public bool Platform { get; protected set; }
+
+ ///
+ ///
+ ///
+ /// .
+ ///
+ ///
+
+
+ // .
+ public EntityHoistingCrane(int Speed, int Weight, Color BodyColor, Color AdditionalColor, bool Counterweight, bool Platform) : base(Speed, Weight, BodyColor)
+ {
+ this.AdditionalColor = AdditionalColor;
+ this.Counterweight = Counterweight;
+ this.Platform = Platform;
+
+ }
+
+}
\ No newline at end of file
diff --git a/HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs b/HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs
new file mode 100644
index 0000000..555320a
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs
@@ -0,0 +1,49 @@
+namespace HoistingCrane.Entities
+{
+
+ ///
+ /// Класс-сущность (Гусеничная машина) Родительский класс
+ ///
+ public class EntityTrackedVehicle
+ {
+ ///
+ /// Скорость, которой обладает объект
+ ///
+ public int Speed { get; protected set; }
+
+
+ ///
+ /// Вес, которым обладает объект
+ ///
+ public double Weight { get; protected set; }
+
+
+ ///
+ /// Основной цвет объекта
+ ///
+ public Color BodyColor { get; protected set; }
+
+
+ ///
+ /// Шаг движения
+ ///
+ public double Step => Speed * 100 / Weight;
+
+
+ ///
+ /// Конструктор сущности
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+
+ public EntityTrackedVehicle(int Speed, double Weight, Color BodyColor)
+ {
+ this.Speed = Speed;
+ this.Weight = Weight;
+ this.BodyColor = BodyColor;
+ }
+
+
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/EntityHoistingCrane.cs b/HoistingCrane/HoistingCrane/EntityHoistingCrane.cs
deleted file mode 100644
index 3fce867..0000000
--- a/HoistingCrane/HoistingCrane/EntityHoistingCrane.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-namespace HoistingCrane;
-
-
-
-public class EntityHoistingCrane
-{
- ///
- /// ,
- ///
- public int Speed { get; private set; }
- ///
- /// ,
- ///
- public double Weight { get; private set; }
- ///
- ///
- ///
- public Color BodyColor { get; private set; }
- ///
- ///
- ///
- public Color AdditionalColor { get; private set; }
-
- ///
- ///
- ///
- public bool Counterweight { get; private set; }
- ///
- ///
- ///
- public bool Platform{ get; private set; }
-
-
- ///
- ///
- ///
- public double Step => Speed * 100 / Weight;
-
-
-
-
- ///
- ///
- ///
- ///
- ///
- ///
- /// .
-
-
-
-
- public void Init(int Speed, double Weight, Color BodyColor, Color AdditionalColor, bool Counterweight, bool Platform)
- {
- this.Speed = Speed;
- this.Weight = Weight;
- this.BodyColor = BodyColor;
- this.AdditionalColor = AdditionalColor;
- this.Counterweight = Counterweight;
- this.Platform = Platform;
- }
-
-}
\ No newline at end of file
diff --git a/HoistingCrane/HoistingCrane/FormHoistingCrane.Designer.cs b/HoistingCrane/HoistingCrane/FormHoistingCrane.Designer.cs
index 3f8792b..a809bd5 100644
--- a/HoistingCrane/HoistingCrane/FormHoistingCrane.Designer.cs
+++ b/HoistingCrane/HoistingCrane/FormHoistingCrane.Designer.cs
@@ -9,7 +9,6 @@ namespace HoistingCrane
private System.ComponentModel.IContainer components = null;
-
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
@@ -19,17 +18,17 @@ namespace HoistingCrane
base.Dispose(disposing);
}
-
-
-
private void InitializeComponent()
{
pictureBoxHoistingCrane = new PictureBox();
- buttonCreate = new Button();
+ buttonCreateHoistingCrane = new Button();
ButtonLeft = new Button();
ButtonRight = new Button();
ButtonUp = new Button();
ButtonDown = new Button();
+ buttonCreateTrackedVehicle = new Button();
+ comboStrategy = new ComboBox();
+ buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxHoistingCrane).BeginInit();
SuspendLayout();
//
@@ -42,23 +41,23 @@ namespace HoistingCrane
pictureBoxHoistingCrane.TabIndex = 0;
pictureBoxHoistingCrane.TabStop = false;
//
- // buttonCreate
+ // buttonCreateHoistingCrane
//
- buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreate.Location = new Point(0, 492);
- buttonCreate.Name = "buttonCreate";
- buttonCreate.Size = new Size(75, 23);
- buttonCreate.TabIndex = 1;
- buttonCreate.Text = "Создать";
- buttonCreate.UseVisualStyleBackColor = true;
- buttonCreate.Click += ButtonCreate_Click;
+ buttonCreateHoistingCrane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreateHoistingCrane.Location = new Point(0, 492);
+ buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane";
+ buttonCreateHoistingCrane.Size = new Size(188, 23);
+ buttonCreateHoistingCrane.TabIndex = 1;
+ buttonCreateHoistingCrane.Text = "Создать подъемный кран";
+ buttonCreateHoistingCrane.UseVisualStyleBackColor = true;
+ buttonCreateHoistingCrane.Click += ButtonCreateHoistingCrane_Click;
//
// ButtonLeft
//
ButtonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonLeft.BackgroundImage = Properties.Resources.left_arrow;
ButtonLeft.BackgroundImageLayout = ImageLayout.Stretch;
- ButtonLeft.Location = new Point(118, 404);
+ ButtonLeft.Location = new Point(642, 475);
ButtonLeft.Name = "ButtonLeft";
ButtonLeft.Size = new Size(40, 40);
ButtonLeft.TabIndex = 2;
@@ -70,7 +69,7 @@ namespace HoistingCrane
ButtonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonRight.BackgroundImage = Properties.Resources.right_arrow;
ButtonRight.BackgroundImageLayout = ImageLayout.Stretch;
- ButtonRight.Location = new Point(207, 404);
+ ButtonRight.Location = new Point(734, 475);
ButtonRight.Name = "ButtonRight";
ButtonRight.Size = new Size(40, 40);
ButtonRight.TabIndex = 3;
@@ -82,7 +81,7 @@ namespace HoistingCrane
ButtonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonUp.BackgroundImage = Properties.Resources.up_arrow;
ButtonUp.BackgroundImageLayout = ImageLayout.Stretch;
- ButtonUp.Location = new Point(164, 367);
+ ButtonUp.Location = new Point(688, 429);
ButtonUp.Name = "ButtonUp";
ButtonUp.Size = new Size(40, 40);
ButtonUp.TabIndex = 4;
@@ -94,23 +93,57 @@ namespace HoistingCrane
ButtonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonDown.BackgroundImage = Properties.Resources.arrow_down_sign_to_navigate;
ButtonDown.BackgroundImageLayout = ImageLayout.Stretch;
- ButtonDown.Location = new Point(164, 440);
+ ButtonDown.Location = new Point(688, 475);
ButtonDown.Name = "ButtonDown";
ButtonDown.Size = new Size(40, 40);
ButtonDown.TabIndex = 5;
ButtonDown.UseVisualStyleBackColor = true;
ButtonDown.Click += ButtonMove_Click;
//
+ // buttonCreateTrackedVehicle
+ //
+ buttonCreateTrackedVehicle.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreateTrackedVehicle.Location = new Point(203, 492);
+ buttonCreateTrackedVehicle.Name = "buttonCreateTrackedVehicle";
+ buttonCreateTrackedVehicle.Size = new Size(194, 23);
+ buttonCreateTrackedVehicle.TabIndex = 6;
+ buttonCreateTrackedVehicle.Text = "Создать гусеничную машину";
+ buttonCreateTrackedVehicle.UseVisualStyleBackColor = true;
+ buttonCreateTrackedVehicle.Click += buttonCreateTrackedVehicle_Click;
+ //
+ // comboStrategy
+ //
+ comboStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboStrategy.FormattingEnabled = true;
+ comboStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
+ comboStrategy.Location = new Point(697, 42);
+ comboStrategy.Name = "comboStrategy";
+ comboStrategy.Size = new Size(121, 23);
+ comboStrategy.TabIndex = 7;
+ //
+ // buttonStrategyStep
+ //
+ buttonStrategyStep.Location = new Point(743, 71);
+ buttonStrategyStep.Name = "buttonStrategyStep";
+ buttonStrategyStep.Size = new Size(75, 23);
+ buttonStrategyStep.TabIndex = 8;
+ buttonStrategyStep.Text = "Шаг";
+ buttonStrategyStep.UseVisualStyleBackColor = true;
+ buttonStrategyStep.Click += ButtonStrategyStep_Click;
+ //
// FormHoistingCrane
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(818, 515);
+ Controls.Add(buttonStrategyStep);
+ Controls.Add(comboStrategy);
+ Controls.Add(buttonCreateTrackedVehicle);
Controls.Add(ButtonDown);
Controls.Add(ButtonUp);
Controls.Add(ButtonRight);
Controls.Add(ButtonLeft);
- Controls.Add(buttonCreate);
+ Controls.Add(buttonCreateHoistingCrane);
Controls.Add(pictureBoxHoistingCrane);
Name = "FormHoistingCrane";
Text = "Подъемный кран";
@@ -121,10 +154,13 @@ namespace HoistingCrane
// #endregion
private PictureBox pictureBoxHoistingCrane;
- private Button buttonCreate;
+ private Button buttonCreateHoistingCrane;
private Button ButtonLeft;
private Button ButtonRight;
private Button ButtonUp;
private Button ButtonDown;
+ private Button buttonCreateTrackedVehicle;
+ private ComboBox comboStrategy;
+ private Button buttonStrategyStep;
}
}
\ No newline at end of file
diff --git a/HoistingCrane/HoistingCrane/FormHoistingCrane.cs b/HoistingCrane/HoistingCrane/FormHoistingCrane.cs
index 7250345..a0f03af 100644
--- a/HoistingCrane/HoistingCrane/FormHoistingCrane.cs
+++ b/HoistingCrane/HoistingCrane/FormHoistingCrane.cs
@@ -1,60 +1,94 @@
-namespace HoistingCrane
+using HoistingCrane.Drawning;
+using HoistingCrane.MovementStrategy;
+
+namespace HoistingCrane
{
public partial class FormHoistingCrane : Form
{
- private DrawningHoistingCrane? _drawningHoistingCrane;
-
+ private DrawningTrackedVehicle? _drawning;
+ private AbstractStrategy? _abstractStrategy;
public FormHoistingCrane()
{
InitializeComponent();
+ _abstractStrategy = null;
}
private void Draw()
{
Bitmap bmp = new(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
Graphics gr = Graphics.FromImage(bmp);
- _drawningHoistingCrane?.DrawTransport(gr);
+ _drawning?.DrawTransport(gr);
pictureBoxHoistingCrane.Image = bmp;
}
- private void ButtonCreate_Click(object sender, EventArgs e)
+
+ ///
+ /// Создать подъемный кран
+ ///
+ ///
+ ///
+ private void ButtonCreateHoistingCrane_Click(object sender, EventArgs e)
{
-
- Random rand = new();
- _drawningHoistingCrane = new DrawningHoistingCrane();
- _drawningHoistingCrane.Init(
- rand.Next(100, 300),
- rand.Next(1000, 3000),
- Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)),
- Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)),
- Convert.ToBoolean(rand.Next(0,2)),
- Convert.ToBoolean(rand.Next(0,2))
- );
- _drawningHoistingCrane.SetPictureSize(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
- _drawningHoistingCrane.SetPosition(rand.Next(0, 100), rand.Next(0, 100));
- Draw();
-
+ CreateObject(nameof(DrawningHoistingCrane));
}
+
+ ///
+ /// Создать бронебойную машину
+ ///
+ ///
+ ///
+ private void buttonCreateTrackedVehicle_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningTrackedVehicle));
+ }
+
+
+ private void CreateObject(string type)
+ {
+ Random rand = new();
+ switch (type)
+ {
+
+ case nameof(DrawningHoistingCrane):
+ _drawning = new DrawningHoistingCrane(rand.Next(100, 300), rand.Next(1000, 3000), Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)),
+ Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)), true, true);
+ break;
+
+ case nameof(DrawningTrackedVehicle):
+ _drawning = new DrawningTrackedVehicle(rand.Next(100, 300), rand.Next(1000, 3000), Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)));
+ break;
+ default:
+ return;
+
+ }
+ _drawning.SetPictureSize(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
+ _drawning.SetPosition(rand.Next(0, 100), rand.Next(0, 100));
+
+ comboStrategy.Enabled = true;
+ Draw();
+ }
+
+
private void ButtonMove_Click(object sender, EventArgs e)
{
- if (_drawningHoistingCrane == null) { return; }
+ if (_drawning == null) { return; }
String name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
{
case "ButtonUp":
- result = _drawningHoistingCrane.MoveTransport(DirectionType.Up);
+ result = _drawning.MoveTransport(DirectionType.Up);
break;
case "ButtonDown":
- result = _drawningHoistingCrane.MoveTransport(DirectionType.Down);
+ result = _drawning.MoveTransport(DirectionType.Down);
break;
case "ButtonRight":
- result = _drawningHoistingCrane.MoveTransport(DirectionType.Right);
+ result = _drawning.MoveTransport(DirectionType.Right);
break;
case "ButtonLeft":
- result = _drawningHoistingCrane.MoveTransport(DirectionType.Left);
+ result = _drawning.MoveTransport(DirectionType.Left);
break;
}
if (result)
@@ -65,6 +99,42 @@
}
+ private void ButtonStrategyStep_Click(object sender, EventArgs e)
+ {
+ if (_drawning == null)
+ {
+ return;
+ }
+ if (comboStrategy.Enabled)
+ {
+ _abstractStrategy = comboStrategy.SelectedIndex switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
+ if (_abstractStrategy == null)
+ {
+ return;
+ }
+ _abstractStrategy.SetData(new MoveableCar(_drawning), pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
+ }
+
+ if (_abstractStrategy == null)
+ {
+ return;
+ }
+
+ comboStrategy.Enabled = false;
+ _abstractStrategy.MakeStep();
+ Draw();
+
+ if (_abstractStrategy.GetStatus() == StrategyStatus.Finish)
+ {
+ comboStrategy.Enabled = true;
+ _abstractStrategy = null;
+ }
+ }
}
}
diff --git a/HoistingCrane/HoistingCrane/MovementStrategy/AbstractStrategy.cs b/HoistingCrane/HoistingCrane/MovementStrategy/AbstractStrategy.cs
new file mode 100644
index 0000000..43e18e9
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/MovementStrategy/AbstractStrategy.cs
@@ -0,0 +1,139 @@
+namespace HoistingCrane.MovementStrategy
+{
+ public abstract class AbstractStrategy
+ {
+ ///
+ /// Перемещаемый объект
+ ///
+ private IMoveableObjects? _moveableObject;
+
+ ///
+ /// Статус перемещения
+ ///
+ private StrategyStatus _state = StrategyStatus.NotInit;
+
+ ///
+ /// Ширина поля
+ ///
+ protected int FieldWidth { get; private set; }
+
+ ///
+ /// Высота поля
+ ///
+ protected int FieldHeight { get; private set; }
+
+ ///
+ /// Статус перемещения
+ ///
+ ///
+ public StrategyStatus GetStatus() { return _state; }
+
+ ///
+ /// Установка данных
+ ///
+ /// Перемещаемый объект
+ /// Ширина поля
+ /// Высота поля
+ public void SetData(IMoveableObjects moveableObject, int width, int height)
+ {
+ if (moveableObject == null)
+ {
+ _state = StrategyStatus.NotInit;
+ return;
+ }
+
+ _state = StrategyStatus.InProgress;
+ _moveableObject = moveableObject;
+ FieldWidth = width;
+ FieldHeight = height;
+ }
+
+ ///
+ /// Шаг перемещения
+ ///
+ public void MakeStep()
+ {
+ if (_state != StrategyStatus.InProgress)
+ {
+ return;
+ }
+
+ if (IsTargetDestination())
+ {
+ _state = StrategyStatus.Finish;
+ return;
+ }
+
+ MoveToTarget();
+ }
+
+ ///
+ /// Перемещение влево
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveLeft() => MoveTo(MovementDirection.Left);
+
+ ///
+ /// Перемещение вправо
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveRight() => MoveTo(MovementDirection.Right);
+
+ ///
+ /// Перемещение вверх
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveUp() => MoveTo(MovementDirection.Up);
+
+ ///
+ /// Перемещение вниз
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveDown() => MoveTo(MovementDirection.Down);
+
+ ///
+ /// Параметры объекта
+ ///
+ protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
+
+ ///
+ /// Шаг объекта
+ ///
+ ///
+ protected int? GetStep()
+ {
+ if (_state != StrategyStatus.InProgress)
+ {
+ return null;
+ }
+ return _moveableObject?.GetStep;
+ }
+
+ ///
+ /// Перемещение к цели
+ ///
+ protected abstract void MoveToTarget();
+
+ ///
+ /// Достигнута ли цель
+ ///
+ ///
+ protected abstract bool IsTargetDestination();
+
+ ///
+ /// Попытка перемещения в требуемом направлении
+ ///
+ /// Направление
+ /// Результат попытки (true - удалось, false - неудача)
+ private bool MoveTo(MovementDirection movementDirection)
+ {
+ if (_state != StrategyStatus.InProgress)
+ {
+ return false;
+ }
+
+ return _moveableObject?.TryMoveObject(movementDirection) ?? false;
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/HoistingCrane/HoistingCrane/MovementStrategy/IMoveableObjects.cs b/HoistingCrane/HoistingCrane/MovementStrategy/IMoveableObjects.cs
new file mode 100644
index 0000000..9ce6732
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/MovementStrategy/IMoveableObjects.cs
@@ -0,0 +1,24 @@
+namespace HoistingCrane.MovementStrategy
+{
+ public interface IMoveableObjects
+ {
+ ///
+ /// Получение позиции объекта
+ ///
+ ObjectParameters? GetObjectPosition { get; }
+
+
+ ///
+ /// Получение шага объекта
+ ///
+ int GetStep { get; }
+
+
+ ///
+ /// Попытка переместить объект в указанном направлении
+ ///
+ /// направление
+ ///
+ bool TryMoveObject(MovementDirection direction);
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/MovementStrategy/MoveToBorder.cs b/HoistingCrane/HoistingCrane/MovementStrategy/MoveToBorder.cs
new file mode 100644
index 0000000..99cb56b
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/MovementStrategy/MoveToBorder.cs
@@ -0,0 +1,51 @@
+namespace HoistingCrane.MovementStrategy
+{
+ public class MoveToBorder : AbstractStrategy
+ {
+ protected override bool IsTargetDestination()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return false;
+ }
+
+ return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight;
+ }
+
+ protected override void MoveToTarget()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return;
+ }
+
+ int diffX = objParams.RightBorder - FieldWidth;
+ if (Math.Abs(diffX) > GetStep())
+ {
+ if (diffX > 0)
+ {
+ MoveLeft();
+ }
+ else
+ {
+ MoveRight();
+ }
+ }
+
+ int diffY = objParams.DownBorder - FieldHeight;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ if (diffY > 0)
+ {
+ MoveUp();
+ }
+ else
+ {
+ MoveDown();
+ }
+ }
+ }
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/MovementStrategy/MoveToCenter.cs b/HoistingCrane/HoistingCrane/MovementStrategy/MoveToCenter.cs
new file mode 100644
index 0000000..aea7661
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/MovementStrategy/MoveToCenter.cs
@@ -0,0 +1,52 @@
+namespace HoistingCrane.MovementStrategy
+{
+ public class MoveToCenter : AbstractStrategy
+ {
+ protected override bool IsTargetDestination()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return false;
+ }
+
+ return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
+ objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
+ }
+
+ protected override void MoveToTarget()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return;
+ }
+
+ int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
+ if (Math.Abs(diffX) > GetStep())
+ {
+ if (diffX > 0)
+ {
+ MoveLeft();
+ }
+ else
+ {
+ MoveRight();
+ }
+ }
+
+ int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ if (diffY > 0)
+ {
+ MoveUp();
+ }
+ else
+ {
+ MoveDown();
+ }
+ }
+ }
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/MovementStrategy/MoveableCar.cs b/HoistingCrane/HoistingCrane/MovementStrategy/MoveableCar.cs
new file mode 100644
index 0000000..bbeaf9e
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/MovementStrategy/MoveableCar.cs
@@ -0,0 +1,62 @@
+using HoistingCrane.Drawning;
+
+namespace HoistingCrane.MovementStrategy
+{
+ public class MoveableCar : IMoveableObjects
+ {
+ ///
+ /// Поле-объект класса DrawningAirplane или его наследника
+ ///
+ private readonly DrawningTrackedVehicle? drawningTrackedVehicle = null;
+ ///
+ /// Конструктор
+ ///
+ /// Объект класса DrawningAirplane
+ public MoveableCar(DrawningTrackedVehicle drawningTrackedVehicle)
+ {
+ this.drawningTrackedVehicle = drawningTrackedVehicle;
+ }
+
+ public ObjectParameters? GetObjectPosition
+ {
+ get
+ {
+ if (drawningTrackedVehicle == null || drawningTrackedVehicle.EntityTrackedVehicle == null || !drawningTrackedVehicle.GetPosX.HasValue || !drawningTrackedVehicle.GetPosY.HasValue)
+ {
+ return null;
+ }
+ return new ObjectParameters(drawningTrackedVehicle.GetPosX.Value, drawningTrackedVehicle.GetPosY.Value, drawningTrackedVehicle.GetWidth, drawningTrackedVehicle.GetHeight);
+ }
+ }
+
+
+ public int GetStep => (int)(drawningTrackedVehicle?.EntityTrackedVehicle?.Step ?? 0);
+
+ public bool TryMoveObject(MovementDirection direction)
+ {
+ if (drawningTrackedVehicle == null || drawningTrackedVehicle.EntityTrackedVehicle == null)
+ {
+ return false;
+ }
+
+ return drawningTrackedVehicle.MoveTransport(GetDirectionType(direction));
+ }
+
+ ///
+ /// Конвертация из MovementDirection в DirectionType
+ ///
+ /// MovementDirection
+ /// DirectionType
+ private static DirectionType GetDirectionType(MovementDirection direction)
+ {
+ return direction switch
+ {
+ MovementDirection.Left => DirectionType.Left,
+ MovementDirection.Right => DirectionType.Right,
+ MovementDirection.Up => DirectionType.Up,
+ MovementDirection.Down => DirectionType.Down,
+ _ => DirectionType.Unknow,
+ };
+ }
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/MovementStrategy/MovementDirection.cs b/HoistingCrane/HoistingCrane/MovementStrategy/MovementDirection.cs
new file mode 100644
index 0000000..9c2632a
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/MovementStrategy/MovementDirection.cs
@@ -0,0 +1,24 @@
+namespace HoistingCrane.MovementStrategy
+{
+ public enum MovementDirection
+ {
+ //Перечислим основные траектории движния нашего автомобиля. Сразу же зададим значения.
+ ///
+ /// Вверх1
+ ///
+ Up = 1,
+ ///
+ /// Вниз
+ ///
+ Down = 2,
+ ///
+ /// Влево
+ ///
+ Left = 3,
+ ///
+ /// Вправо
+ ///
+ Right = 4
+
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/MovementStrategy/ObjectParameters.cs b/HoistingCrane/HoistingCrane/MovementStrategy/ObjectParameters.cs
new file mode 100644
index 0000000..57257e5
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/MovementStrategy/ObjectParameters.cs
@@ -0,0 +1,70 @@
+namespace HoistingCrane.MovementStrategy
+{
+ public class ObjectParameters
+ {
+ ///
+ /// Начальная координата х
+ ///
+ private readonly int _x;
+
+ ///
+ /// Начальная координата y
+ ///
+ private readonly int _y;
+
+ ///
+ /// Ширина объекта
+ ///
+ private readonly int _width;
+
+ ///
+ /// Высота объекта
+ ///
+ private readonly int _height;
+
+ ///
+ /// Левая граница
+ ///
+ public int LeftBorder => _x;
+
+ ///
+ /// Правая граница
+ ///
+ public int RightBorder => _x + _width;
+
+ ///
+ /// Верхняя граница
+ ///
+ public int TopBorder => _y;
+
+ ///
+ /// Нижняя граница
+ ///
+ public int DownBorder => _y + _height;
+
+ ///
+ /// Центральная координата по горизонтали
+ ///
+ public int ObjectMiddleHorizontal => _x + _width / 2;
+
+ ///
+ /// Центральная координата по вертикали
+ ///
+ public int ObjectMiddleVertical => _y + _height / 2;
+
+ ///
+ /// Конструктор
+ ///
+ /// Координата по х
+ /// Координата по у
+ /// Ширина объекта
+ /// Высота объекта
+ public ObjectParameters(int _x, int _y, int _width, int _height)
+ {
+ this._x = _x;
+ this._y = _y;
+ this._width = _width;
+ this._height = _height;
+ }
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/MovementStrategy/StrategyStatus.cs b/HoistingCrane/HoistingCrane/MovementStrategy/StrategyStatus.cs
new file mode 100644
index 0000000..3a9cf4f
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/MovementStrategy/StrategyStatus.cs
@@ -0,0 +1,21 @@
+namespace HoistingCrane.MovementStrategy
+{
+ public enum StrategyStatus
+ {
+ ///
+ /// Всё готово к началу
+ ///
+ NotInit,
+
+ ///
+ /// Выполняется
+ ///
+ InProgress,
+
+ ///
+ /// Завершено
+ ///
+ Finish
+
+ }
+}