PIbd22_NikiforovaMV_Contain.../ContainerShip/MoveToBorder.cs

56 lines
1.6 KiB
C#
Raw Normal View History

2023-11-25 12:44:21 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ContainerShip.MovementStrategy;
namespace ContainerShip.MovementStrategy
{
internal class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
if (GetObjectParameters == null)
{
return false;
}
return GetObjectParameters.RightBorder <= FieldWidth &&
GetObjectParameters.RightBorder + GetStep() >= FieldWidth &&
GetObjectParameters.DownBorder <= FieldHeight &&
GetObjectParameters.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
if (GetObjectParameters == null)
{
return;
}
if (Math.Abs(GetObjectParameters.ObjectMiddleHorizontal - FieldWidth) > GetStep())
{
if (GetObjectParameters.ObjectMiddleHorizontal - FieldWidth > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
if (Math.Abs(GetObjectParameters.ObjectMiddleVertical - FieldHeight) > GetStep())
{
if (GetObjectParameters.ObjectMiddleVertical - FieldHeight > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}