30 lines
924 B
Java
30 lines
924 B
Java
|
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();
|
||
|
}
|
||
|
}
|
||
|
}
|