PIbd-14_Antonova_A.A.__Hard/MovementStrategy/MoveToBorder.java
2024-06-10 21:17:02 +04:00

37 lines
912 B
Java

package MovementStrategy;
public class MoveToBorder extends AbstractStrategy{
@Override
protected boolean IsTargetDestinaion() {
ObjectParameters objParams = GetObjectParameters();
if (objParams == null)
{
return false;
}
return objParams.RightBorder + GetStep() >= FieldWidth - GetStep() &&
objParams.DownBorder + GetStep() >= FieldHeight - GetStep();
}
@Override
protected void MoveToTarget() {
ObjectParameters objParams = GetObjectParameters();
if (objParams == null)
{
return;
}
int diffX = FieldWidth - objParams.RightBorder;
if (Math.abs(diffX) > GetStep())
{
MoveRight();
}
int diffY = FieldHeight - objParams.DownBorder;
if (Math.abs(diffY) > GetStep())
{
MoveDown();
}
}
}