37 lines
1.0 KiB
Java
37 lines
1.0 KiB
Java
|
package DoubleDeckerBus.MovementStrategy;
|
||
|
|
||
|
public class MoveToBorder extends AbstractStrategy {
|
||
|
@Override
|
||
|
protected boolean IsTargetDestination() {
|
||
|
ObjectParameters objParams = GetObjectParameters();
|
||
|
|
||
|
if (objParams == null) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return objParams.RightBorder <= FieldWidth() && objParams.RightBorder + GetStep() >= FieldWidth() &&
|
||
|
objParams.DownBorder <= FieldHeight() && objParams.DownBorder + GetStep() >= FieldHeight();
|
||
|
}
|
||
|
@Override
|
||
|
protected void MoveToTarget() {
|
||
|
ObjectParameters objParams = GetObjectParameters();
|
||
|
|
||
|
if (objParams == null) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
int diffX = objParams.RightBorder - FieldWidth();
|
||
|
if (Math.abs(diffX) >= GetStep()) {
|
||
|
if (diffX < 0) {
|
||
|
MoveRight();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int diffY = objParams.DownBorder - FieldHeight();
|
||
|
if (Math.abs(diffY) >= GetStep()) {
|
||
|
if (diffY < 0) {
|
||
|
MoveDown();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|