From e789954950942d4ad3872a91a9f1933dfaa12aec Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Tue, 26 Sep 2023 12:19:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=B2=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BE=D0=B9=20=D1=81=D1=82=D1=80=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=B3=D0=B8=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D1=89?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormStormtrooper.Designer.cs | 2 +- .../ProjectStormtrooper/FormStormtrooper.cs | 2 +- .../ProjectStormtrooper/MoveToLeftUpCorner.cs | 55 ------------------- .../ProjectStormtrooper/MoveToRightBottom.cs | 38 +++++++++++++ 4 files changed, 40 insertions(+), 57 deletions(-) delete mode 100644 ProjectStormtrooper/ProjectStormtrooper/MoveToLeftUpCorner.cs create mode 100644 ProjectStormtrooper/ProjectStormtrooper/MoveToRightBottom.cs diff --git a/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.Designer.cs b/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.Designer.cs index ab84802..46e6117 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.Designer.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.Designer.cs @@ -124,7 +124,7 @@ // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.FormattingEnabled = true; - comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToLeftUpCorner" }); + comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToRightBottom" }); comboBoxStrategy.Location = new Point(719, 12); comboBoxStrategy.Name = "comboBoxStrategy"; comboBoxStrategy.Size = new Size(151, 28); diff --git a/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.cs b/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.cs index c6fcd30..96fc949 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/FormStormtrooper.cs @@ -115,7 +115,7 @@ namespace ProjectStormtrooper _abstractStrategy = comboBoxStrategy.SelectedIndex switch { 0 => new MoveToCenter(), - 1 => new MoveToLeftUpCorner(), + 1 => new MoveToRightBottom(), _ => null, }; if (_abstractStrategy == null) diff --git a/ProjectStormtrooper/ProjectStormtrooper/MoveToLeftUpCorner.cs b/ProjectStormtrooper/ProjectStormtrooper/MoveToLeftUpCorner.cs deleted file mode 100644 index 83002a6..0000000 --- a/ProjectStormtrooper/ProjectStormtrooper/MoveToLeftUpCorner.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectStormtrooper -{ - public class MoveToLeftUpCorner : AbstractStrategy - { - protected override bool IsTargetDestinaion() - { - var objParams = GetObjectParameters; - if (objParams == null) - { - return false; - } - return objParams.ObjectMiddleHorizontal <= (objParams.RightBorder - objParams.LeftBorder) / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= (objParams.RightBorder - objParams.LeftBorder) / 2 && - objParams.ObjectMiddleVertical <= (objParams.DownBorder - objParams.TopBorder) / 2 && objParams.ObjectMiddleVertical + GetStep() >= (objParams.DownBorder - objParams.TopBorder) / 2; - } - - protected override void MoveToTarget() - { - var objParams = GetObjectParameters; - if (objParams == null) - { - return; - } - var diffX = objParams.ObjectMiddleHorizontal - (objParams.RightBorder - objParams.LeftBorder) / 2; - if (Math.Abs(diffX) > GetStep()) - { - if (diffX > 0) - { - MoveLeft(); - } - else - { - MoveRight(); - } - } - var diffY = objParams.ObjectMiddleVertical - (objParams.DownBorder - objParams.TopBorder) / 2; - if (Math.Abs(diffY) > GetStep()) - { - if (diffY > 0) - { - MoveUp(); - } - else - { - MoveDown(); - } - } - } - } -} diff --git a/ProjectStormtrooper/ProjectStormtrooper/MoveToRightBottom.cs b/ProjectStormtrooper/ProjectStormtrooper/MoveToRightBottom.cs new file mode 100644 index 0000000..9bc7f3c --- /dev/null +++ b/ProjectStormtrooper/ProjectStormtrooper/MoveToRightBottom.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectStormtrooper +{ + public class MoveToRightBottom : AbstractStrategy + { + protected override bool IsTargetDestinaion() + { + var objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + return objParams.RightBorder >= FieldWidth - GetStep() && objParams.DownBorder >= FieldHeight - GetStep(); + } + + protected override void MoveToTarget() + { + var objParams = GetObjectParameters; + if (objParams == null) + { + return; + } + if (objParams.RightBorder < FieldWidth - GetStep()) + { + MoveRight(); + } + if (objParams.TopBorder < FieldHeight - GetStep()) + { + MoveDown(); + } + } + } +}