diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs index 53ecbad..3f5f8be 100644 --- a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs @@ -126,7 +126,7 @@ // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.FormattingEnabled = true; - comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" }); + comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К левому нижнему краю", "К правому нижнему краю" }); comboBoxStrategy.Location = new Point(620, 12); comboBoxStrategy.Name = "comboBoxStrategy"; comboBoxStrategy.Size = new Size(242, 40); diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs index b828ba9..2b776ba 100644 --- a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs @@ -148,7 +148,8 @@ public partial class FormBulldozer : Form _strategy = comboBoxStrategy.SelectedIndex switch { 0 => new MoveToCenter(), - 1 => new MoveToBorder(), + 1 => new MoveToBorderLB(), + 2 => new MoveToBorderRB(), _ => null, }; @@ -161,11 +162,11 @@ public partial class FormBulldozer : Form pictureBoxBulldozer.Height); } - if (_strategy == null) + if (_strategy == null) { - return; + return; } - + comboBoxStrategy.Enabled = false; _strategy.MakeStep(); Draw(); @@ -177,3 +178,5 @@ public partial class FormBulldozer : Form } } } + +//2 diff --git a/ProjectBulldozer/ProjectBulldozer/MovementStrategy/AbstractStrategy.cs b/ProjectBulldozer/ProjectBulldozer/MovementStrategy/AbstractStrategy.cs index 41a7392..e00e78f 100644 --- a/ProjectBulldozer/ProjectBulldozer/MovementStrategy/AbstractStrategy.cs +++ b/ProjectBulldozer/ProjectBulldozer/MovementStrategy/AbstractStrategy.cs @@ -53,7 +53,9 @@ public abstract class AbstractStrategy FieldHeight = height; } - + /// + /// Шаг перемещения + /// public void MakeStep() { if (_state != StrategyStatus.InProgress) diff --git a/ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveToBorderLB.cs b/ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveToBorderLB.cs new file mode 100644 index 0000000..9f02a6a --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveToBorderLB.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBulldozer.MovementStrategy; + +public class MoveToBorderLB : AbstractStrategy +{ + + protected override bool IsTargetDestinaion() + { + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + + return objParams.LeftBorder - GetStep() <= 0 && objParams.BottomBorder + GetStep() >= FieldHeight; + } + + protected override void MoveToTarget() + { + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return; + } + + int diffX = objParams.LeftBorder - FieldWidth; + if (Math.Abs(diffX) > GetStep()) + { + MoveLeft(); + } + + int diffY = objParams.BottomBorder - FieldHeight; + if (Math.Abs(diffY) > GetStep()) + { + MoveDown(); + } + } +} diff --git a/ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveToBorder.cs b/ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveToBorderRB.cs similarity index 95% rename from ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveToBorder.cs rename to ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveToBorderRB.cs index 7017e52..0be1bb5 100644 --- a/ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveToBorder.cs +++ b/ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveToBorderRB.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ProjectBulldozer.MovementStrategy; -public class MoveToBorder : AbstractStrategy +public class MoveToBorderRB : AbstractStrategy { protected override bool IsTargetDestinaion() diff --git a/ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveToCenter.cs b/ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveToCenter.cs index c261ca7..6988daa 100644 --- a/ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveToCenter.cs +++ b/ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveToCenter.cs @@ -22,8 +22,8 @@ public class MoveToCenter : AbstractStrategy return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 && - objParams.ObjectMiddleVertical + GetStep() <= FieldHeight / 2 && - objParams.ObjectMiddleVertical >= FieldHeight / 2; + objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 && + objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2; } protected override void MoveToTarget() diff --git a/ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveableDozer.cs b/ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveableDozer.cs index 09cae42..b18258d 100644 --- a/ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveableDozer.cs +++ b/ProjectBulldozer/ProjectBulldozer/MovementStrategy/MoveableDozer.cs @@ -44,7 +44,7 @@ public class MoveableDozer : IMoveableObject public bool TryMoveObject(MovementDirection direction) { - if (_dozer != null || _dozer.EntityDozer == null) + if (_dozer == null || _dozer.EntityDozer == null) { return false; }