28 lines
923 B
Java
28 lines
923 B
Java
public class MoveToBorder extends AbstractStrategy {
|
|
protected boolean IsTargetDestinaion()
|
|
{
|
|
var objParams = GetObjectParameters();
|
|
if (objParams == null) {
|
|
return false;
|
|
}
|
|
return objParams.RightBorder() <= FieldWidth &&
|
|
objParams.RightBorder() + GetStep() >= FieldWidth &&
|
|
objParams.DownBorder() <= FieldHeight &&
|
|
objParams.DownBorder() + GetStep() >= FieldHeight;
|
|
}
|
|
protected void MoveToTarget()
|
|
{
|
|
var objParams = GetObjectParameters();
|
|
if (objParams == null) {
|
|
return;
|
|
}
|
|
var diffX = FieldWidth - objParams.ObjectMiddleHorizontal();
|
|
if (Math.abs(diffX) > GetStep()) {
|
|
MoveRight();
|
|
}
|
|
var diffY = FieldHeight - objParams.ObjectMiddleVertical();
|
|
if (Math.abs(diffY) > GetStep()) {
|
|
MoveDown();
|
|
}
|
|
}
|
|
} |