PIbd-21_KozyrevSS_GasolineT.../MoveToBorder.java

30 lines
924 B
Java
Raw Permalink Normal View History

public class MoveToBorder extends AbstractStrategy
{
@Override
protected boolean IsTargetDestination() {
ObjectParameters objParams = GetObjectParameters();
if (objParams == null) {
return false;
}
return objParams.RightBorder() + GetStep() >= GetFieldWidth() && objParams.DownBorder() + GetStep() >= GetFieldHeight();
}
@Override
protected void MoveToTarget() {
ObjectParameters objParams = GetObjectParameters();
if (objParams == null) {
return;
}
int diffX = objParams.RightBorder() - GetFieldWidth();
int diffY = objParams.DownBorder() - GetFieldHeight();
if (diffX >= 0) {
MoveDown();
} else if (diffY >= 0) {
MoveRight();
} else if (Math.abs(diffX) > Math.abs(diffY)) {
MoveRight();
} else {
MoveDown();
}
}
}