From ca87f5d55d3880ffbad195bb858ca3de830729a8 Mon Sep 17 00:00:00 2001 From: MatveyPetrov Date: Tue, 6 Feb 2024 17:05:23 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=962?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Draw/DirectionType.cs | 5 + .../Draw/DrawningAircraft.cs | 27 +++- .../FormMilitaryAircraft.Designer.cs | 44 +++++- .../FormMilitaryAircraft.cs | 59 +++++++- .../MovementStrategy/AbstractStrategy.cs | 139 ++++++++++++++++++ .../MovementStrategy/IMoveableObjects.cs | 31 ++++ .../MovementStrategy/MoveToBorder.cs | 57 +++++++ .../MovementStrategy/MoveToCenter.cs | 40 +++++ .../MovementStrategy/MoveableAircraft.cs | 69 +++++++++ .../MovementStrategy/MovementDirection.cs | 29 ++++ .../MovementStrategy/ObjectParameters.cs | 74 ++++++++++ .../MovementStrategy/StrategyStatus.cs | 29 ++++ 12 files changed, 590 insertions(+), 13 deletions(-) create mode 100644 ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/AbstractStrategy.cs create mode 100644 ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/IMoveableObjects.cs create mode 100644 ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/MoveToBorder.cs create mode 100644 ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/MoveToCenter.cs create mode 100644 ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/MoveableAircraft.cs create mode 100644 ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/MovementDirection.cs create mode 100644 ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/ObjectParameters.cs create mode 100644 ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/StrategyStatus.cs diff --git a/ProectMilitaryAircraft/ProectMilitaryAircraft/Draw/DirectionType.cs b/ProectMilitaryAircraft/ProectMilitaryAircraft/Draw/DirectionType.cs index 99b45f1..eaf23b6 100644 --- a/ProectMilitaryAircraft/ProectMilitaryAircraft/Draw/DirectionType.cs +++ b/ProectMilitaryAircraft/ProectMilitaryAircraft/Draw/DirectionType.cs @@ -11,6 +11,11 @@ namespace ProectMilitaryAircraft.Draw; /// public enum DirectionType { + /// + /// Неизвестное направление + /// + Unknow = -1, + /// /// Вверх /// diff --git a/ProectMilitaryAircraft/ProectMilitaryAircraft/Draw/DrawningAircraft.cs b/ProectMilitaryAircraft/ProectMilitaryAircraft/Draw/DrawningAircraft.cs index e4611cc..51b60c9 100644 --- a/ProectMilitaryAircraft/ProectMilitaryAircraft/Draw/DrawningAircraft.cs +++ b/ProectMilitaryAircraft/ProectMilitaryAircraft/Draw/DrawningAircraft.cs @@ -44,6 +44,27 @@ public class DrawningAircraft /// private readonly int _drawingMilitaryAircraftHeight = 110; + + /// + /// Координа Х + /// + public int? GetPosX => _startPosX; + + /// + /// Координата Y + /// + public int? GetPosY => _startPosY; + + /// + /// Ширина объекта + /// + public int GetWidth => _drawningMilitaryAircraftWidth; + + /// + /// Высота объекта + /// + public int GetHeight => _drawingMilitaryAircraftHeight; + /// /// Пустой конструктор /// @@ -148,20 +169,24 @@ public class DrawningAircraft return true; //Вправо case DirectionType.Right: +#pragma warning disable CS8629 // Тип значения, допускающего NULL, может быть NULL. if (_startPosX.Value + EntityAircraft.Step <= _pictureWidth.Value) { if (_startPosX + 98 <= _pictureWidth) _startPosX += (int)EntityAircraft.Step; } +#pragma warning restore CS8629 // Тип значения, допускающего NULL, может быть NULL. return true; //Влево case DirectionType.Down: +#pragma warning disable CS8629 // Тип значения, допускающего NULL, может быть NULL. if (_startPosY.Value + EntityAircraft.Step <= _pictureHeight.Value) { if (_startPosY + 90 <= _pictureHeight) _startPosY += (int)EntityAircraft.Step; } +#pragma warning restore CS8629 // Тип значения, допускающего NULL, может быть NULL. return true; default: return false; @@ -207,6 +232,4 @@ public class DrawningAircraft g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 50, _startPosX.Value + 60, _startPosY.Value + 55); } - - } diff --git a/ProectMilitaryAircraft/ProectMilitaryAircraft/FormMilitaryAircraft.Designer.cs b/ProectMilitaryAircraft/ProectMilitaryAircraft/FormMilitaryAircraft.Designer.cs index 857662a..acc8355 100644 --- a/ProectMilitaryAircraft/ProectMilitaryAircraft/FormMilitaryAircraft.Designer.cs +++ b/ProectMilitaryAircraft/ProectMilitaryAircraft/FormMilitaryAircraft.Designer.cs @@ -35,6 +35,8 @@ buttonRight = new Button(); buttonDown = new Button(); buttonCreateA = new Button(); + comboBoxStrategy = new ComboBox(); + buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxMilitaryAircraft).BeginInit(); SuspendLayout(); // @@ -43,14 +45,14 @@ pictureBoxMilitaryAircraft.Dock = DockStyle.Fill; pictureBoxMilitaryAircraft.Location = new Point(0, 0); pictureBoxMilitaryAircraft.Name = "pictureBoxMilitaryAircraft"; - pictureBoxMilitaryAircraft.Size = new Size(1108, 499); + pictureBoxMilitaryAircraft.Size = new Size(953, 651); pictureBoxMilitaryAircraft.TabIndex = 0; pictureBoxMilitaryAircraft.TabStop = false; // // buttonCreateMA // buttonCreateMA.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateMA.Location = new Point(12, 464); + buttonCreateMA.Location = new Point(12, 616); buttonCreateMA.Name = "buttonCreateMA"; buttonCreateMA.Size = new Size(172, 23); buttonCreateMA.TabIndex = 1; @@ -65,7 +67,7 @@ buttonLeft.BackgroundImage = Properties.Resources.Left; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; buttonLeft.ForeColor = SystemColors.ControlLightLight; - buttonLeft.Location = new Point(979, 458); + buttonLeft.Location = new Point(824, 610); buttonLeft.Name = "buttonLeft"; buttonLeft.Size = new Size(35, 35); buttonLeft.TabIndex = 2; @@ -79,7 +81,7 @@ buttonUp.BackgroundImage = Properties.Resources.Up; buttonUp.BackgroundImageLayout = ImageLayout.Stretch; buttonUp.ForeColor = SystemColors.ControlLightLight; - buttonUp.Location = new Point(1020, 417); + buttonUp.Location = new Point(865, 569); buttonUp.Name = "buttonUp"; buttonUp.Size = new Size(35, 35); buttonUp.TabIndex = 3; @@ -93,7 +95,7 @@ buttonRight.BackgroundImage = Properties.Resources.Right; buttonRight.BackgroundImageLayout = ImageLayout.Stretch; buttonRight.ForeColor = SystemColors.ControlLightLight; - buttonRight.Location = new Point(1061, 458); + buttonRight.Location = new Point(906, 610); buttonRight.Name = "buttonRight"; buttonRight.Size = new Size(35, 35); buttonRight.TabIndex = 4; @@ -107,7 +109,7 @@ buttonDown.BackgroundImage = Properties.Resources.Down; buttonDown.BackgroundImageLayout = ImageLayout.Stretch; buttonDown.ForeColor = SystemColors.ControlLightLight; - buttonDown.Location = new Point(1020, 458); + buttonDown.Location = new Point(865, 610); buttonDown.Name = "buttonDown"; buttonDown.Size = new Size(35, 35); buttonDown.TabIndex = 5; @@ -117,7 +119,7 @@ // buttonCreateA // buttonCreateA.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateA.Location = new Point(199, 464); + buttonCreateA.Location = new Point(199, 616); buttonCreateA.Name = "buttonCreateA"; buttonCreateA.Size = new Size(172, 23); buttonCreateA.TabIndex = 6; @@ -125,11 +127,35 @@ buttonCreateA.UseVisualStyleBackColor = true; buttonCreateA.Click += ButtonCreateA_Click; // + // comboBoxStrategy + // + comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; + comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStrategy.FormattingEnabled = true; + comboBoxStrategy.Items.AddRange(new object[] { "К ценру", "К краю" }); + comboBoxStrategy.Location = new Point(823, 12); + comboBoxStrategy.Name = "comboBoxStrategy"; + comboBoxStrategy.Size = new Size(121, 23); + comboBoxStrategy.TabIndex = 7; + // + // buttonStrategyStep + // + buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonStrategyStep.Location = new Point(870, 41); + buttonStrategyStep.Name = "buttonStrategyStep"; + buttonStrategyStep.Size = new Size(75, 23); + buttonStrategyStep.TabIndex = 8; + buttonStrategyStep.Text = "Шаг"; + buttonStrategyStep.UseVisualStyleBackColor = true; + buttonStrategyStep.Click += ButtonStrategyStep_Click; + // // FormMilitaryAircraft // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1108, 499); + ClientSize = new Size(953, 651); + Controls.Add(buttonStrategyStep); + Controls.Add(comboBoxStrategy); Controls.Add(buttonCreateA); Controls.Add(buttonDown); Controls.Add(buttonRight); @@ -152,5 +178,7 @@ private Button buttonRight; private Button buttonDown; private Button buttonCreateA; + private ComboBox comboBoxStrategy; + private Button buttonStrategyStep; } } \ No newline at end of file diff --git a/ProectMilitaryAircraft/ProectMilitaryAircraft/FormMilitaryAircraft.cs b/ProectMilitaryAircraft/ProectMilitaryAircraft/FormMilitaryAircraft.cs index 81970d1..78a6f72 100644 --- a/ProectMilitaryAircraft/ProectMilitaryAircraft/FormMilitaryAircraft.cs +++ b/ProectMilitaryAircraft/ProectMilitaryAircraft/FormMilitaryAircraft.cs @@ -8,16 +8,30 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ProectMilitaryAircraft.Draw; +using ProectMilitaryAircraft.MovementStrategy; namespace ProectMilitaryAircraft { public partial class FormMilitaryAircraft : Form { - + /// + /// Поле-объект для прорисовки объекта + /// private DrawningAircraft? _DrawningAircraft; + + + /// + /// Стратегия перемещения + /// + private AbstractStrategys? _AbstractStrategy; + + /// + /// Конструктор формы + /// public FormMilitaryAircraft() { InitializeComponent(); + _AbstractStrategy = null; } private void Draw() @@ -45,7 +59,7 @@ namespace ProectMilitaryAircraft break; case nameof(DrawningMilitaryAircraft): - _DrawningAircraft = new DrawningMilitaryAircraft(rnd.Next(100, 300), rnd.Next(1000, 3000), + _DrawningAircraft = new DrawningMilitaryAircraft(rnd.Next(100, 300), rnd.Next(1000, 3000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), pictureBoxMilitaryAircraft.Width, pictureBoxMilitaryAircraft.Height); @@ -55,7 +69,8 @@ namespace ProectMilitaryAircraft } _DrawningAircraft.SetpictureSize(pictureBoxMilitaryAircraft.Width, pictureBoxMilitaryAircraft.Height); _DrawningAircraft.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100)); - + _AbstractStrategy = null; + comboBoxStrategy.Enabled = true; Draw(); } @@ -104,5 +119,43 @@ namespace ProectMilitaryAircraft Draw(); } } + + /// + /// + /// + /// + /// + private void ButtonStrategyStep_Click(object sender, EventArgs e) + { + if (_DrawningAircraft == null) + { + return; + } + + if (comboBoxStrategy.Enabled) + { + _AbstractStrategy = comboBoxStrategy.SelectedIndex switch + { + 0 => new MoveToCenter(), + 1 => new MoveToBorder(), + _ => null, + }; + if (_AbstractStrategy == null) { return; } + + _AbstractStrategy.SetData(new MoveableAircraft(_DrawningAircraft), pictureBoxMilitaryAircraft.Width, pictureBoxMilitaryAircraft.Height); + } + + if (_AbstractStrategy == null) { return; } + + comboBoxStrategy.Enabled = false; + _AbstractStrategy.MakeStep(); + Draw(); + + if (_AbstractStrategy.GetStatus() == StrategyStatus.Finish) + { + comboBoxStrategy.Enabled = true; + _AbstractStrategy = null; + } + } } } diff --git a/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/AbstractStrategy.cs b/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/AbstractStrategy.cs new file mode 100644 index 0000000..d390f82 --- /dev/null +++ b/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/AbstractStrategy.cs @@ -0,0 +1,139 @@ +using System; +using System.Collections.Generic; +using System.DirectoryServices.ActiveDirectory; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProectMilitaryAircraft.MovementStrategy; + +/// +/// класс - стратегия перемещения объекта +/// +public abstract class AbstractStrategys +{ + /// + /// Перемещаемый объект + /// + private IMoveableObjects? _moveableObjects; + + /// + /// Статус перемеения + /// + 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 moveableObjects, int width, int height) + { + if(moveableObjects == null) + { + _state = StrategyStatus.NotInit; + return; + } + _state = StrategyStatus.InProgress; + _moveableObjects = moveableObjects; + FieldWidth = width; + FieldHeight = height; + } + + /// + /// Шаг перемещения + /// + public void MakeStep() + { + if (_state != StrategyStatus.InProgress) + { + return; + } + if (IsTrgetDestansion()) + { + _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 => _moveableObjects?.GetObjectPosition; + + /// + /// Шаг объекта + /// + /// + protected int? GetStep() + { + if (_state != StrategyStatus.InProgress) + { + return null; + } + return _moveableObjects?.GetStep; + } + + /// + /// Перемещение к цели + /// + protected abstract void MoveToTarget(); + + /// + /// Достигнута ли цель + /// + /// + protected abstract bool IsTrgetDestansion(); + + private bool MoveTo(MovementDirection movementDirection) + { + if (_state != StrategyStatus.InProgress) + { + return false; + } + return _moveableObjects?.TryMoveObject(movementDirection) ?? false; + } + +} diff --git a/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/IMoveableObjects.cs b/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/IMoveableObjects.cs new file mode 100644 index 0000000..7775962 --- /dev/null +++ b/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/IMoveableObjects.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProectMilitaryAircraft.MovementStrategy; + + +/// +/// Интерфейс для работы с перемещаемым объектом +/// +public interface IMoveableObjects +{ + /// + /// Получение координаты объекта + /// + ObjectParameters? GetObjectPosition { get; } + + /// + /// Шаг объекта + /// + int GetStep { get; } + + /// + /// Попытка переместить объект в указанном направлении + /// + /// Направление + /// true - Объект перемещен, false - перемещение невозможно-v + bool TryMoveObject(MovementDirection direction); +} diff --git a/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/MoveToBorder.cs b/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/MoveToBorder.cs new file mode 100644 index 0000000..347f50d --- /dev/null +++ b/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/MoveToBorder.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProectMilitaryAircraft.MovementStrategy; + +public class MoveToBorder : AbstractStrategys +{ + protected override bool IsTrgetDestansion() + { + var 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() + { + var objParams = GetObjectParameters; + if (objParams == null) + { + return; + } + var diffX = objParams.RightBorder - FieldWidth; + if (Math.Abs(diffX) > GetStep()) + { + if (diffX > 0) + { + MoveLeft(); + } + else + { + MoveRight(); + } + } + var diffY = objParams.DownBorder - FieldHeight; + if (Math.Abs(diffY) > GetStep()) + { + if (diffY > 0) + { + MoveUp(); + } + else + { + MoveDown(); + } + } + } +} diff --git a/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/MoveToCenter.cs b/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/MoveToCenter.cs new file mode 100644 index 0000000..3d354ef --- /dev/null +++ b/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/MoveToCenter.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace ProectMilitaryAircraft.MovementStrategy; + +public class MoveToCenter : AbstractStrategys +{ + protected override bool IsTrgetDestansion() + { + 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/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/MoveableAircraft.cs b/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/MoveableAircraft.cs new file mode 100644 index 0000000..a927b0b --- /dev/null +++ b/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/MoveableAircraft.cs @@ -0,0 +1,69 @@ +using ProectMilitaryAircraft.Draw; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProectMilitaryAircraft.MovementStrategy; + +/// +/// Класс - реалицация IMoveableObjects с использованием DrawningAircraft +/// +public class MoveableAircraft : IMoveableObjects +{ + /// + /// Поле - объект класса DrawningAircraft или его наследника + /// + private readonly DrawningAircraft? _Air = null; + + /// + /// Конструктор + /// + /// Объект класса DrawningAircraft + public MoveableAircraft(DrawningAircraft Air) + { + _Air = Air; + } + + public ObjectParameters? GetObjectPosition + { + get + { + if (_Air == null || _Air.EntityAircraft == null || !_Air.GetPosX.HasValue || !_Air.GetPosY.HasValue) + { + return null; + } + return new ObjectParameters(_Air.GetPosX.Value, _Air.GetPosY.Value, _Air.GetWidth, _Air.GetHeight); + } + } + public int GetStep => (int)(_Air?.EntityAircraft?.Step ?? 0); + + public bool TryMoveObject(MovementDirection direction) + { + if(_Air == null || _Air.EntityAircraft == null) + { + return false; + } + + return _Air.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/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/MovementDirection.cs b/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/MovementDirection.cs new file mode 100644 index 0000000..5a3eb9c --- /dev/null +++ b/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/MovementDirection.cs @@ -0,0 +1,29 @@ +namespace ProectMilitaryAircraft.MovementStrategy; + + +/// +/// Направление перемещения +/// +public enum MovementDirection +{ + + /// + /// Вверх + /// + Up = 1, + + /// + /// Вниз + /// + Down = 2, + + /// + ///Влево + /// + Left = 3, + + /// + /// Вправо + /// + Right = 4, +} diff --git a/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/ObjectParameters.cs b/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/ObjectParameters.cs new file mode 100644 index 0000000..f93e116 --- /dev/null +++ b/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/ObjectParameters.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProectMilitaryAircraft.MovementStrategy; + + +/// +/// Параметры - координаты объекта +/// +public class ObjectParameters +{ + /// + /// Координата Х + /// + private readonly int _x; + + /// + /// Координата Y + /// + private readonly int _y; + + /// + /// Ширина объекта + /// + private readonly int _width; + + /// + /// Высота объекта + /// + private readonly int _height; + + + /// + /// Левая граница + /// + public int LeftBorder => _x; + + /// + /// Верхняя граница + /// + public int TopBorder => _y; + + /// + /// Правая граница + /// + public int RightBorder => _x + _width; + + /// + /// Нижняя граница + /// + public int DownBorder => _y + _width; + + /// + /// Середнина объекта + /// + public int ObjectMiddleHorizontal => _x + _height / 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/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/StrategyStatus.cs b/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/StrategyStatus.cs new file mode 100644 index 0000000..77ae0b8 --- /dev/null +++ b/ProectMilitaryAircraft/ProectMilitaryAircraft/MovementStrategy/StrategyStatus.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProectMilitaryAircraft.MovementStrategy; + + +/// +/// Статус выполнения операции перемещения +/// +public enum StrategyStatus +{ + /// + /// Все готово к началу + /// + NotInit, + + /// + /// Выполняется + /// + InProgress, + + /// + /// Завершено + /// + Finish +}