PIbd-22_Kurbanova_A.A.Warml.../WarmlyLocomotive/MoveToBorder.cs
2023-11-03 21:51:37 +04:00

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();
}
}
}
}