diff --git a/Battleship/Battleship/Entities/EntityBattleship.cs b/Battleship/Battleship/Entities/EntityBattleship.cs
index c961dc1..2a84efe 100644
--- a/Battleship/Battleship/Entities/EntityBattleship.cs
+++ b/Battleship/Battleship/Entities/EntityBattleship.cs
@@ -17,9 +17,6 @@ public class EntityBattleship : EntityWarship
/// Основной цвет
///
public Color BodyColor { get; private set; }
- ///
- /// Перемещение военного корабля
- ///
/// ///
/// Признак (опция) отсека для ракет
///
diff --git a/Battleship/Battleship/Entities/EntityWarship.cs b/Battleship/Battleship/Entities/EntityWarship.cs
index 8d20e4d..9b88f8e 100644
--- a/Battleship/Battleship/Entities/EntityWarship.cs
+++ b/Battleship/Battleship/Entities/EntityWarship.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Battleship.Entities;
+namespace Battleship.Entities;
///
/// Класс-сущность Военный корабль
///
diff --git a/Battleship/Battleship/MovementStrategy/MoveToBorder.cs b/Battleship/Battleship/MovementStrategy/MoveToBorder.cs
index e941770..257dbbc 100644
--- a/Battleship/Battleship/MovementStrategy/MoveToBorder.cs
+++ b/Battleship/Battleship/MovementStrategy/MoveToBorder.cs
@@ -1,40 +1,52 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Battleship.MovementStrategy;
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestination()
{
- var objParams = GetObjectParameters;
+ ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
- return objParams.RightBorder + GetStep() >= FieldWidth &&
- objParams.DownBorder + GetStep() >= FieldHeight;
+
+ return objParams.RightBorder - GetStep() <= FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth &&
+ objParams.DownBorder - GetStep() <= FieldHeight && objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
- var objParams = GetObjectParameters;
+ ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
- var diffX = objParams.RightBorder - FieldWidth;
+
+ int diffX = objParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
- MoveRight();
+ if (diffX > 0)
+ {
+ MoveLeft();
+ }
+ else
+ {
+ MoveRight();
+ }
}
- var diffY = objParams.DownBorder - FieldHeight;
+
+ int diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
- MoveDown();
+ if (diffY > 0)
+ {
+ MoveUp();
+ }
+ else
+ {
+ MoveDown();
+ }
}
}
}
diff --git a/Battleship/Battleship/MovementStrategy/MoveToCenter.cs b/Battleship/Battleship/MovementStrategy/MoveToCenter.cs
index 7fd9ad9..84274a2 100644
--- a/Battleship/Battleship/MovementStrategy/MoveToCenter.cs
+++ b/Battleship/Battleship/MovementStrategy/MoveToCenter.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Battleship.MovementStrategy;
+namespace Battleship.MovementStrategy;
///
/// Стратегия перемещения объекта в центр экрана
@@ -14,20 +8,19 @@ public class MoveToCenter : AbstractStrategy
protected override bool IsTargetDestination()
{
ObjectParameters? objParams = GetObjectParameters;
- if (objParams != null )
+ if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontall - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontall + GetStep() >= FieldWidth / 2 &&
- objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2
- && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
+ objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
ObjectParameters? objParams = GetObjectParameters;
- if (objParams == null )
+ if (objParams == null)
{
return;
}
@@ -45,10 +38,10 @@ public class MoveToCenter : AbstractStrategy
}
}
- int diffy = objParams.ObjectMiddleVertical - FieldHeight / 2;
- if (Math.Abs(diffy) > GetStep())
+ int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
+ if (Math.Abs(diffY) > GetStep())
{
- if (diffy > 0)
+ if (diffY > 0)
{
MoveUp();
}
@@ -58,4 +51,4 @@ public class MoveToCenter : AbstractStrategy
}
}
}
-}
+}
\ No newline at end of file