diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DirectionType.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DirectionType.cs
index 2bcd53a..805eb17 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DirectionType.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DirectionType.cs
@@ -4,6 +4,11 @@
///
public enum DirectionType
{
+ ///
+ /// Неизвестное направление
+ ///
+ Unknow = -1,
+
///
/// Вверх
///
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningPropelledArtillery.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningPropelledArtillery.cs
index 4bebc30..dba4d5b 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningPropelledArtillery.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningPropelledArtillery.cs
@@ -44,6 +44,26 @@ public class DrawningPropelledArtillery
///
private readonly int _drawningPropelledArtilleryHeight = 105;
+ ///
+ /// Координата X объекта
+ ///
+ public int? GetPosX => _startPosX;
+
+ ///
+ /// Координата Y объекта
+ ///
+ public int? GetPosY => _startPosY;
+
+ ///
+ /// Ширина объекта
+ ///
+ public int GetWidth => _drawningPropelledArtilleryWidth;
+
+ ///
+ /// Высота объекта
+ ///
+ public int GetHeight => _drawningPropelledArtilleryHeight;
+
///
/// Пустой конструктор
///
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.Designer.cs
deleted file mode 100644
index 5ad432a..0000000
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.Designer.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-namespace SelfPropelledArtilleryUnit
-{
- partial class FormSelfPropelledArtilleryUnit
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
- SuspendLayout();
- //
- // FormSelfPropelledArtilleryUnit
- //
- AutoScaleDimensions = new SizeF(7F, 15F);
- AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(877, 442);
- Name = "FormSelfPropelledArtilleryUnit";
- Text = "FormSelfPropelledArtilleryUnit";
- ResumeLayout(false);
- }
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.cs
deleted file mode 100644
index 299f56c..0000000
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace SelfPropelledArtilleryUnit
-{
- public partial class FormSelfPropelledArtilleryUnit : Form
- {
- public FormSelfPropelledArtilleryUnit()
- {
- InitializeComponent();
- }
- }
-}
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.resx b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.resx
deleted file mode 100644
index af32865..0000000
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.resx
+++ /dev/null
@@ -1,120 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/AbstractStrategy.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/AbstractStrategy.cs
new file mode 100644
index 0000000..794ba0a
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/AbstractStrategy.cs
@@ -0,0 +1,139 @@
+namespace SelfPropelledArtilleryUnit.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/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/IMoveableObject.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/IMoveableObject.cs
new file mode 100644
index 0000000..5da7a46
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/IMoveableObject.cs
@@ -0,0 +1,24 @@
+namespace SelfPropelledArtilleryUnit.MovementStrategy;
+
+///
+/// Интерфейс для работы с перемещаемым объектом
+///
+public interface IMoveableObject
+{
+ ///
+ /// Получение координаты объекта
+ ///
+ ObjectParameters? GetObjectPosition { get; }
+
+ ///
+ /// Шаг объекта
+ ///
+ int GetStep { get; }
+
+ ///
+ /// Попытка переместить объект в указанном направлении
+ ///
+ /// Направление
+ /// true - объект перемещен, false - перемещение невозможно
+ bool TryMoveObject(MovementDirection direction);
+}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveToBorder.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveToBorder.cs
new file mode 100644
index 0000000..e48881e
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveToBorder.cs
@@ -0,0 +1,31 @@
+namespace SelfPropelledArtilleryUnit.MovementStrategy;
+
+public class MoveToBorder : AbstractStrategy
+{
+ protected override bool IsTargetDestinaion()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return false;
+ }
+ return objParams.LeftBorder - GetStep() <= 0 ||
+ objParams.RightBorder + GetStep() >= FieldWidth ||
+ objParams.TopBorder - GetStep() <= 0
+ || objParams.ObjectMiddleVertical + GetStep() >= FieldHeight;
+ }
+
+ protected override void MoveToTarget()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return;
+ }
+ //реализация в правый нижний угол
+ int x = objParams.RightBorder;
+ if (x + GetStep() < FieldWidth) MoveRight();
+ int y = objParams.DownBorder;
+ if (y + GetStep() < FieldHeight) MoveDown();
+ }
+}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveToCenter.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveToCenter.cs
new file mode 100644
index 0000000..45214d3
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveToCenter.cs
@@ -0,0 +1,53 @@
+namespace SelfPropelledArtilleryUnit.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();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveablePropelledArtillery.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveablePropelledArtillery.cs
new file mode 100644
index 0000000..9208f1b
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveablePropelledArtillery.cs
@@ -0,0 +1,63 @@
+using SelfPropelledArtilleryUnit.Drawnings;
+
+namespace SelfPropelledArtilleryUnit.MovementStrategy;
+///
+/// Класс-реализация IMoveableObject с использованием DrawningPropelledArtillery
+///
+public class MoveablePropelledArtillery : IMoveableObject
+{
+ ///
+ /// Поле-объект класса DrawningPropelledArtillery или его наследника
+ ///
+ private readonly DrawningPropelledArtillery? _PropelledArtillery = null;
+
+ ///
+ /// Конструктор
+ ///
+ /// Объект класса DrawningPropelledArtillery
+ public MoveablePropelledArtillery(DrawningPropelledArtillery PropelledArtillery)
+ {
+ _PropelledArtillery = PropelledArtillery;
+ }
+
+ public ObjectParameters? GetObjectPosition
+ {
+ get
+ {
+ if (_PropelledArtillery == null || _PropelledArtillery.EntityPropelledArtillery == null || !_PropelledArtillery.GetPosX.HasValue || !_PropelledArtillery.GetPosY.HasValue)
+ {
+ return null;
+ }
+ return new ObjectParameters(_PropelledArtillery.GetPosX.Value, _PropelledArtillery.GetPosY.Value, _PropelledArtillery.GetWidth, _PropelledArtillery.GetHeight);
+ }
+ }
+
+ public int GetStep => (int)(_PropelledArtillery?.EntityPropelledArtillery?.Step ?? 0);
+
+ public bool TryMoveObject(MovementDirection direction)
+ {
+ if (_PropelledArtillery == null || _PropelledArtillery.EntityPropelledArtillery == null)
+ {
+ return false;
+ }
+
+ return _PropelledArtillery.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,
+ };
+ }
+}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MovementDirection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MovementDirection.cs
new file mode 100644
index 0000000..2dae8cc
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MovementDirection.cs
@@ -0,0 +1,26 @@
+namespace SelfPropelledArtilleryUnit.MovementStrategy;
+///
+/// Направление перемещения
+///
+public enum MovementDirection
+{
+ ///
+ /// Вверх
+ ///
+ Up = 1,
+
+ ///
+ /// Вниз
+ ///
+ Down = 2,
+
+ ///
+ /// Влево
+ ///
+ Left = 3,
+
+ ///
+ /// Вправо
+ ///
+ Right = 4
+}
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/ObjectParameters.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/ObjectParameters.cs
new file mode 100644
index 0000000..d7cdaba
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/ObjectParameters.cs
@@ -0,0 +1,69 @@
+namespace SelfPropelledArtilleryUnit.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;
+ }
+}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/StrategyStatus.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/StrategyStatus.cs
new file mode 100644
index 0000000..6315c8d
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/StrategyStatus.cs
@@ -0,0 +1,21 @@
+namespace SelfPropelledArtilleryUnit.MovementStrategy;
+///
+/// Статус выполнения операции перемещения
+///
+public enum StrategyStatus
+{
+ ///
+ /// Все готово к началу
+ ///
+ NotInit,
+
+ ///
+ /// Выполняется
+ ///
+ InProgress,
+
+ ///
+ /// Завершено
+ ///
+ Finish
+}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.Designer.cs
index d54b38f..10f2ab7 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.Designer.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.Designer.cs
@@ -35,6 +35,8 @@
buttonDown = new Button();
buttonRight = new Button();
button1 = new Button();
+ comboBoxStrategy = new ComboBox();
+ buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxSelfPropelledArtilleryUnit).BeginInit();
SuspendLayout();
//
@@ -117,11 +119,34 @@
button1.UseVisualStyleBackColor = true;
button1.Click += buttonCreatePropelledArtillery_Click;
//
+ // comboBoxStrategy
+ //
+ comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxStrategy.FormattingEnabled = true;
+ comboBoxStrategy.Items.AddRange(new object[] { "К центру ", "К краю" });
+ comboBoxStrategy.Location = new Point(784, 12);
+ comboBoxStrategy.Name = "comboBoxStrategy";
+ comboBoxStrategy.Size = new Size(121, 23);
+ comboBoxStrategy.TabIndex = 7;
+ comboBoxStrategy.SelectedIndexChanged += comboBoxStrategy_SelectedIndexChanged;
+ //
+ // buttonStrategyStep
+ //
+ buttonStrategyStep.Location = new Point(829, 41);
+ buttonStrategyStep.Name = "buttonStrategyStep";
+ buttonStrategyStep.Size = new Size(75, 23);
+ buttonStrategyStep.TabIndex = 8;
+ buttonStrategyStep.Text = "Шаг";
+ buttonStrategyStep.UseVisualStyleBackColor = true;
+ buttonStrategyStep.Click += buttonStrategyStep_Click;
+ //
// SelfPropelledArtilleryUnit
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(923, 493);
+ Controls.Add(buttonStrategyStep);
+ Controls.Add(comboBoxStrategy);
Controls.Add(button1);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
@@ -144,5 +169,7 @@
private Button buttonDown;
private Button buttonRight;
private Button button1;
+ private ComboBox comboBoxStrategy;
+ private Button buttonStrategyStep;
}
}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.cs
index e2ff54f..e6cbfc4 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.cs
@@ -8,6 +8,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SelfPropelledArtilleryUnit.Drawnings;
+using SelfPropelledArtilleryUnit.MovementStrategy;
namespace SelfPropelledArtilleryUnit
{
@@ -15,10 +16,20 @@ namespace SelfPropelledArtilleryUnit
{
private DrawningPropelledArtillery? _drawningPropelledArtillery;
+ ///
+ /// Стратегия перемещения
+ ///
+ private AbstractStrategy? _strategy;
+
+ ///
+ /// Конструктор формы
+ ///
public SelfPropelledArtilleryUnit()
{
InitializeComponent();
+ _strategy = null;
}
+
private void Draw()
{
if (_drawningPropelledArtillery == null)
@@ -52,6 +63,8 @@ namespace SelfPropelledArtilleryUnit
_drawningPropelledArtillery.SetPictureSize(pictureBoxSelfPropelledArtilleryUnit.Width, pictureBoxSelfPropelledArtilleryUnit.Height);
_drawningPropelledArtillery.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ _strategy = null;
+ comboBoxStrategy.Enabled = true;
Draw();
}
@@ -95,5 +108,53 @@ namespace SelfPropelledArtilleryUnit
Draw();
}
}
+
+ ///
+ /// Обработка нажатия кнопки "Шаг"
+ ///
+ ///
+ ///
+ private void buttonStrategyStep_Click(object sender, EventArgs e)
+ {
+ if (_drawningPropelledArtillery == null)
+ {
+ return;
+ }
+
+ if (comboBoxStrategy.Enabled)
+ {
+ _strategy = comboBoxStrategy.SelectedIndex switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
+ if (_strategy == null)
+ {
+ return;
+ }
+ _strategy.SetData(new MoveablePropelledArtillery(_drawningPropelledArtillery), pictureBoxSelfPropelledArtilleryUnit.Width, pictureBoxSelfPropelledArtilleryUnit.Height);
+ }
+
+ if (_strategy == null)
+ {
+ return;
+ }
+
+ comboBoxStrategy.Enabled = false;
+ _strategy.MakeStep();
+ Draw();
+
+ if (_strategy.GetStatus() == StrategyStatus.Finish)
+ {
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ }
+ }
+
+ private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
+ {
+
+ }
}
}