36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
namespace WarmlyLocomotive.MovementStrategy
|
|
{
|
|
internal class MoveToBorder : AbstractStrategy
|
|
{
|
|
protected override bool IsTargetDestinaion()
|
|
{
|
|
var objParams = GetObjectParameters;
|
|
if (objParams == null)
|
|
{
|
|
return false;
|
|
}
|
|
return objParams.RightBorder <= FieldWidth &&
|
|
objParams.RightBorder + GetStep() >= FieldWidth &&
|
|
objParams.DownBorder <= FieldHeight &&
|
|
objParams.DownBorder + GetStep() >= FieldHeight;
|
|
}
|
|
protected override void MoveToTarget()
|
|
{
|
|
var objParams = GetObjectParameters;
|
|
if (objParams == null)
|
|
{
|
|
return;
|
|
}
|
|
var diffX = FieldWidth - objParams.ObjectMiddleHorizontal;
|
|
if (Math.Abs(diffX) > GetStep())
|
|
{
|
|
MoveRight();
|
|
}
|
|
var diffY = FieldHeight - objParams.ObjectMiddleVertical;
|
|
if (Math.Abs(diffY) > GetStep())
|
|
{
|
|
MoveDown();
|
|
}
|
|
}
|
|
}
|
|
} |