2023-11-03 21:51:37 +04:00
|
|
|
|
namespace WarmlyLocomotive.MovementStrategy
|
2023-10-31 15:28:54 +04:00
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|