2023-12-04 16:53:15 +04:00
|
|
|
package DoubleDeckerBus.MovementStrategy;
|
|
|
|
|
|
|
|
public class MoveToBorder extends AbstractStrategy {
|
|
|
|
@Override
|
|
|
|
protected boolean IsTargetDestination() {
|
2023-12-05 14:27:04 +04:00
|
|
|
var objParams = GetObjectParameters();
|
2023-12-04 16:53:15 +04:00
|
|
|
|
|
|
|
if (objParams == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return objParams.RightBorder <= FieldWidth() && objParams.RightBorder + GetStep() >= FieldWidth() &&
|
|
|
|
objParams.DownBorder <= FieldHeight() && objParams.DownBorder + GetStep() >= FieldHeight();
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
protected void MoveToTarget() {
|
2023-12-05 14:27:04 +04:00
|
|
|
var objParams = GetObjectParameters();
|
2023-12-04 16:53:15 +04:00
|
|
|
|
|
|
|
if (objParams == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-12-05 14:27:04 +04:00
|
|
|
var diffX = objParams.RightBorder - FieldWidth();
|
2023-12-04 16:53:15 +04:00
|
|
|
if (Math.abs(diffX) >= GetStep()) {
|
|
|
|
if (diffX < 0) {
|
|
|
|
MoveRight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-05 14:27:04 +04:00
|
|
|
var diffY = objParams.DownBorder - FieldHeight();
|
2023-12-04 16:53:15 +04:00
|
|
|
if (Math.abs(diffY) >= GetStep()) {
|
|
|
|
if (diffY < 0) {
|
|
|
|
MoveDown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|