diff --git a/ProjectAirbus/ProjectAirbus/Drawnings/DirectionType.cs b/ProjectAirbus/ProjectAirbus/Drawnings/DirectionType.cs
new file mode 100644
index 0000000..dcb133f
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/Drawnings/DirectionType.cs
@@ -0,0 +1,29 @@
+namespace ProjectAirbus.Drawnings;
+
+public enum DirectionType
+{
+ ///
+ /// Неизвестное направление
+ ///
+ Unknow = -1,
+
+ ///
+ /// Вверх
+ ///
+ Up = 1,
+
+ ///
+ /// Вниз
+ ///
+ Down = 2,
+
+ ///
+ /// Влево
+ ///
+ Left = 3,
+
+ ///
+ /// Вправо
+ ///
+ Right = 4
+}
diff --git a/ProjectAirbus/ProjectAirbus/DrawningAirbus.cs b/ProjectAirbus/ProjectAirbus/Drawnings/DrawningAirbus.cs
similarity index 76%
rename from ProjectAirbus/ProjectAirbus/DrawningAirbus.cs
rename to ProjectAirbus/ProjectAirbus/Drawnings/DrawningAirbus.cs
index dde2026..a111595 100644
--- a/ProjectAirbus/ProjectAirbus/DrawningAirbus.cs
+++ b/ProjectAirbus/ProjectAirbus/Drawnings/DrawningAirbus.cs
@@ -1,16 +1,16 @@
-using System.Drawing;
+using ProjectAirbus.Entities;
-namespace ProjectAirbus;
+namespace ProjectAirbus.Drawnings;
///
-/// Класс отрисовки и перемещения объекта-сущности
+/// Класс отрисовки и перемещения базового объекта-сущности
///
public class DrawningAirbus
{
///
/// Класс-сущность
///
- public EntityAirbus? EntityAirbus { get; private set; }
+ public EntityAirbus? EntityAirbus { get; protected set; }
///
/// Ширина окна
@@ -25,38 +25,75 @@ public class DrawningAirbus
///
/// Начальная координата х
///
- private int? _startPosX;
+ protected int? _startPosX;
///
/// Начальная координата у
///
- private int? _startPosY;
+ protected int? _startPosY;
///
/// Ширина самолета
///
- public readonly int _drawningAirbusWidth = 145;
+ private readonly int _drawningAirbusWidth = 145;
///
/// Высота самолета
///
- public readonly int _drawningAirbusHeight = 50;
+ private readonly int _drawningAirbusHeight = 50;
///
- /// Инициализация свойств
+ /// Координата X объекта
+ ///
+ public int? GetPosX => _startPosX;
+
+ ///
+ /// Координата Y объекта
+ ///
+ public int? GetPosY => _startPosY;
+
+ ///
+ /// Ширина объекта
+ ///
+ public int GetWidth => _drawningAirbusWidth;
+
+ ///
+ /// Высотаы объекта
+ ///
+ public int GetHeight => _drawningAirbusHeight;
+
+ ///
+ /// Пустой конструктор
+ ///
+ private DrawningAirbus()
+ {
+ _pictureWidth = null;
+ _pictureHeight = null;
+ _startPosX = 0;
+ _startPosY = 0;
+ }
+
+ ///
+ /// Конструктор
///
/// Скорость
/// Вес
/// Основной цвет
/// Дополнительный цвет
- public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool additionalEngine, bool passengerCompartment)
+ public DrawningAirbus(int speed, double weight, Color bodyColor) : this()
{
- EntityAirbus = new EntityAirbus();
- EntityAirbus.Init(speed, weight, bodyColor, additionalColor, additionalEngine, passengerCompartment);
- _pictureWidth = null;
- _pictureHeight = null;
- _startPosX = null;
- _startPosY = null;
+ EntityAirbus = new EntityAirbus(speed, weight, bodyColor);
+ }
+
+ ///
+ /// Конструктор для наследников
+ ///
+ /// Ширина прорисовки аэробуса
+ /// Высота прорисовки аэробуса
+ protected DrawningAirbus(int drawningCarWidth, int drawningCarHeight) : this()
+ {
+ _drawningAirbusWidth = drawningCarWidth;
+ _pictureHeight = drawningCarHeight;
}
///
@@ -64,7 +101,7 @@ public class DrawningAirbus
///
/// Ширина поля
/// Высота поля
- ///
+ /// true - границы заданы, false - границы не заданы, проверка не пройдена
public bool SetPictureSize(int width, int height)
{
if (width > _drawningAirbusWidth && height > _drawningAirbusHeight)
@@ -119,7 +156,7 @@ public class DrawningAirbus
}
///
- /// Выбор направления перемещения
+ /// Изменение направления перемещения
///
/// Направлениие
/// true - перемещение возможно и выполнено, false - перемещение невозможно и не выполнено
@@ -165,16 +202,15 @@ public class DrawningAirbus
/// Отрисовка самолёта
///
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
- if (EntityAirbus == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ if (EntityAirbus == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Brush brushBodyColor = new SolidBrush(EntityAirbus.BodyColor);
- Brush brushAdditionalColor = new SolidBrush(EntityAirbus.AdditionalColor);
Brush brushBlack = new SolidBrush(Color.Black);
//границы самолёта
@@ -187,18 +223,6 @@ public class DrawningAirbus
g.DrawLine(pen, _startPosX.Value + 120, _startPosY.Value + 40, _startPosX.Value + 145, _startPosY.Value + 30);
g.DrawLine(pen, _startPosX.Value + 120, _startPosY.Value + 30, _startPosX.Value + 145, _startPosY.Value + 30);
- //дополнительный отсек для пассажиров
- if (EntityAirbus.PassengerCompartment)
- {
- g.DrawRectangle(pen, _startPosX.Value + 60, _startPosY.Value + 10, 40, 10);
- g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 10, 20, 20);
- g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 10, 20, 20);
-
- g.FillRectangle(brushAdditionalColor, _startPosX.Value + 60, _startPosY.Value + 11, 40, 10);
- g.FillEllipse(brushAdditionalColor, _startPosX.Value + 50, _startPosY.Value + 10, 20, 20);
- g.FillEllipse(brushAdditionalColor, _startPosX.Value + 90, _startPosY.Value + 10, 20, 20);
- }
-
//шасси
g.DrawLine(pen, _startPosX.Value + 40, _startPosY.Value + 40, _startPosX.Value + 40, _startPosY.Value + 44);
g.DrawEllipse(pen, _startPosX.Value + 34, _startPosY.Value + 44, 6, 6);
@@ -216,14 +240,6 @@ public class DrawningAirbus
g.FillEllipse(brushBlack, _startPosX.Value + 12, _startPosY.Value + 15, 8, 8);
g.FillRectangle(brushBlack, _startPosX.Value + 4, _startPosY.Value + 15, 12, 8);
- //дополнительный двигатель на крыле
- if (EntityAirbus.AdditionalEngine)
- {
- g.FillEllipse(brushAdditionalColor, _startPosX.Value + 48, _startPosY.Value + 30, 8, 8);
- g.FillEllipse(brushAdditionalColor, _startPosX.Value + 60, _startPosY.Value + 30, 8, 8);
- g.FillRectangle(brushAdditionalColor, _startPosX.Value + 52, _startPosY.Value + 30, 12, 8);
- }
-
//крыло
g.FillRectangle(brushBlack, _startPosX.Value + 40, _startPosY.Value + 28, 40, 4);
g.FillEllipse(brushBlack, _startPosX.Value + 38, _startPosY.Value + 28, 4, 4);
diff --git a/ProjectAirbus/ProjectAirbus/Drawnings/DrawningBigAirbus.cs b/ProjectAirbus/ProjectAirbus/Drawnings/DrawningBigAirbus.cs
new file mode 100644
index 0000000..18a5182
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/Drawnings/DrawningBigAirbus.cs
@@ -0,0 +1,46 @@
+using ProjectAirbus.Entities;
+
+namespace ProjectAirbus.Drawnings;
+
+public class DrawningBigAirbus : DrawningAirbus
+{
+ public DrawningBigAirbus(int speed, double weight, Color bodyColor, Color additionalColor, bool additionalEngine, bool passengerCompartment) : base(145, 50)
+ {
+ EntityAirbus = new EntityBigAirbus(speed, weight, bodyColor, additionalColor, additionalEngine, passengerCompartment);
+ }
+
+ public override void DrawTransport(Graphics g)
+ {
+ if (EntityAirbus == null || EntityAirbus is not EntityBigAirbus bigAirbus || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush brushBodyColor = new SolidBrush(EntityAirbus.BodyColor);
+ Brush brushAdditionalColor = new SolidBrush(bigAirbus.AdditionalColor);
+ Brush brushBlack = new SolidBrush(Color.Black);
+
+ //дополнительный отсек для пассажиров
+ if (bigAirbus.PassengerCompartment)
+ {
+ g.DrawRectangle(pen, _startPosX.Value + 60, _startPosY.Value + 10, 40, 10);
+ g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 10, 20, 20);
+ g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 10, 20, 20);
+
+ g.FillRectangle(brushAdditionalColor, _startPosX.Value + 60, _startPosY.Value + 11, 40, 10);
+ g.FillEllipse(brushAdditionalColor, _startPosX.Value + 50, _startPosY.Value + 10, 20, 20);
+ g.FillEllipse(brushAdditionalColor, _startPosX.Value + 90, _startPosY.Value + 10, 20, 20);
+ }
+
+ base.DrawTransport(g);
+
+ //дополнительный двигатель на крыле
+ if (bigAirbus.AdditionalEngine)
+ {
+ g.FillEllipse(brushAdditionalColor, _startPosX.Value + 48, _startPosY.Value + 30, 8, 8);
+ g.FillEllipse(brushAdditionalColor, _startPosX.Value + 60, _startPosY.Value + 30, 8, 8);
+ g.FillRectangle(brushAdditionalColor, _startPosX.Value + 52, _startPosY.Value + 30, 12, 8);
+ }
+ }
+}
diff --git a/ProjectAirbus/ProjectAirbus/Entities/EntityAirbus.cs b/ProjectAirbus/ProjectAirbus/Entities/EntityAirbus.cs
new file mode 100644
index 0000000..772903c
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/Entities/EntityAirbus.cs
@@ -0,0 +1,40 @@
+namespace ProjectAirbus.Entities;
+
+///
+/// Класс-сущность "Аэробус"
+///
+public class EntityAirbus
+{
+ ///
+ /// Скорость
+ ///
+ 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 EntityAirbus(int speed, double weight, Color bodyColor)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodyColor;
+ }
+}
diff --git a/ProjectAirbus/ProjectAirbus/Entities/EntityBIgAirbus.cs b/ProjectAirbus/ProjectAirbus/Entities/EntityBIgAirbus.cs
new file mode 100644
index 0000000..7ca39fa
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/Entities/EntityBIgAirbus.cs
@@ -0,0 +1,26 @@
+namespace ProjectAirbus.Entities;
+
+public class EntityBigAirbus : EntityAirbus
+{
+ ///
+ /// Дополнительный цвет
+ ///
+ public Color AdditionalColor { get; private set; }
+
+ ///
+ /// Опция наличия дополнительного двигателя
+ ///
+ public bool AdditionalEngine { get; private set; }
+
+ ///
+ /// Опция наличия дополнительного отсека для пассажиров
+ ///
+ public bool PassengerCompartment { get; private set; }
+
+ public EntityBigAirbus(int speed, double weight, Color bodyColor, Color additionalColor, bool additionalEngine, bool passengerCompartment) : base(0, 0, Color.Black)
+ {
+ AdditionalColor = additionalColor;
+ AdditionalEngine = additionalEngine;
+ PassengerCompartment = passengerCompartment;
+ }
+}
diff --git a/ProjectAirbus/ProjectAirbus/EntityAirbus.cs b/ProjectAirbus/ProjectAirbus/EntityAirbus.cs
deleted file mode 100644
index 3296488..0000000
--- a/ProjectAirbus/ProjectAirbus/EntityAirbus.cs
+++ /dev/null
@@ -1,62 +0,0 @@
-namespace ProjectAirbus;
-
-///
-/// Класс-сущность "Аэробус"
-///
-public class EntityAirbus
-{
- ///
- /// Скорость
- ///
- 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 AdditionalEngine { get; private set; }
-
- ///
- /// Опция наличия дополнительного отсека для пассажиров
- ///
- public bool PassengerCompartment { get; private set; }
-
- ///
- /// Шаг перемещения автомобиля
- ///
- public double Step => Speed * 100 / Weight;
-
- ///
- /// Инициализация полей объекта-класса аэробуса
- ///
- /// Скорость
- /// Вес
- /// Основной цвет
- /// Дополнительный цвет
- /// Опция наличия дополнительного двигателя
- /// Опция наличия дополнительного отсека для пассажиров
- public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool additionalEngine,
- bool passengerCompartment)
- {
- Speed = speed;
- Weight = weight;
- BodyColor = bodyColor;
- AdditionalColor = additionalColor;
- AdditionalEngine = additionalEngine;
- PassengerCompartment = passengerCompartment;
- }
-}
diff --git a/ProjectAirbus/ProjectAirbus/FormAirbus.Designer.cs b/ProjectAirbus/ProjectAirbus/FormAirbus.Designer.cs
index 0db8d7a..a22c61f 100644
--- a/ProjectAirbus/ProjectAirbus/FormAirbus.Designer.cs
+++ b/ProjectAirbus/ProjectAirbus/FormAirbus.Designer.cs
@@ -29,11 +29,14 @@
private void InitializeComponent()
{
pictureBoxAirbus = new PictureBox();
- buttonCreateAirBus = new Button();
+ buttonCreateAirbus = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonRight = new Button();
buttonDown = new Button();
+ buttonCreateBigAirbus = new Button();
+ comboBoxStrategy = new ComboBox();
+ buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxAirbus).BeginInit();
SuspendLayout();
//
@@ -47,16 +50,16 @@
pictureBoxAirbus.TabIndex = 0;
pictureBoxAirbus.TabStop = false;
//
- // buttonCreateAirBus
+ // buttonCreateAirbus
//
- buttonCreateAirBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateAirBus.Location = new Point(12, 529);
- buttonCreateAirBus.Name = "buttonCreateAirBus";
- buttonCreateAirBus.Size = new Size(75, 23);
- buttonCreateAirBus.TabIndex = 1;
- buttonCreateAirBus.Text = "Создать";
- buttonCreateAirBus.UseVisualStyleBackColor = true;
- buttonCreateAirBus.Click += ButtonCreateAirbus_Click;
+ buttonCreateAirbus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreateAirbus.Location = new Point(182, 529);
+ buttonCreateAirbus.Name = "buttonCreateAirbus";
+ buttonCreateAirbus.Size = new Size(164, 23);
+ buttonCreateAirbus.TabIndex = 1;
+ buttonCreateAirbus.Text = "Создать аэробус";
+ buttonCreateAirbus.UseVisualStyleBackColor = true;
+ buttonCreateAirbus.Click += ButtonCreateAirbus_Click;
//
// buttonLeft
//
@@ -106,16 +109,50 @@
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
+ // buttonCreateBigAirbus
+ //
+ buttonCreateBigAirbus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreateBigAirbus.Location = new Point(12, 529);
+ buttonCreateBigAirbus.Name = "buttonCreateBigAirbus";
+ buttonCreateBigAirbus.Size = new Size(164, 23);
+ buttonCreateBigAirbus.TabIndex = 6;
+ buttonCreateBigAirbus.Text = "Создать большой аэробус";
+ buttonCreateBigAirbus.UseVisualStyleBackColor = true;
+ buttonCreateBigAirbus.Click += buttonCreateBigAirbus_Click;
+ //
+ // comboBoxStrategy
+ //
+ comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxStrategy.FormattingEnabled = true;
+ comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
+ comboBoxStrategy.Location = new Point(909, 12);
+ comboBoxStrategy.Name = "comboBoxStrategy";
+ comboBoxStrategy.Size = new Size(121, 23);
+ comboBoxStrategy.TabIndex = 7;
+ //
+ // buttonStrategyStep
+ //
+ buttonStrategyStep.Location = new Point(909, 41);
+ buttonStrategyStep.Name = "buttonStrategyStep";
+ buttonStrategyStep.Size = new Size(121, 23);
+ buttonStrategyStep.TabIndex = 8;
+ buttonStrategyStep.Text = "Шаг";
+ buttonStrategyStep.UseVisualStyleBackColor = true;
+ buttonStrategyStep.Click += buttonStrategyStep_Click;
+ //
// FormAirbus
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1042, 564);
+ Controls.Add(buttonStrategyStep);
+ Controls.Add(comboBoxStrategy);
+ Controls.Add(buttonCreateBigAirbus);
Controls.Add(buttonDown);
Controls.Add(buttonRight);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
- Controls.Add(buttonCreateAirBus);
+ Controls.Add(buttonCreateAirbus);
Controls.Add(pictureBoxAirbus);
Margin = new Padding(3, 2, 3, 2);
Name = "FormAirbus";
@@ -128,10 +165,13 @@
#endregion
private PictureBox pictureBoxAirbus;
- private Button buttonCreateAirBus;
+ private Button buttonCreateAirbus;
private Button buttonLeft;
private Button buttonUp;
private Button buttonRight;
private Button buttonDown;
+ private Button buttonCreateBigAirbus;
+ private ComboBox comboBoxStrategy;
+ private Button buttonStrategyStep;
}
}
\ No newline at end of file
diff --git a/ProjectAirbus/ProjectAirbus/FormAirbus.cs b/ProjectAirbus/ProjectAirbus/FormAirbus.cs
index e84ff77..2ba014c 100644
--- a/ProjectAirbus/ProjectAirbus/FormAirbus.cs
+++ b/ProjectAirbus/ProjectAirbus/FormAirbus.cs
@@ -1,4 +1,6 @@
using System.Diagnostics;
+using ProjectAirbus.Drawnings;
+using ProjectAirbus.MovementStrategy;
namespace ProjectAirbus
@@ -13,12 +15,15 @@ namespace ProjectAirbus
///
private DrawningAirbus? _drawningAirbus;
+ private AbstractStrategy? _strategy;
+
///
/// Конструктор формы
///
public FormAirbus()
{
InitializeComponent();
+ _strategy = null;
}
///
@@ -37,25 +42,40 @@ namespace ProjectAirbus
pictureBoxAirbus.Image = bmp;
}
+ private void CreateObject(string type)
+ {
+ Random random = new();
+ switch (type)
+ {
+ case nameof(DrawningAirbus):
+ _drawningAirbus = new DrawningAirbus(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(DrawningBigAirbus):
+ _drawningAirbus = new DrawningBigAirbus(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;
+ }
+
+ _drawningAirbus.SetPictureSize(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
+ _drawningAirbus.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ _strategy = null;
+ //comboBoxStrategy.Enabled = true;
+ Draw();
+ }
+
///
/// Обработка кнопки "создать"
///
///
///
- private void ButtonCreateAirbus_Click(object sender, EventArgs e)
- {
- Random random = new();
- _drawningAirbus = new DrawningAirbus();
- _drawningAirbus.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)));
+ private void ButtonCreateAirbus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirbus));
- _drawningAirbus.SetPictureSize(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
- _drawningAirbus.SetPosition(random.Next(10, 100), random.Next(10, 100));
-
- Draw();
- }
+ private void buttonCreateBigAirbus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBigAirbus));
///
/// Обработка кнопок перемещения объекта
@@ -68,12 +88,13 @@ namespace ProjectAirbus
{
return;
}
-
+
String name = ((Button)sender)?.Name ?? String.Empty;
bool result = false;
- switch (name) {
+ switch (name)
+ {
case "buttonUp":
- result = _drawningAirbus.MoveTransport(DirectionType.Up);
+ result = _drawningAirbus.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
result = _drawningAirbus.MoveTransport(DirectionType.Down);
@@ -91,5 +112,45 @@ namespace ProjectAirbus
Draw();
}
}
+
+ private void buttonStrategyStep_Click(object sender, EventArgs e)
+ {
+ if (_drawningAirbus == null)
+ {
+ return;
+ }
+
+ if (comboBoxStrategy.Enabled)
+ {
+ _strategy = comboBoxStrategy.SelectedIndex switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
+
+ if (_strategy == null)
+ {
+ return;
+ }
+
+ _strategy.SetData(new MoveableAirbus(_drawningAirbus), pictureBoxAirbus.Width, pictureBoxAirbus.Height);
+ }
+
+ if (_strategy == null)
+ {
+ return;
+ }
+
+ comboBoxStrategy.Enabled = false;
+ _strategy.MakeStep();
+ Draw();
+
+ if (_strategy.GetStatus() == StrategyStatus.Finish)
+ {
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ }
+ }
}
}
diff --git a/ProjectAirbus/ProjectAirbus/MovementStrategy/AbstractStrategy.cs b/ProjectAirbus/ProjectAirbus/MovementStrategy/AbstractStrategy.cs
new file mode 100644
index 0000000..fb67a87
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/MovementStrategy/AbstractStrategy.cs
@@ -0,0 +1,78 @@
+namespace ProjectAirbus.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 (IsTargetDestination())
+ {
+ _state = StrategyStatus.Finish;
+ return;
+ }
+
+ MoveToTarget();
+ }
+
+ protected bool MoveLeft() => MoveTo(MovementDirection.Left);
+
+ protected bool MoveRight() => MoveTo(MovementDirection.Right);
+
+ protected bool MoveUp() => MoveTo(MovementDirection.Up);
+
+ 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();
+
+ 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/ProjectAirbus/ProjectAirbus/MovementStrategy/IMoveableObject.cs b/ProjectAirbus/ProjectAirbus/MovementStrategy/IMoveableObject.cs
new file mode 100644
index 0000000..d9dacfd
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/MovementStrategy/IMoveableObject.cs
@@ -0,0 +1,9 @@
+namespace ProjectAirbus.MovementStrategy;
+public interface IMoveableObject
+{
+ ObjectParameters? GetObjectPosition { get; }
+
+ int GetStep { get; }
+
+ bool TryMoveObject(MovementDirection direction);
+}
\ No newline at end of file
diff --git a/ProjectAirbus/ProjectAirbus/MovementStrategy/MoveToBorder.cs b/ProjectAirbus/ProjectAirbus/MovementStrategy/MoveToBorder.cs
new file mode 100644
index 0000000..d5feef9
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/MovementStrategy/MoveToBorder.cs
@@ -0,0 +1,37 @@
+namespace ProjectAirbus.MovementStrategy;
+
+public class MoveToBorder : AbstractStrategy
+{
+ protected override bool IsTargetDestination()
+ {
+ 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 diffX = objParams.RightBorder - FieldWidth;
+ if (Math.Abs(diffX) > GetStep())
+ {
+ MoveRight();
+ }
+
+ int diffY = objParams.BottomBorder - FieldHeight;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ MoveDown();
+ }
+ }
+}
diff --git a/ProjectAirbus/ProjectAirbus/MovementStrategy/MoveToCenter.cs b/ProjectAirbus/ProjectAirbus/MovementStrategy/MoveToCenter.cs
new file mode 100644
index 0000000..b5671c3
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/MovementStrategy/MoveToCenter.cs
@@ -0,0 +1,52 @@
+namespace ProjectAirbus.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/ProjectAirbus/ProjectAirbus/MovementStrategy/MoveableAirbus.cs b/ProjectAirbus/ProjectAirbus/MovementStrategy/MoveableAirbus.cs
new file mode 100644
index 0000000..8f990dc
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/MovementStrategy/MoveableAirbus.cs
@@ -0,0 +1,50 @@
+using ProjectAirbus.Drawnings;
+
+namespace ProjectAirbus.MovementStrategy;
+
+internal class MoveableAirbus : IMoveableObject
+{
+ private readonly DrawningAirbus? _airbus = null;
+
+ public MoveableAirbus(DrawningAirbus airbus)
+ {
+ _airbus = airbus;
+ }
+
+ public ObjectParameters? GetObjectPosition
+ {
+ get
+ {
+ if (_airbus == null || _airbus.EntityAirbus == null || !_airbus.GetPosX.HasValue || !_airbus.GetPosY.HasValue)
+ {
+ return null;
+ }
+
+ return new ObjectParameters(_airbus.GetPosX.Value, _airbus.GetPosY.Value, _airbus.GetWidth, _airbus.GetHeight);
+ }
+ }
+
+ public int GetStep => (int)(_airbus?.EntityAirbus?.Step ?? 0);
+
+ public bool TryMoveObject(MovementDirection direction)
+ {
+ if(_airbus == null || _airbus.EntityAirbus == null)
+ {
+ return false;
+ }
+
+ return _airbus.MoveTransport(GetDirectionType(direction));
+ }
+
+ 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/ProjectAirbus/ProjectAirbus/DirectionType.cs b/ProjectAirbus/ProjectAirbus/MovementStrategy/MovementDirection.cs
similarity index 82%
rename from ProjectAirbus/ProjectAirbus/DirectionType.cs
rename to ProjectAirbus/ProjectAirbus/MovementStrategy/MovementDirection.cs
index 377bd27..f2e5b1c 100644
--- a/ProjectAirbus/ProjectAirbus/DirectionType.cs
+++ b/ProjectAirbus/ProjectAirbus/MovementStrategy/MovementDirection.cs
@@ -1,25 +1,25 @@
-namespace ProjectAirbus;
+namespace ProjectAirbus.MovementStrategy;
///
/// Направление перемещения
///
-public enum DirectionType
+public enum MovementDirection
{
///
/// Вверх
///
Up = 1,
-
+
///
/// Вниз
///
Down = 2,
-
+
///
/// Влево
///
Left = 3,
-
+
///
/// Вправо
///
diff --git a/ProjectAirbus/ProjectAirbus/MovementStrategy/ObjectParameters.cs b/ProjectAirbus/ProjectAirbus/MovementStrategy/ObjectParameters.cs
new file mode 100644
index 0000000..fe727ab
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/MovementStrategy/ObjectParameters.cs
@@ -0,0 +1,36 @@
+namespace ProjectAirbus.MovementStrategy;
+
+///
+/// Параметры-координаты Объекта
+///
+public class ObjectParameters
+{
+ private readonly int _x;
+
+ 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 BottomBorder => _y + _height;
+
+ public int ObjectMiddleHorizontal => _x + _width / 2;
+
+ public int ObjectMiddleVertical => _y + _height / 2;
+
+ public ObjectParameters(int x , int y, int width, int height)
+ {
+ _x = x;
+ _y = y;
+ _width = width;
+ _height = height;
+ }
+}
+
diff --git a/ProjectAirbus/ProjectAirbus/MovementStrategy/StrategyStatus.cs b/ProjectAirbus/ProjectAirbus/MovementStrategy/StrategyStatus.cs
new file mode 100644
index 0000000..f9eeb4b
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/MovementStrategy/StrategyStatus.cs
@@ -0,0 +1,13 @@
+namespace ProjectAirbus.MovementStrategy;
+
+///
+/// Статус выполнения перемещения
+///
+public enum StrategyStatus
+{
+ NotInit,
+
+ InProgress,
+
+ Finish
+}
\ No newline at end of file
diff --git a/ProjectAirbus/ProjectAirbus/ProjectAirbus.csproj b/ProjectAirbus/ProjectAirbus/ProjectAirbus.csproj
index af03d74..edfd4f7 100644
--- a/ProjectAirbus/ProjectAirbus/ProjectAirbus.csproj
+++ b/ProjectAirbus/ProjectAirbus/ProjectAirbus.csproj
@@ -8,6 +8,12 @@
enable
+
+
+
+
+
+
True