From a30f2a037c3fcf500745dc116b1875de73f83568 Mon Sep 17 00:00:00 2001 From: cyxarukk Date: Mon, 11 Mar 2024 13:16:46 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B2=20=D0=BB=D0=B0=D0=B1=D0=B5=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectCar/FormGasMachine.Designer.cs | 18 +++-- .../MovementStrategy/AbstractStrategy.cs | 69 ++++++++++++++++++ .../MovementStrategy/IMoveableObjects.cs | 24 +++++++ .../MovementStrategy/MovementDirection.cs | 21 ++++++ .../MovementStrategy/ObjectParameters.cs | 72 +++++++++++++++++++ .../MovementStrategy/StrategyStatus.cs | 22 ++++++ 6 files changed, 219 insertions(+), 7 deletions(-) create mode 100644 ProjectCar/ProjectCar/MovementStrategy/AbstractStrategy.cs create mode 100644 ProjectCar/ProjectCar/MovementStrategy/IMoveableObjects.cs create mode 100644 ProjectCar/ProjectCar/MovementStrategy/MovementDirection.cs create mode 100644 ProjectCar/ProjectCar/MovementStrategy/ObjectParameters.cs create mode 100644 ProjectCar/ProjectCar/MovementStrategy/StrategyStatus.cs diff --git a/ProjectCar/ProjectCar/FormGasMachine.Designer.cs b/ProjectCar/ProjectCar/FormGasMachine.Designer.cs index fb91bf8..c8bc445 100644 --- a/ProjectCar/ProjectCar/FormGasMachine.Designer.cs +++ b/ProjectCar/ProjectCar/FormGasMachine.Designer.cs @@ -1,4 +1,4 @@ -namespace ProjectCar +namespace ProjectGasMachine { partial class FormGasMachine { @@ -28,7 +28,7 @@ /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormGasMachine)); + //System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormGasMachine)); buttonCreate = new Button(); buttonLeft = new Button(); buttonRight = new Button(); @@ -53,7 +53,8 @@ // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage"); + //buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage"); + buttonLeft.BackgroundImage = Properties.Resources.free_icon_left_arrow_10696518; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; buttonLeft.Location = new Point(862, 481); buttonLeft.Name = "buttonLeft"; @@ -65,7 +66,8 @@ // buttonRight // buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage"); + //buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage"); + buttonRight.BackgroundImage = Properties.Resources.free_icon_left_arrow_10696518; buttonRight.BackgroundImageLayout = ImageLayout.Stretch; buttonRight.Location = new Point(944, 481); buttonRight.Name = "buttonRight"; @@ -77,7 +79,8 @@ // buttonUp // buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage"); + //buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage"); + buttonUp.BackgroundImage = Properties.Resources.free_icon_left_arrow_10696518; buttonUp.BackgroundImageLayout = ImageLayout.Stretch; buttonUp.Location = new Point(903, 440); buttonUp.Name = "buttonUp"; @@ -89,7 +92,8 @@ // buttonDown // buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage"); + //buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage"); + buttonDown.BackgroundImage = Properties.Resources.free_icon_left_arrow_10696518; buttonDown.BackgroundImageLayout = ImageLayout.Stretch; buttonDown.Location = new Point(903, 481); buttonDown.Name = "buttonDown"; @@ -117,7 +121,7 @@ buttonCreateMachine.TabIndex = 6; buttonCreateMachine.Text = "Создать орнамент на колесах"; buttonCreateMachine.UseVisualStyleBackColor = true; - buttonCreateMachine.Click += buttonCreateMachine_Click; + buttonCreateMachine.Click += ButtonCreateMachine_Click; // // FormGasMachine // diff --git a/ProjectCar/ProjectCar/MovementStrategy/AbstractStrategy.cs b/ProjectCar/ProjectCar/MovementStrategy/AbstractStrategy.cs new file mode 100644 index 0000000..073eae3 --- /dev/null +++ b/ProjectCar/ProjectCar/MovementStrategy/AbstractStrategy.cs @@ -0,0 +1,69 @@ +namespace ProjectGasMachine.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(); + } + + +} diff --git a/ProjectCar/ProjectCar/MovementStrategy/IMoveableObjects.cs b/ProjectCar/ProjectCar/MovementStrategy/IMoveableObjects.cs new file mode 100644 index 0000000..5f0599e --- /dev/null +++ b/ProjectCar/ProjectCar/MovementStrategy/IMoveableObjects.cs @@ -0,0 +1,24 @@ +namespace ProjectGasMachine.MovementStrategy; +/// +/// интерфейс для работы с перемещаемым объектом +/// +public interface IMoveableObjects +{ + /// + /// получение координаты объекта + /// + ObjectParameters? GetObjectPosition { get; } + + /// + /// шаг объекта + /// + int GetStep { get; } + + /// + /// попытка переместить объект в указанном направлении + /// + /// + /// true - объект перемещен, false - перемещение невозможно + bool TryMoveObject(MovementDirection direction); + +} diff --git a/ProjectCar/ProjectCar/MovementStrategy/MovementDirection.cs b/ProjectCar/ProjectCar/MovementStrategy/MovementDirection.cs new file mode 100644 index 0000000..ee99ae7 --- /dev/null +++ b/ProjectCar/ProjectCar/MovementStrategy/MovementDirection.cs @@ -0,0 +1,21 @@ +namespace ProjectGasMachine.MovementStrategy; + +public enum MovementDirection +{ + /// + /// Вверх + /// + Up = 1, + /// + /// Вниз + /// + Down = 2, + /// + /// Влево + /// + Left = 3, + /// + /// Вправо + /// + Right = 4 +} diff --git a/ProjectCar/ProjectCar/MovementStrategy/ObjectParameters.cs b/ProjectCar/ProjectCar/MovementStrategy/ObjectParameters.cs new file mode 100644 index 0000000..344bd99 --- /dev/null +++ b/ProjectCar/ProjectCar/MovementStrategy/ObjectParameters.cs @@ -0,0 +1,72 @@ +namespace ProjectGasMachine.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/ProjectCar/ProjectCar/MovementStrategy/StrategyStatus.cs b/ProjectCar/ProjectCar/MovementStrategy/StrategyStatus.cs new file mode 100644 index 0000000..5c2a13c --- /dev/null +++ b/ProjectCar/ProjectCar/MovementStrategy/StrategyStatus.cs @@ -0,0 +1,22 @@ +namespace ProjectGasMachine.MovementStrategy; + +/// +/// статус выполнения операции перемещения +/// +public enum StrategyStatus +{ + /// + /// все готово к началу + /// + NotInit, + + /// + /// выполняется + /// + InProgress, + + /// + /// завершено + /// + Finish +}