From b355d6f6ab25b0a286ef8303001423e047ca4ae1 Mon Sep 17 00:00:00 2001 From: Geo7312 Date: Sat, 24 Feb 2024 22:57:17 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=81=D1=82=D1=80=D0=B0=D1=82=D0=B5=D0=B3?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Drawnings/DirectionType.cs | 5 + .../Drawnings/DrawningTrolleyB.cs | 68 ++++++---- .../FormTrolleybus.Designer.cs | 26 ++++ .../ProjectTrolleybus/FormTrolleybus.cs | 74 ++++++++++- .../MovementStrategy/AbstractStrategy.cs | 123 ++++++++++++++++++ .../MovementStrategy/IMoveableObject.cs | 24 ++++ .../MovementStrategy/MoveToBorder.cs | 56 ++++++++ .../MovementStrategy/MoveToCenter.cs | 54 ++++++++ .../MovementStrategy/MoveableTrolleyB.cs | 69 ++++++++++ .../MovementStrategy/MovementDirection.cs | 27 ++++ .../MovementStrategy/ObjectParameters.cs | 62 +++++++++ .../MovementStrategy/StrategyStatus.cs | 19 +++ 12 files changed, 580 insertions(+), 27 deletions(-) create mode 100644 ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/AbstractStrategy.cs create mode 100644 ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/IMoveableObject.cs create mode 100644 ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/MoveToBorder.cs create mode 100644 ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/MoveToCenter.cs create mode 100644 ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/MoveableTrolleyB.cs create mode 100644 ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/MovementDirection.cs create mode 100644 ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/ObjectParameters.cs create mode 100644 ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/StrategyStatus.cs diff --git a/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DirectionType.cs b/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DirectionType.cs index be67327..16417d7 100644 --- a/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DirectionType.cs +++ b/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DirectionType.cs @@ -5,6 +5,11 @@ /// public enum DirectionType { + /// + /// Неизвестное направление + /// + Unknow = -1, + /// /// Вверх /// diff --git a/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleyB.cs b/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleyB.cs index 64f0ccb..84f98ce 100644 --- a/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleyB.cs +++ b/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleyB.cs @@ -37,12 +37,32 @@ public class DrawningTrolleyB /// /// Ширина прорисовки транспорта /// - private readonly int _drawningVehicleWidth = 90; + private readonly int _drawningVehicleWidth = 89; /// /// Высота прорисовки транспорта /// - private readonly int _drawningVehicleHeight = 33; + private readonly int _drawningVehicleHeight = 31; + + /// + /// Координата X объекта + /// + public int? GetPosX => _startPosX; + + /// + /// Координата Y объекта + /// + public int? GetPosY => _startPosY; + + /// + /// Ширина объекта + /// + public int GetWidth => _drawningVehicleWidth; + + /// + /// Высота объекта + /// + public int GetHight => _drawningVehicleHeight; /// /// Пустой конструктор @@ -204,44 +224,44 @@ public class DrawningTrolleyB //Колёса pen.Width = 2; - g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 21, 12, 12); - g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 21, 12, 12); + g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 23, 12, 12); + g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 23, 12, 12); pen.Width = 1; Brush brBlackWheel = new SolidBrush(Color.Black); - g.FillEllipse(brBlackWheel, _startPosX.Value + 10, _startPosY.Value + 21, 12, 12); - g.FillEllipse(brBlackWheel, _startPosX.Value + 70, _startPosY.Value + 21, 12, 12); + g.FillEllipse(brBlackWheel, _startPosX.Value + 10, _startPosY.Value + 23, 12, 12); + g.FillEllipse(brBlackWheel, _startPosX.Value + 70, _startPosY.Value + 23, 12, 12); Brush brYelWheel = new SolidBrush(Color.Goldenrod); - g.FillEllipse(brYelWheel, _startPosX.Value + 12, _startPosY.Value + 23, 8, 8); - g.FillEllipse(brYelWheel, _startPosX.Value + 72, _startPosY.Value + 23, 8, 8); + g.FillEllipse(brYelWheel, _startPosX.Value + 12, _startPosY.Value + 25, 8, 8); + g.FillEllipse(brYelWheel, _startPosX.Value + 72, _startPosY.Value + 25, 8, 8); //Кузов Brush br = new SolidBrush(EntityTrolleyB.BodyColor); - g.FillRectangle(br, _startPosX.Value + 1, _startPosY.Value + 1, 89, 24); + g.FillRectangle(br, _startPosX.Value + 1, _startPosY.Value + 3, 89, 24); //Границы Автомобиля - g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 90, 25); - g.DrawRectangle(pen, _startPosX.Value + 26, _startPosY.Value + 10, 10, 15); - g.DrawRectangle(pen, _startPosX.Value + 78, _startPosY.Value + 4, 12, 12); + g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 2, 90, 25); + g.DrawRectangle(pen, _startPosX.Value + 26, _startPosY.Value + 12, 10, 15); + g.DrawRectangle(pen, _startPosX.Value + 78, _startPosY.Value + 6, 12, 12); pen.Width = 2; - g.DrawEllipse(pen, _startPosX.Value + 2, _startPosY.Value + 5, 8, 10); - g.DrawEllipse(pen, _startPosX.Value + 14, _startPosY.Value + 5, 8, 10); - g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 5, 8, 10); - g.DrawEllipse(pen, _startPosX.Value + 52, _startPosY.Value + 5, 8, 10); - g.DrawEllipse(pen, _startPosX.Value + 64, _startPosY.Value + 5, 8, 10); + g.DrawEllipse(pen, _startPosX.Value + 2, _startPosY.Value + 7, 8, 10); + g.DrawEllipse(pen, _startPosX.Value + 14, _startPosY.Value + 7, 8, 10); + g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 7, 8, 10); + g.DrawEllipse(pen, _startPosX.Value + 52, _startPosY.Value + 7, 8, 10); + g.DrawEllipse(pen, _startPosX.Value + 64, _startPosY.Value + 7, 8, 10); pen.Width = 1; //Стекла и кабина Brush brBlue = new SolidBrush(Color.LightBlue); - g.FillRectangle(brBlue, _startPosX.Value + 79, _startPosY.Value + 5, 11, 11); - g.FillEllipse(brBlue, _startPosX.Value + 2, _startPosY.Value + 5, 8, 10); - g.FillEllipse(brBlue, _startPosX.Value + 14, _startPosY.Value + 5, 8, 10); - g.FillEllipse(brBlue, _startPosX.Value + 40, _startPosY.Value + 5, 8, 10); - g.FillEllipse(brBlue, _startPosX.Value + 52, _startPosY.Value + 5, 8, 10); - g.FillEllipse(brBlue, _startPosX.Value + 64, _startPosY.Value + 5, 8, 10); + g.FillRectangle(brBlue, _startPosX.Value + 79, _startPosY.Value + 7, 11, 11); + g.FillEllipse(brBlue, _startPosX.Value + 2, _startPosY.Value + 7, 8, 10); + g.FillEllipse(brBlue, _startPosX.Value + 14, _startPosY.Value + 7, 8, 10); + g.FillEllipse(brBlue, _startPosX.Value + 40, _startPosY.Value + 7, 8, 10); + g.FillEllipse(brBlue, _startPosX.Value + 52, _startPosY.Value + 7, 8, 10); + g.FillEllipse(brBlue, _startPosX.Value + 64, _startPosY.Value + 7, 8, 10); //Дверь Brush brBlack = new SolidBrush(Color.LightGray); - g.FillRectangle(brBlack, _startPosX.Value + 27, _startPosY.Value + 11, 9, 14); + g.FillRectangle(brBlack, _startPosX.Value + 27, _startPosY.Value + 13, 9, 14); } } diff --git a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.Designer.cs b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.Designer.cs index f6ed86c..95e9c34 100644 --- a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.Designer.cs +++ b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.Designer.cs @@ -35,6 +35,8 @@ buttonRight = new Button(); buttonUp = new Button(); buttonCreateTrolleyB = new Button(); + comboBoxStrategy = new ComboBox(); + buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxTrolleybus).BeginInit(); SuspendLayout(); // @@ -117,11 +119,33 @@ buttonCreateTrolleyB.UseVisualStyleBackColor = true; buttonCreateTrolleyB.Click += ButtonCreateTrolleyB_Click; // + // comboBoxStrategy + // + comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStrategy.FormattingEnabled = true; + comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" }); + comboBoxStrategy.Location = new Point(667, 12); + comboBoxStrategy.Name = "comboBoxStrategy"; + comboBoxStrategy.Size = new Size(121, 23); + comboBoxStrategy.TabIndex = 7; + // + // buttonStrategyStep + // + buttonStrategyStep.Location = new Point(713, 41); + buttonStrategyStep.Name = "buttonStrategyStep"; + buttonStrategyStep.Size = new Size(75, 23); + buttonStrategyStep.TabIndex = 8; + buttonStrategyStep.Text = "Шаг"; + buttonStrategyStep.UseVisualStyleBackColor = true; + buttonStrategyStep.Click += buttonStrategyStep_Click; + // // FormTrolleybus // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); + Controls.Add(buttonStrategyStep); + Controls.Add(comboBoxStrategy); Controls.Add(buttonCreateTrolleyB); Controls.Add(buttonUp); Controls.Add(buttonRight); @@ -144,5 +168,7 @@ private Button buttonRight; private Button buttonUp; private Button buttonCreateTrolleyB; + private ComboBox comboBoxStrategy; + private Button buttonStrategyStep; } } \ No newline at end of file diff --git a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.cs b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.cs index fe80fdb..ba58b73 100644 --- a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.cs +++ b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.cs @@ -1,17 +1,36 @@ using ProjectTrolleybus.Drawnings; using ProjectTrolleybus.Entities; +using ProjectTrolleybus.MovementStrategy; namespace ProjectTrolleybus; +/// +/// Форма работы с объектом "Троллейбус" +/// public partial class FormTrolleybus : Form { + /// + /// Поле-объект для прорисовки объекта + /// private DrawningTrolleyB? _drawningTrolleyB; + /// + /// Стратегия перемещения + /// + private AbstractStrategy? _strategy; + + /// + /// Конструктор формы + /// public FormTrolleybus() { InitializeComponent(); + _strategy = null; } + /// + /// Метод прорисовки транспорта + /// private void Draw() { Bitmap bmp = new(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); @@ -20,6 +39,11 @@ public partial class FormTrolleybus : Form pictureBoxTrolleybus.Image = bmp; } + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создания объекта private void CreateObject(string type) { Random random = new(); @@ -31,8 +55,8 @@ public partial class FormTrolleybus : Form break; case nameof(DrawningTrolleybus): _drawningTrolleyB = new DrawningTrolleybus(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)), + 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: @@ -41,6 +65,9 @@ public partial class FormTrolleybus : Form _drawningTrolleyB.SetPictureSize(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); _drawningTrolleyB.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); + _strategy = null; + comboBoxStrategy.Enabled = true; + Draw(); } @@ -64,6 +91,11 @@ public partial class FormTrolleybus : Form CreateObject(nameof(DrawningTrolleyB)); } + /// + /// Перемещение объекта по кнопке (нажатие кнопок навигации) + /// + /// + /// private void ButtonMove_Click(object sender, EventArgs e) { if (_drawningTrolleyB == null) @@ -94,6 +126,42 @@ public partial class FormTrolleybus : Form Draw(); } } -} + private void buttonStrategyStep_Click(object sender, EventArgs e) + { + if (_drawningTrolleyB == null) + { + return; + } + if (comboBoxStrategy.Enabled) + { + _strategy = comboBoxStrategy.SelectedIndex switch + { + 0 => new MoveToCenter(), + 1 => new MoveToBorder(), + _ => null, + }; + if (_strategy == null) + { + return; + } + _strategy.SetData(new MoveableTrolleyB(_drawningTrolleyB), pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); + } + + if (_strategy == null) + { + return; + } + + comboBoxStrategy.Enabled = false; + _strategy.MakeStep(); + Draw(); + + if (_strategy.GetStatus() == StrategyStatus.Finish) + { + comboBoxStrategy.Enabled = true; + _strategy = null; + } + } +} \ No newline at end of file diff --git a/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/AbstractStrategy.cs b/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/AbstractStrategy.cs new file mode 100644 index 0000000..b61cd51 --- /dev/null +++ b/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/AbstractStrategy.cs @@ -0,0 +1,123 @@ +namespace ProjectTrolleybus.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(); + } + + /// + /// Перемещение влево + /// + /// Результат перемещения (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 IsTargetDestination(); + + protected bool MoveTo(MovementDirection movementDirection) + { + if (_state != StrategyStatus.InProgress) + { + return false; + } + + return _moveableObject?.TryMoveObject(movementDirection) ?? false; + } +} diff --git a/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/IMoveableObject.cs b/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/IMoveableObject.cs new file mode 100644 index 0000000..de558bc --- /dev/null +++ b/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/IMoveableObject.cs @@ -0,0 +1,24 @@ +namespace ProjectTrolleybus.MovementStrategy; + +/// +/// Интерфейс для работы с перемещаемым объектом +/// +public interface IMoveableObject +{ + /// + /// Получение координаты объекта + /// + ObjectParameters? GetObjectPosition { get; } + + /// + /// Шаг объекта + /// + int GetStep { get; } + + /// + /// Попытка переместить объект в указанном направлении + /// + /// + /// + bool TryMoveObject(MovementDirection direction); +} diff --git a/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/MoveToBorder.cs b/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/MoveToBorder.cs new file mode 100644 index 0000000..5e5ce8a --- /dev/null +++ b/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/MoveToBorder.cs @@ -0,0 +1,56 @@ +namespace ProjectTrolleybus.MovementStrategy; + +/// +/// Стратегия перемещения объекта к границам +/// +public class MoveToBorder : AbstractStrategy +{ + protected override bool IsTargetDestination() + { + + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + + return objParams.RightBorder <= FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth && + objParams.DownBorder <= FieldHeight && + 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()) + { + if (diffX > 0) + { + MoveLeft(); + } + else + { + MoveRight(); + } + } + + int diffY = objParams.DownBorder - FieldHeight; + if (Math.Abs(diffY) > GetStep()) + { + if (diffY > 0) + { + MoveUp(); + } + else + { + MoveDown(); + } + } + } +} diff --git a/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/MoveToCenter.cs b/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/MoveToCenter.cs new file mode 100644 index 0000000..4f5a381 --- /dev/null +++ b/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/MoveToCenter.cs @@ -0,0 +1,54 @@ +namespace ProjectTrolleybus.MovementStrategy; + +/// +/// Стратегия перемещения объекта к центру +/// +public class MoveToCenter : AbstractStrategy +{ + protected override bool IsTargetDestination() + { + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + + return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleVertical + 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/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/MoveableTrolleyB.cs b/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/MoveableTrolleyB.cs new file mode 100644 index 0000000..f49dc85 --- /dev/null +++ b/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/MoveableTrolleyB.cs @@ -0,0 +1,69 @@ +using ProjectTrolleybus.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectTrolleybus.MovementStrategy; + +/// +/// Класс-реализация IMoveableObject с использованием DrawningTrolleyB +/// +public class MoveableTrolleyB : IMoveableObject +{ + /// + /// Поле-объект класса DrawningTrolleyB или его наследника + /// + private readonly DrawningTrolleyB? _trolleyB = null; + + /// + /// Конструктор + /// + /// Объект класса DrawningTrolleyB + public MoveableTrolleyB(DrawningTrolleyB trolleyB) + { + _trolleyB = trolleyB; + } + + public ObjectParameters? GetObjectPosition + { + get + { + if (_trolleyB == null || _trolleyB.EntityTrolleyB == null || !_trolleyB.GetPosX.HasValue || !_trolleyB.GetPosY.HasValue) + { + return null; + } + return new ObjectParameters(_trolleyB.GetPosX.Value, _trolleyB.GetPosY.Value, _trolleyB.GetWidth, _trolleyB.GetHight); + } + } + + public int GetStep => (int)(_trolleyB?.EntityTrolleyB?.Step ?? 0); + + public bool TryMoveObject(MovementDirection direction) + { + if (_trolleyB == null || _trolleyB.EntityTrolleyB == null) + { + return false; + } + + return _trolleyB.MoveVehicle(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/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/MovementDirection.cs b/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/MovementDirection.cs new file mode 100644 index 0000000..3482982 --- /dev/null +++ b/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/MovementDirection.cs @@ -0,0 +1,27 @@ +namespace ProjectTrolleybus.MovementStrategy; + +/// +/// Направление перемещения +/// +public enum MovementDirection +{ + /// + /// Вверх + /// + Up = 1, + + /// + /// Вниз + /// + Down = 2, + + /// + /// Влево + /// + Left = 3, + + /// + /// Вправо + /// + Right = 4 +} diff --git a/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/ObjectParameters.cs b/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/ObjectParameters.cs new file mode 100644 index 0000000..cf2ec36 --- /dev/null +++ b/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/ObjectParameters.cs @@ -0,0 +1,62 @@ +namespace ProjectTrolleybus.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; + + public ObjectParameters(int x, int y, int width, int height) + { + _x = x; + _y = y; + _width = width; + _height = height; + } +} diff --git a/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/StrategyStatus.cs b/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/StrategyStatus.cs new file mode 100644 index 0000000..6b6e301 --- /dev/null +++ b/ProjectTrolleybus/ProjectTrolleybus/MovementStrategy/StrategyStatus.cs @@ -0,0 +1,19 @@ +namespace ProjectTrolleybus.MovementStrategy; + +public enum StrategyStatus +{ + /// + /// Все готово к началу + /// + NotInit, + + /// + /// Выполняется + /// + InProgress, + + /// + /// Завершено + /// + Finish +}