56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|