namespace ProjectCruiser.MoveStrategy; public class MoveToCentre : AbstractStrategy { protected override bool IsTargetDestination() { ObjParameters? objP = GetObjectParameters; if (objP == null) { return false; } return objP.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 && objP.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 && objP.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 && objP.ObjectMiddleVertical + GetStep() >= FieldHeight / 2; } protected override void MoveToTarget() { ObjParameters? objP = GetObjectParameters; if (objP == null) { return; } int diffx = objP.ObjectMiddleHorizontal - FieldWidth / 2; if (Math.Abs(diffx) > GetStep()) { if (diffx > 0) { MoveLeft(); } else { MoveRight(); } } int diffy = objP.ObjectMiddleVertical - FieldHeight / 2; if (Math.Abs(diffy) > GetStep()) { if (diffy > 0) { MoveUp(); } else { MoveDown(); } } } }