diff --git a/ProjectAiSD/ProjectAiSD.sln b/ProjectAiSD/ProjectAiSD.sln
new file mode 100644
index 0000000..d414e0a
--- /dev/null
+++ b/ProjectAiSD/ProjectAiSD.sln
@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.8.34330.188
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ProjectAiSD", "ProjectAiSD\ProjectAiSD.vcxproj", "{1203BB93-5B4B-446F-9CD3-4E1FBC19A791}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {1203BB93-5B4B-446F-9CD3-4E1FBC19A791}.Debug|x64.ActiveCfg = Debug|x64
+ {1203BB93-5B4B-446F-9CD3-4E1FBC19A791}.Debug|x64.Build.0 = Debug|x64
+ {1203BB93-5B4B-446F-9CD3-4E1FBC19A791}.Debug|x86.ActiveCfg = Debug|Win32
+ {1203BB93-5B4B-446F-9CD3-4E1FBC19A791}.Debug|x86.Build.0 = Debug|Win32
+ {1203BB93-5B4B-446F-9CD3-4E1FBC19A791}.Release|x64.ActiveCfg = Release|x64
+ {1203BB93-5B4B-446F-9CD3-4E1FBC19A791}.Release|x64.Build.0 = Release|x64
+ {1203BB93-5B4B-446F-9CD3-4E1FBC19A791}.Release|x86.ActiveCfg = Release|Win32
+ {1203BB93-5B4B-446F-9CD3-4E1FBC19A791}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {6902D87F-9F53-4C0D-8571-543876503D6B}
+ EndGlobalSection
+EndGlobal
diff --git a/ProjectAiSD/ProjectAiSD/FileAiSD.c b/ProjectAiSD/ProjectAiSD/FileAiSD.c
new file mode 100644
index 0000000..e69de29
diff --git a/ProjectAiSD/ProjectAiSD/ProjectAiSD.vcxproj b/ProjectAiSD/ProjectAiSD/ProjectAiSD.vcxproj
new file mode 100644
index 0000000..7c6c389
--- /dev/null
+++ b/ProjectAiSD/ProjectAiSD/ProjectAiSD.vcxproj
@@ -0,0 +1,138 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+
+ 17.0
+ Win32Proj
+ {1203bb93-5b4b-446f-9cd3-4e1fbc19a791}
+ ProjectAiSD
+ 10.0
+
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Level3
+ true
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+ Level3
+ true
+ _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+
+
+
+
diff --git a/ProjectAiSD/ProjectAiSD/ProjectAiSD.vcxproj.filters b/ProjectAiSD/ProjectAiSD/ProjectAiSD.vcxproj.filters
new file mode 100644
index 0000000..153170c
--- /dev/null
+++ b/ProjectAiSD/ProjectAiSD/ProjectAiSD.vcxproj.filters
@@ -0,0 +1,17 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+
+
\ No newline at end of file
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/DrawingHoistingCrane.cs b/ProjectHoistingCrane/ProjectHoistingCrane/DrawingHoistingCrane.cs
deleted file mode 100644
index 0f71b92..0000000
--- a/ProjectHoistingCrane/ProjectHoistingCrane/DrawingHoistingCrane.cs
+++ /dev/null
@@ -1,249 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ProjectHoistingCrane;
-
-public class DrawningHoistingCrane
-{
- ///
- /// Класс-сущность
- ///
- public EntityHoistingCrane? EntityHoistingCrane { get; private set; }
- ///
- /// Ширина окна
- ///
- private int? _pictureWidth;
- ///
- /// Высота окна
- ///
- private int? _pictureHeight;
- ///
- /// Левая координата прорисовки автомобиля
- ///
- private int? _startPosX;
- ///
- /// Верхняя кооридната прорисовки автомобиля
- ///
- private int? _startPosY;
- ///
- /// Ширина прорисовки автомобиля
- ///
- private readonly int _drawningCraneWidth = 110;
- ///
- /// Высота прорисовки автомобиля
- ///
- private readonly int _drawningCraneHeight = 56;
- ///
- /// Инициализация свойств
- ///
- /// Скорость
- /// Вес
- /// Основной цвет
- /// Дополнительный цвет
- /// Признак наличия противовеса
- /// Признак наличия крана
- public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool counterweight, bool crane)
- {
- EntityHoistingCrane = new EntityHoistingCrane();
- EntityHoistingCrane.Init(speed, weight, bodyColor, additionalColor,
- counterweight, crane);
- _pictureWidth = null;
- _pictureHeight = null;
- _startPosX = null;
- _startPosY = null;
- }
- ///
- /// Установка границ поля
- ///
- /// Ширина поля
- /// Высота поля
- /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах
- public bool SetPictureSize(int width, int height)
- {
- // TODO проверка, что объект "влезает" в размеры поля
- // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
-
- if (width <= _drawningCraneWidth || height <= _drawningCraneHeight)
- {
- return false;
- }
-
- _pictureWidth = width;
- _pictureHeight = height;
-
- if (_startPosX != null || _startPosY != null)
- {
- if (_startPosX + _drawningCraneWidth > _pictureWidth) _startPosX = _pictureWidth - _drawningCraneWidth;
- if (_startPosY + _drawningCraneHeight > _pictureHeight) _startPosY = _pictureHeight - _drawningCraneHeight;
- if (_startPosX < 0) _startPosX = 0;
- if (_startPosY < 0) _startPosY = 0;
- }
-
- return true;
- }
-
- ///
- /// Установка позиции
- ///
- /// Координата X
- /// Координата Y
- public void SetPosition(int x, int y)
- {
- if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
- {
- return;
- }
-
- // TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
- // то надо изменить координаты, чтобы он оставался в этих границах
-
- _startPosX = x;
- _startPosY = y;
- if (_startPosX + _drawningCraneWidth > _pictureWidth) _startPosX = _pictureWidth - _drawningCraneWidth;
- if (_startPosY + _drawningCraneHeight > _pictureHeight) _startPosY = _pictureHeight - _drawningCraneHeight;
- if (_startPosX < 0) _startPosX = 0;
- if (_startPosY < 0) _startPosY = 0;
- }
-
- ///
- /// Изменение направления перемещения
- ///
- /// Направление
- /// true - перемещене выполнено, false - перемещение невозможно
- 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 < _pictureWidth - _drawningCraneWidth)
- {
- _startPosX += (int)EntityHoistingCrane.Step;
- }
- //TODO прописать логику сдвига в право
- return true;
- //вниз
- case DirectionType.Down:
- if (_startPosY.Value + EntityHoistingCrane.Step < _pictureHeight - _drawningCraneHeight)
- {
- _startPosY += (int)EntityHoistingCrane.Step;
- }
- //TODO прописать логику сдвига в вниз
- return true;
- default:
- return false;
- }
- }
-
- ///
- /// Прорисовка объекта
- ///
- ///
- public void DrawTransport(Graphics g)
- {
- if (EntityHoistingCrane == null || !_startPosX.HasValue || !_startPosY.HasValue)
- {
- return;
- }
- Pen pen = new(Color.Black);
- Brush additionalBrush = new SolidBrush(EntityHoistingCrane.AdditionalColor);
- Brush BodyBrush = new SolidBrush(EntityHoistingCrane.BodyColor);
- Brush CraneBrush = new SolidBrush(Color.Black);
-
-
- //корпус
- g.FillRectangle(BodyBrush, _startPosX.Value + 10, _startPosY.Value + 30, 62, 12);
- g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 30, 62, 12);
- g.FillRectangle(BodyBrush, _startPosX.Value + 22, _startPosY.Value + 16, 4, 15);
- g.DrawRectangle(pen, _startPosX.Value + 22, _startPosY.Value + 16, 4, 14);
- g.FillRectangle(BodyBrush, _startPosX.Value + 37, _startPosY.Value + 8, 5, 23);
- g.DrawRectangle(pen, _startPosX.Value + 37, _startPosY.Value + 8, 5, 22);
-
- //стекло
- g.FillRectangle(additionalBrush, _startPosX.Value + 52, _startPosY.Value + 14, 21, 16);
- g.DrawRectangle(pen, _startPosX.Value + 52, _startPosY.Value + 14, 20, 16);
-
- //гусеницы
- g.DrawLine(pen, _startPosX.Value + 8, _startPosY.Value + 42, _startPosX.Value + 10, _startPosY.Value + 42);
- g.DrawLine(pen, _startPosX.Value + 7, _startPosY.Value + 43, _startPosX.Value + 7, _startPosY.Value + 53);
- g.DrawLine(pen, _startPosX.Value + 8, _startPosY.Value + 54, _startPosX.Value + 12, _startPosY.Value + 54);
- g.DrawLine(pen, _startPosX.Value + 13, _startPosY.Value + 55, _startPosX.Value + 69, _startPosY.Value + 55);
- g.DrawLine(pen, _startPosX.Value + 70, _startPosY.Value + 54, _startPosX.Value + 73, _startPosY.Value + 54);
- g.DrawLine(pen, _startPosX.Value + 74, _startPosY.Value + 53, _startPosX.Value + 74, _startPosY.Value + 43);
- g.DrawLine(pen, _startPosX.Value + 71, _startPosY.Value + 42, _startPosX.Value + 73, _startPosY.Value + 42);
-
- //колеса
- g.FillEllipse(BodyBrush, _startPosX.Value + 10, _startPosY.Value + 44, 9, 9);
- g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 44, 9, 9);
- g.FillEllipse(BodyBrush, _startPosX.Value + 63, _startPosY.Value + 44, 9, 9);
- g.DrawEllipse(pen, _startPosX.Value + 63, _startPosY.Value + 44, 9, 9);
-
- g.FillEllipse(BodyBrush, _startPosX.Value + 25, _startPosY.Value + 48, 6, 6);
- g.DrawEllipse(pen, _startPosX.Value + 25, _startPosY.Value + 48, 6, 6);
- g.FillEllipse(BodyBrush, _startPosX.Value + 38, _startPosY.Value + 48, 6, 6);
- g.DrawEllipse(pen, _startPosX.Value + 38, _startPosY.Value + 48, 6, 6);
- g.FillEllipse(BodyBrush, _startPosX.Value + 50, _startPosY.Value + 48, 6, 6);
- g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 48, 6, 6);
-
- g.FillEllipse(BodyBrush, _startPosX.Value + 33, _startPosY.Value + 44, 4, 4);
- g.DrawEllipse(pen, _startPosX.Value + 33, _startPosY.Value + 44, 4, 4);
- g.FillEllipse(BodyBrush, _startPosX.Value + 45, _startPosY.Value + 44, 4, 4);
- g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 44, 4, 4);
-
- //кран
- if (EntityHoistingCrane.Crane)
- {
- //балка
- g.FillRectangle(BodyBrush, _startPosX.Value, _startPosY.Value, 110, 9);
- g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 109, 8);
-
- //крюк
- g.FillRectangle(CraneBrush , _startPosX.Value + 107, _startPosY.Value + 8, 3, 13);
- g.FillRectangle(CraneBrush, _startPosX.Value + 102, _startPosY.Value + 18, 8, 3);
- g.FillRectangle(CraneBrush, _startPosX.Value + 102, _startPosY.Value + 16, 3, 5);
- }
-
- //противовес
- if (EntityHoistingCrane.Сounterweight)
- {
- g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value, 10, 9);
- g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value, 9, 8);
-
- g.DrawLine(pen, _startPosX.Value + 35, _startPosY.Value + 2, _startPosX.Value + 44, _startPosY.Value + 2);
- g.DrawLine(pen, _startPosX.Value + 35, _startPosY.Value + 4, _startPosX.Value + 44, _startPosY.Value + 4);
- g.DrawLine(pen, _startPosX.Value + 35, _startPosY.Value + 6, _startPosX.Value + 44, _startPosY.Value + 6);
- }
- }
-}
-
-
-
-
-
-
-
-
-
-
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/DirectionType.cs b/ProjectHoistingCrane/ProjectHoistingCrane/Drawnings/DirectionType.cs
similarity index 77%
rename from ProjectHoistingCrane/ProjectHoistingCrane/DirectionType.cs
rename to ProjectHoistingCrane/ProjectHoistingCrane/Drawnings/DirectionType.cs
index f3ef53c..d0dfa5b 100644
--- a/ProjectHoistingCrane/ProjectHoistingCrane/DirectionType.cs
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/Drawnings/DirectionType.cs
@@ -4,13 +4,17 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace ProjectHoistingCrane;
+namespace ProjectHoistingCrane.Drawnings;
///
/// Направление перемещения
///
public enum DirectionType
{
+ ///
+ /// Неизвестное направление
+ ///
+ Unknow = -1,
///
/// Вверх
///
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/Drawnings/DrawningCrane.cs b/ProjectHoistingCrane/ProjectHoistingCrane/Drawnings/DrawningCrane.cs
new file mode 100644
index 0000000..41917bc
--- /dev/null
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/Drawnings/DrawningCrane.cs
@@ -0,0 +1,252 @@
+using ProjectHoistingCrane.Entities;
+namespace ProjectHoistingCrane.Drawnings;
+
+public class DrawningCrane
+{
+ ///
+ /// Класс-сущность
+ ///
+ public EntityCrane? EntityCrane { get; protected set; }
+ ///
+ /// Ширина окна
+ ///
+ private int? _pictureWidth;
+ ///
+ /// Высота окна
+ ///
+ private int? _pictureHeight;
+ ///
+ /// Левая координата прорисовки автомобиля
+ ///
+ protected int? _startPosX;
+ ///
+ /// Верхняя кооридната прорисовки автомобиля
+ ///
+ protected int? _startPosY;
+ ///
+ /// Ширина прорисовки автомобиля
+ ///
+ private readonly int _drawningCraneWidth = 68;
+ ///
+ /// Высота прорисовки автомобиля
+ ///
+ private readonly int _drawningCraneHeight = 48;
+
+ ///
+ /// Координата X объекта
+ ///
+ public int? GetPosX => _startPosX;
+
+ ///
+ /// Координата Y объекта
+ ///
+ public int? GetPosY => _startPosY;
+
+ ///
+ /// Ширина объекта
+ ///
+ public int GetWidth => _drawningCraneWidth;
+
+ ///
+ /// Высота объекта
+ ///
+ public int GetHeight => _drawningCraneHeight;
+
+ ///
+ /// Пустой конструктор
+ ///
+ private DrawningCrane()
+ {
+ _pictureWidth = null;
+ _pictureHeight = null;
+ _startPosX = null;
+ _startPosY = null;
+ }
+
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+
+ public DrawningCrane(int speed, double weight, Color bodyColor) : this()
+ {
+ EntityCrane = new EntityCrane(speed, weight, bodyColor);
+ }
+
+ ///
+ /// Конструктор для наследников
+ ///
+ /// Ширина прорисовки крана
+ /// Высота прорисовки крана
+
+
+ protected DrawningCrane(int drawningCraneWidth, int drawningCraneHeight) : this()
+ {
+ _drawningCraneWidth = drawningCraneWidth;
+ _drawningCraneHeight = drawningCraneHeight;
+ }
+
+
+ ///
+ /// Установка границ поля
+ ///
+ /// Ширина поля
+ /// Высота поля
+ /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах
+ public bool SetPictureSize(int width, int height)
+ {
+ // TODO проверка, что объект "влезает" в размеры поля
+ // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
+
+ if (width <= _drawningCraneWidth || height <= _drawningCraneHeight)
+ {
+ return false;
+ }
+
+ _pictureWidth = width;
+ _pictureHeight = height;
+
+ if (_startPosX != null || _startPosY != null)
+ {
+ if (_startPosX + _drawningCraneWidth > _pictureWidth) _startPosX = _pictureWidth - _drawningCraneWidth;
+ if (_startPosY + _drawningCraneHeight > _pictureHeight) _startPosY = _pictureHeight - _drawningCraneHeight;
+ if (_startPosX < 0) _startPosX = 0;
+ if (_startPosY < 0) _startPosY = 0;
+ }
+
+ return true;
+ }
+
+ ///
+ /// Установка позиции
+ ///
+ /// Координата X
+ /// Координата Y
+ public void SetPosition(int x, int y)
+ {
+ if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
+ {
+ return;
+ }
+
+ // TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
+ // то надо изменить координаты, чтобы он оставался в этих границах
+
+ _startPosX = x;
+ _startPosY = y;
+ if (_startPosX + _drawningCraneWidth > _pictureWidth) _startPosX = _pictureWidth - _drawningCraneWidth;
+ if (_startPosY + _drawningCraneHeight > _pictureHeight) _startPosY = _pictureHeight - _drawningCraneHeight;
+ if (_startPosX < 0) _startPosX = 0;
+ if (_startPosY < 0) _startPosY = 0;
+ }
+
+ ///
+ /// Изменение направления перемещения
+ ///
+ /// Направление
+ /// true - перемещене выполнено, false - перемещение невозможно
+ public bool MoveTransport(DirectionType direction)
+ {
+ if (EntityCrane == null || !_startPosX.HasValue ||
+ !_startPosY.HasValue)
+ {
+ return false;
+ }
+ switch (direction)
+ {
+ //влево
+ case DirectionType.Left:
+ if (_startPosX.Value - EntityCrane.Step > 0)
+ {
+ _startPosX -= (int)EntityCrane.Step;
+ }
+ return true;
+ //вверх
+ case DirectionType.Up:
+ if (_startPosY.Value - EntityCrane.Step > 0)
+ {
+ _startPosY -= (int)EntityCrane.Step;
+ }
+ return true;
+ // вправо
+ case DirectionType.Right:
+ if (_startPosX.Value + EntityCrane.Step < _pictureWidth - _drawningCraneWidth)
+ {
+ _startPosX += (int)EntityCrane.Step;
+ }
+ //TODO прописать логику сдвига в право
+ return true;
+ //вниз
+ case DirectionType.Down:
+ if (_startPosY.Value + EntityCrane.Step < _pictureHeight - _drawningCraneHeight)
+ {
+ _startPosY += (int)EntityCrane.Step;
+ }
+ //TODO прописать логику сдвига в вниз
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ ///
+ /// Прорисовка объекта
+ ///
+ ///
+ public virtual void DrawTransport(Graphics g)
+ {
+ if (EntityCrane == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+ Pen pen = new(Color.Black);
+
+
+ Brush BodyBrush = new SolidBrush(EntityCrane.BodyColor);
+ Brush WindowBrush = new SolidBrush(Color.Blue);
+
+
+ //корпус
+ g.FillRectangle(BodyBrush, _startPosX.Value + 3, _startPosY.Value + 22, 62, 12);
+ g.DrawRectangle(pen, _startPosX.Value + 3, _startPosY.Value + 22, 62, 12);
+ g.FillRectangle(BodyBrush, _startPosX.Value + 15, _startPosY.Value + 8, 4, 15);
+ g.DrawRectangle(pen, _startPosX.Value + 15, _startPosY.Value + 8, 4, 14);
+ g.FillRectangle(BodyBrush, _startPosX.Value + 30, _startPosY.Value, 5, 23);
+ g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value, 5, 22);
+
+ //стекло
+ g.FillRectangle(WindowBrush, _startPosX.Value + 45, _startPosY.Value + 6, 21, 16);
+ g.DrawRectangle(pen, _startPosX.Value + 45, _startPosY.Value + 6, 20, 16);
+
+ //гусеницы
+ g.DrawLine(pen, _startPosX.Value + 1, _startPosY.Value + 34, _startPosX.Value + 3, _startPosY.Value + 34);
+ g.DrawLine(pen, _startPosX.Value, _startPosY.Value + 35, _startPosX.Value, _startPosY.Value + 45);
+ g.DrawLine(pen, _startPosX.Value + 1, _startPosY.Value + 46, _startPosX.Value + 5, _startPosY.Value + 46);
+ g.DrawLine(pen, _startPosX.Value + 6, _startPosY.Value + 47, _startPosX.Value + 62, _startPosY.Value + 47);
+ g.DrawLine(pen, _startPosX.Value + 63, _startPosY.Value + 46, _startPosX.Value + 66, _startPosY.Value + 46);
+ g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 45, _startPosX.Value + 67, _startPosY.Value + 35);
+ g.DrawLine(pen, _startPosX.Value + 64, _startPosY.Value + 34, _startPosX.Value + 66, _startPosY.Value + 34);
+
+ //колеса
+ g.FillEllipse(BodyBrush, _startPosX.Value + 3, _startPosY.Value + 36, 9, 9);
+ g.DrawEllipse(pen, _startPosX.Value + 3, _startPosY.Value + 36, 9, 9);
+ g.FillEllipse(BodyBrush, _startPosX.Value + 56, _startPosY.Value + 36, 9, 9);
+ g.DrawEllipse(pen, _startPosX.Value + 56, _startPosY.Value + 36, 9, 9);
+
+ g.FillEllipse(BodyBrush, _startPosX.Value + 18, _startPosY.Value + 40, 6, 6);
+ g.DrawEllipse(pen, _startPosX.Value + 18, _startPosY.Value + 40, 6, 6);
+ g.FillEllipse(BodyBrush, _startPosX.Value + 31, _startPosY.Value + 40, 6, 6);
+ g.DrawEllipse(pen, _startPosX.Value + 31, _startPosY.Value + 40, 6, 6);
+ g.FillEllipse(BodyBrush, _startPosX.Value + 43, _startPosY.Value + 40, 6, 6);
+ g.DrawEllipse(pen, _startPosX.Value + 43, _startPosY.Value + 40, 6, 6);
+
+ g.FillEllipse(BodyBrush, _startPosX.Value + 26, _startPosY.Value + 36, 4, 4);
+ g.DrawEllipse(pen, _startPosX.Value + 26, _startPosY.Value + 36, 4, 4);
+ g.FillEllipse(BodyBrush, _startPosX.Value + 38, _startPosY.Value + 36, 4, 4);
+ g.DrawEllipse(pen, _startPosX.Value + 38, _startPosY.Value + 36, 4, 4);
+
+
+ }
+}
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/Drawnings/DrawningHoistingCrane.cs b/ProjectHoistingCrane/ProjectHoistingCrane/Drawnings/DrawningHoistingCrane.cs
new file mode 100644
index 0000000..0727322
--- /dev/null
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/Drawnings/DrawningHoistingCrane.cs
@@ -0,0 +1,76 @@
+using ProjectHoistingCrane.Entities;
+
+namespace ProjectHoistingCrane.Drawnings;
+
+public class DrawningHoistingCrane : DrawningCrane
+{
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ /// Дополнительный цвет
+ /// Признак наличия противовеса
+ /// Признак наличия крана
+ public DrawningHoistingCrane(int speed, double weight, Color bodyColor, Color additionalColor, bool counterweight, bool crane) : base(110, 56)
+ {
+ EntityCrane = new EntityHoistingCrane(speed, weight, bodyColor, additionalColor,
+ counterweight, crane);
+
+ }
+
+ public override void DrawTransport(Graphics g)
+ {
+ if (EntityCrane == null || EntityCrane is not EntityHoistingCrane hoistingCrane || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush additionalBrush = new SolidBrush(hoistingCrane.AdditionalColor);
+
+
+
+ _startPosX += 7;
+ _startPosY += 8;
+ base.DrawTransport(g);
+ _startPosX -= 7;
+ _startPosY -= 8;
+
+
+ //кран
+ if (hoistingCrane.Crane)
+ {
+ //балка
+ g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value, 110, 9);
+ g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 109, 8);
+
+ //крюк
+ g.FillRectangle(additionalBrush, _startPosX.Value + 107, _startPosY.Value + 8, 3, 13);
+ g.FillRectangle(additionalBrush, _startPosX.Value + 102, _startPosY.Value + 18, 8, 3);
+ g.FillRectangle(additionalBrush, _startPosX.Value + 102, _startPosY.Value + 16, 3, 5);
+ }
+
+ //противовес
+ if (hoistingCrane.Сounterweight)
+ {
+ g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value, 10, 9);
+ g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value, 9, 8);
+
+ g.DrawLine(pen, _startPosX.Value + 35, _startPosY.Value + 2, _startPosX.Value + 44, _startPosY.Value + 2);
+ g.DrawLine(pen, _startPosX.Value + 35, _startPosY.Value + 4, _startPosX.Value + 44, _startPosY.Value + 4);
+ g.DrawLine(pen, _startPosX.Value + 35, _startPosY.Value + 6, _startPosX.Value + 44, _startPosY.Value + 6);
+ }
+ }
+}
+
+
+
+
+
+
+
+
+
+
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/Entities/EntityCrane.cs b/ProjectHoistingCrane/ProjectHoistingCrane/Entities/EntityCrane.cs
new file mode 100644
index 0000000..151fdb1
--- /dev/null
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/Entities/EntityCrane.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectHoistingCrane.Entities;
+///
+/// Класс сущность Кран
+///
+public class EntityCrane
+{
+ ///
+ /// Скорость
+ ///
+ public int Speed { get; private set; }
+ ///
+ /// Вес
+ ///
+ public double Weight { get; private set; }
+ ///
+ /// Основной цвет
+ ///
+ public Color BodyColor { get; private set; }
+
+ ///
+ /// Шаг перемещения автомобиля
+ ///
+ public double Step => Speed * 100 / Weight;
+
+ /// КОнструктор сущности
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Основной цвет
+
+
+ public EntityCrane(int speed, double weight, Color bodyColor)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodyColor;
+ }
+}
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/EntityHoistingCrane.cs b/ProjectHoistingCrane/ProjectHoistingCrane/Entities/EntityHoistingCrane.cs
similarity index 52%
rename from ProjectHoistingCrane/ProjectHoistingCrane/EntityHoistingCrane.cs
rename to ProjectHoistingCrane/ProjectHoistingCrane/Entities/EntityHoistingCrane.cs
index 60d33be..b28d807 100644
--- a/ProjectHoistingCrane/ProjectHoistingCrane/EntityHoistingCrane.cs
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/Entities/EntityHoistingCrane.cs
@@ -1,25 +1,8 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using ProjectHoistingCrane.Drawnings;
+namespace ProjectHoistingCrane.Entities;
-namespace ProjectHoistingCrane;
-
-public class EntityHoistingCrane
+public class EntityHoistingCrane : EntityCrane
{
- ///
- /// Скорость
- ///
- public int Speed { get; private set; }
- ///
- /// Вес
- ///
- public double Weight { get; private set; }
- ///
- /// Основной цвет
- ///
- public Color BodyColor { get; private set; }
///
/// Дополнительный цвет (для опциональных элементов)
///
@@ -32,12 +15,9 @@ public class EntityHoistingCrane
/// Признак (опция) наличия крана
///
public bool Crane { get; private set; }
+
///
- /// Шаг перемещения автомобиля
- ///
- public double Step => Speed * 100 / Weight;
- ///
- /// Инициализация полей объекта-класса спортивного автомобиля
+ /// Конструктор
///
/// Скорость
/// Вес автомобиля
@@ -45,11 +25,8 @@ public class EntityHoistingCrane
/// Дополнительный цвет
/// Признак наличия обвеса
/// Признак наличия крана
- public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool counterweight, bool crane)
+ public EntityHoistingCrane(int speed, double weight, Color bodyColor, Color additionalColor, bool counterweight, bool crane):base(speed, weight, bodyColor)
{
- Speed = speed;
- Weight = weight;
- BodyColor = bodyColor;
AdditionalColor = additionalColor;
Сounterweight = counterweight;
Crane = crane;
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/Form1.cs b/ProjectHoistingCrane/ProjectHoistingCrane/Form1.cs
deleted file mode 100644
index 3ca129a..0000000
--- a/ProjectHoistingCrane/ProjectHoistingCrane/Form1.cs
+++ /dev/null
@@ -1,94 +0,0 @@
-namespace ProjectHoistingCrane
-{
- public partial class Form1 : Form
- {
- ///
- /// -
- ///
- private DrawningHoistingCrane? _drawningHoistingCrane;
- ///
- ///
- ///
- public Form1()
- {
- InitializeComponent();
- }
-
-
- ///
- ///
- ///
- private void Draw()
- {
- if (_drawningHoistingCrane == null)
- {
- return;
- }
- Bitmap bmp = new(pictureBoxHoistingCrane.Width,
- pictureBoxHoistingCrane.Height);
- Graphics gr = Graphics.FromImage(bmp);
- _drawningHoistingCrane.DrawTransport(gr);
- pictureBoxHoistingCrane.Image = bmp;
- }
-
-
-
- ///
- /// ""
- ///
- ///
- ///
- private void buttonCreate_Click(object sender, EventArgs e)
- {
- Random random = new();
- _drawningHoistingCrane = new DrawningHoistingCrane();
- _drawningHoistingCrane.Init(random.Next(100, 300), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
- _drawningHoistingCrane.SetPictureSize(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
- _drawningHoistingCrane.SetPosition(random.Next(10, 100), random.Next(10, 100));
- //_drawningHoistingCrane.SetPosition(random.Next(pictureBoxHoistingCrane.Width - 210, pictureBoxHoistingCrane.Width - 66), random.Next(10, 100));
- Draw();
- }
-
- ///
- /// ( )
- ///
- ///
- ///
- private void buttonMove_Click(object sender, EventArgs e)
- {
- if (_drawningHoistingCrane == null)
- {
- return;
- }
- string name = ((Button)sender)?.Name ?? string.Empty;
- bool result = false;
- switch (name)
- {
- case "buttonUp":
- result =
- _drawningHoistingCrane.MoveTransport(DirectionType.Up);
- break;
- case "buttonDown":
- result =
- _drawningHoistingCrane.MoveTransport(DirectionType.Down);
- break;
- case "buttonLeft":
- result =
- _drawningHoistingCrane.MoveTransport(DirectionType.Left);
- break;
- case "buttonRight":
- result =
- _drawningHoistingCrane.MoveTransport(DirectionType.Right);
- break;
- }
- if (result)
- {
- Draw();
- }
- }
- }
-}
-
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/Form1.Designer.cs b/ProjectHoistingCrane/ProjectHoistingCrane/FormHoistingCrane.Designer.cs
similarity index 66%
rename from ProjectHoistingCrane/ProjectHoistingCrane/Form1.Designer.cs
rename to ProjectHoistingCrane/ProjectHoistingCrane/FormHoistingCrane.Designer.cs
index f64d119..c077d90 100644
--- a/ProjectHoistingCrane/ProjectHoistingCrane/Form1.Designer.cs
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/FormHoistingCrane.Designer.cs
@@ -1,6 +1,6 @@
namespace ProjectHoistingCrane
{
- partial class Form1
+ partial class FormHoistingCrane
{
///
/// Required designer variable.
@@ -30,11 +30,14 @@
{
pictureBox1 = new PictureBox();
pictureBoxHoistingCrane = new PictureBox();
- buttonCreate = new Button();
+ buttonCreateHoistingCrane = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonRight = new Button();
buttonDown = new Button();
+ buttonCreateCrane = new Button();
+ comboBoxStrategy = new ComboBox();
+ StepButton = new Button();
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
((System.ComponentModel.ISupportInitialize)pictureBoxHoistingCrane).BeginInit();
SuspendLayout();
@@ -59,16 +62,16 @@
pictureBoxHoistingCrane.TabIndex = 1;
pictureBoxHoistingCrane.TabStop = false;
//
- // buttonCreate
+ // buttonCreateHoistingCrane
//
- buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreate.Location = new Point(24, 402);
- buttonCreate.Name = "buttonCreate";
- buttonCreate.Size = new Size(94, 29);
- buttonCreate.TabIndex = 2;
- buttonCreate.Text = "Создать";
- buttonCreate.UseVisualStyleBackColor = true;
- buttonCreate.Click += buttonCreate_Click;
+ buttonCreateHoistingCrane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreateHoistingCrane.Location = new Point(24, 402);
+ buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane";
+ buttonCreateHoistingCrane.Size = new Size(210, 29);
+ buttonCreateHoistingCrane.TabIndex = 2;
+ buttonCreateHoistingCrane.Text = "Создать подъёмный кран";
+ buttonCreateHoistingCrane.UseVisualStyleBackColor = true;
+ buttonCreateHoistingCrane.Click += buttonCreateHoistingCrane_Click;
//
// buttonLeft
//
@@ -118,22 +121,55 @@
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += buttonMove_Click;
//
- // Form1
+ // buttonCreateCrane
+ //
+ buttonCreateCrane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreateCrane.Location = new Point(240, 401);
+ buttonCreateCrane.Name = "buttonCreateCrane";
+ buttonCreateCrane.Size = new Size(210, 29);
+ buttonCreateCrane.TabIndex = 7;
+ buttonCreateCrane.Text = "Создать кран";
+ buttonCreateCrane.UseVisualStyleBackColor = true;
+ buttonCreateCrane.Click += buttonCreateCrane_Click;
+ //
+ // comboBoxStrategy
+ //
+ comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxStrategy.FormattingEnabled = true;
+ comboBoxStrategy.Items.AddRange(new object[] { "Стратегия движения к центру", "Стратегия движения в угол" });
+ comboBoxStrategy.Location = new Point(413, 12);
+ comboBoxStrategy.Name = "comboBoxStrategy";
+ comboBoxStrategy.Size = new Size(257, 28);
+ comboBoxStrategy.TabIndex = 8;
+ //
+ // StepButton
+ //
+ StepButton.Location = new Point(576, 46);
+ StepButton.Name = "StepButton";
+ StepButton.Size = new Size(94, 35);
+ StepButton.TabIndex = 10;
+ StepButton.Text = "Шаг";
+ StepButton.UseVisualStyleBackColor = true;
+ StepButton.Click += ButtonStrategyStep_Click;
+ //
+ // FormHoistingCrane
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(682, 453);
+ Controls.Add(StepButton);
+ Controls.Add(comboBoxStrategy);
+ Controls.Add(buttonCreateCrane);
Controls.Add(buttonDown);
Controls.Add(buttonRight);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
- Controls.Add(buttonCreate);
+ Controls.Add(buttonCreateHoistingCrane);
Controls.Add(pictureBoxHoistingCrane);
Controls.Add(pictureBox1);
- Name = "Form1";
+ Name = "FormHoistingCrane";
StartPosition = FormStartPosition.CenterScreen;
Text = "Form1";
-
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
((System.ComponentModel.ISupportInitialize)pictureBoxHoistingCrane).EndInit();
ResumeLayout(false);
@@ -144,10 +180,13 @@
private PictureBox pictureBox1;
private PictureBox pictureBoxHoistingCrane;
- private Button buttonCreate;
+ private Button buttonCreateHoistingCrane;
private Button buttonLeft;
private Button buttonUp;
private Button buttonRight;
private Button buttonDown;
+ private Button buttonCreateCrane;
+ private ComboBox comboBoxStrategy;
+ private Button StepButton;
}
}
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/FormHoistingCrane.cs b/ProjectHoistingCrane/ProjectHoistingCrane/FormHoistingCrane.cs
new file mode 100644
index 0000000..aef34a2
--- /dev/null
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/FormHoistingCrane.cs
@@ -0,0 +1,170 @@
+using ProjectHoistingCrane.Drawnings;
+using ProjectHoistingCrane.MovementStrategy;
+namespace ProjectHoistingCrane;
+
+public partial class FormHoistingCrane : Form
+{
+ ///
+ /// -
+ ///
+ private DrawningCrane? _drawningCrane;
+ ///
+ ///
+ ///
+
+ ///
+ ///
+ ///
+ private AbstractStrategy? _strategy;
+
+ ///
+ ///
+ ///
+ public FormHoistingCrane()
+ {
+ InitializeComponent();
+ _strategy = null;
+ }
+
+
+ ///
+ ///
+ ///
+ private void Draw()
+ {
+ if (_drawningCrane == null)
+ {
+ return;
+ }
+ Bitmap bmp = new(pictureBoxHoistingCrane.Width,
+ pictureBoxHoistingCrane.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _drawningCrane.DrawTransport(gr);
+ pictureBoxHoistingCrane.Image = bmp;
+ }
+
+ ///
+ /// -
+ ///
+ ///
+ private void CreateObject(string type)
+ {
+ Random random = new();
+ switch (type)
+ {
+ case nameof(DrawningCrane):
+ _drawningCrane = new DrawningCrane(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
+ break;
+ case nameof(DrawningHoistingCrane):
+ _drawningCrane = new DrawningHoistingCrane(random.Next(100, 300), random.Next(1000, 3000),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ break;
+ default:
+ return;
+ }
+ _drawningCrane.SetPictureSize(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
+ _drawningCrane.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ _strategy = null;
+ comboBoxStrategy.Enabled = true;
+ Draw();
+ }
+
+ ///
+ /// " "
+ ///
+ ///
+ ///
+ private void buttonCreateHoistingCrane_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningHoistingCrane));
+ }
+
+ ///
+ /// " "
+ ///
+ ///
+ ///
+ private void buttonCreateCrane_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningCrane));
+ }
+
+ ///
+ /// ( )
+ ///
+ ///
+ ///
+ private void buttonMove_Click(object sender, EventArgs e)
+ {
+ if (_drawningCrane == null)
+ {
+ return;
+ }
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ bool result = false;
+ switch (name)
+ {
+ case "buttonUp":
+ result =
+ _drawningCrane.MoveTransport(DirectionType.Up);
+ break;
+ case "buttonDown":
+ result =
+ _drawningCrane.MoveTransport(DirectionType.Down);
+ break;
+ case "buttonLeft":
+ result =
+ _drawningCrane.MoveTransport(DirectionType.Left);
+ break;
+ case "buttonRight":
+ result =
+ _drawningCrane.MoveTransport(DirectionType.Right);
+ break;
+ }
+ if (result)
+ {
+ Draw();
+ }
+ }
+
+ private void ButtonStrategyStep_Click(object sender, EventArgs e)
+ {
+ if (_drawningCrane == null)
+ {
+ return;
+ }
+
+ if (comboBoxStrategy.Enabled)
+ {
+ _strategy = comboBoxStrategy.SelectedIndex switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
+ if (_strategy == null)
+ {
+ return;
+ }
+ _strategy.SetData(new MoveableCrane(_drawningCrane), pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
+ }
+
+ if (_strategy == null)
+ {
+ return;
+ }
+
+ comboBoxStrategy.Enabled = false;
+ _strategy.MakeStep();
+ Draw();
+
+ if (_strategy.GetStatus() == StrategyStatus.Finish)
+ {
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ }
+ }
+}
+
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/Form1.resx b/ProjectHoistingCrane/ProjectHoistingCrane/FormHoistingCrane.resx
similarity index 100%
rename from ProjectHoistingCrane/ProjectHoistingCrane/Form1.resx
rename to ProjectHoistingCrane/ProjectHoistingCrane/FormHoistingCrane.resx
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/AbstractStrategy.cs b/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/AbstractStrategy.cs
new file mode 100644
index 0000000..c9990fd
--- /dev/null
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/AbstractStrategy.cs
@@ -0,0 +1,124 @@
+namespace ProjectHoistingCrane.MovementStrategy;
+
+public abstract class AbstractStrategy
+{
+ ///
+ /// Перемещаемый объект
+ ///
+ private IMoveableObject? _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(IMoveableObject 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 (IsTargetDestinaion())
+ {
+ _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 IsTargetDestinaion();
+
+ ///
+ /// Попытка перемещения в требуемом направлении
+ ///
+ /// Направление
+ /// Результат попытки (true - удалось переместиться, false - неудача)
+ private bool MoveTo(MovementDirection movementDirection)
+ {
+ if (_state != StrategyStatus.InProgress)
+ {
+ return false;
+ }
+ return _moveableObject?.TryMoveObject(movementDirection) ?? false;
+ }
+}
+
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/IMoveableObject.cs b/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/IMoveableObject.cs
new file mode 100644
index 0000000..e545923
--- /dev/null
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/IMoveableObject.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectHoistingCrane.MovementStrategy;
+
+public interface IMoveableObject
+{
+ ///
+ /// Получение координаты объекта
+ ///
+ ObjectParameters? GetObjectPosition { get; }
+ ///
+ /// Шаг объекта
+ ///
+ int GetStep { get; }
+ ///
+ /// Попытка переместить объект в указанном направлении
+ ///
+ /// Направление
+ /// true - объект перемещен, false - перемещение невозможно
+ bool TryMoveObject(MovementDirection direction);
+}
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/MoveToBorder.cs b/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/MoveToBorder.cs
new file mode 100644
index 0000000..aa3b8c1
--- /dev/null
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/MoveToBorder.cs
@@ -0,0 +1,34 @@
+namespace ProjectHoistingCrane.MovementStrategy;
+
+public class MoveToBorder : AbstractStrategy
+{
+ protected override bool IsTargetDestinaion()
+ {
+ 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())
+ {
+ MoveRight();
+ }
+
+ int diffY = objParams.DownBorder - FieldHeight;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ MoveDown();
+ }
+ }
+}
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/MoveToCenter.cs b/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/MoveToCenter.cs
new file mode 100644
index 0000000..13fe962
--- /dev/null
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/MoveToCenter.cs
@@ -0,0 +1,52 @@
+namespace ProjectHoistingCrane.MovementStrategy;
+
+///
+/// Стратегия перемещения объекта к центру экрана
+///
+public class MoveToCenter : AbstractStrategy
+{
+ protected override bool IsTargetDestinaion()
+ {
+ 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/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/MoveableCrane.cs b/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/MoveableCrane.cs
new file mode 100644
index 0000000..51036ce
--- /dev/null
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/MoveableCrane.cs
@@ -0,0 +1,62 @@
+using ProjectHoistingCrane.Drawnings;
+namespace ProjectHoistingCrane.MovementStrategy;
+
+///
+///Класс-реализация IMoveableObject с использованием DrawningCrane
+///
+public class MoveableCrane : IMoveableObject
+{
+ ///
+ /// Поле-объект класса DrawningCrane или его наследника
+ ///
+ private readonly DrawningCrane? _crane = null;
+
+
+ ///
+ /// Конструктор
+ ///
+ /// Объект класса DrawningCrane
+ public MoveableCrane(DrawningCrane crane)
+ {
+ _crane = crane;
+ }
+ public ObjectParameters? GetObjectPosition
+ {
+ get
+ {
+ if (_crane == null || _crane.EntityCrane == null || !_crane.GetPosX.HasValue || !_crane.GetPosY.HasValue)
+ {
+ return null;
+ }
+ return new ObjectParameters(_crane.GetPosX.Value, _crane.GetPosY.Value, _crane.GetWidth, _crane.GetHeight);
+ }
+ }
+
+ public int GetStep => (int)(_crane?.EntityCrane?.Step ?? 0);
+
+ public bool TryMoveObject(MovementDirection direction)
+ {
+ if (_crane == null || _crane.EntityCrane == null)
+ {
+ return false;
+ }
+ return _crane.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/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/MovementDirection.cs b/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/MovementDirection.cs
new file mode 100644
index 0000000..e4aa526
--- /dev/null
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/MovementDirection.cs
@@ -0,0 +1,21 @@
+namespace ProjectHoistingCrane.MovementStrategy;
+
+public enum MovementDirection
+{
+ ///
+ /// Вверх
+ ///
+ Up = 1,
+ ///
+ /// Вниз
+ ///
+ Down = 2,
+ ///
+ /// Влево
+ ///
+ Left = 3,
+ ///
+ /// Вправо
+ ///
+ Right = 4
+}
\ No newline at end of file
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/ObjectParameters.cs b/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/ObjectParameters.cs
new file mode 100644
index 0000000..15d4baa
--- /dev/null
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/ObjectParameters.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectHoistingCrane.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/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/StrategyStatus.cs b/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/StrategyStatus.cs
new file mode 100644
index 0000000..36b620a
--- /dev/null
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/MovementStrategy/StrategyStatus.cs
@@ -0,0 +1,17 @@
+namespace ProjectHoistingCrane.MovementStrategy;
+
+public enum StrategyStatus
+{
+ ///
+ /// Все готово к началу
+ ///
+ NotInit,
+ ///
+ /// Выполняется
+ ///
+ InProgress,
+ ///
+ /// Завершено
+ ///
+ Finish
+}
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/Program.cs b/ProjectHoistingCrane/ProjectHoistingCrane/Program.cs
index 5c793c1..5d92f2a 100644
--- a/ProjectHoistingCrane/ProjectHoistingCrane/Program.cs
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/Program.cs
@@ -11,7 +11,7 @@ namespace ProjectHoistingCrane
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new Form1());
+ Application.Run(new FormHoistingCrane());
}
}
}
\ No newline at end of file