PIbd-22_Shabunov_O.A._AirBo.../AirBomber/MovementStrategy/MoveToDownRightStrategy.cs

44 lines
1.2 KiB
C#

namespace AirBomber.MovementStrategy
{
public class MoveToDownRightStrategy : AbstractStrategy
{
protected override bool IsTargetDestination()
{
ObjectParameters? ObjParams = ObjectParameters;
if (ObjParams is null)
return false;
return
ObjParams.RightBorder <= FieldWidth &&
ObjParams.RightBorder + GetStep() >= FieldWidth &&
ObjParams.BottomBorder <= FieldHeight &&
ObjParams.BottomBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
ObjectParameters? ObjParams = ObjectParameters;
if (ObjParams is null)
return;
float diffX = ObjParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
MoveLeft();
else
MoveRight();
}
float diffY = ObjParams.BottomBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
MoveUp();
else
MoveDown();
}
}
}
}