This commit is contained in:
Yunusov_Niyaz 2023-11-04 01:54:14 +04:00
parent e59a8e2cd2
commit f9487fc660
2 changed files with 42 additions and 0 deletions

37
src/MoveToCenter.java Normal file
View File

@ -0,0 +1,37 @@
public class MoveToCenter extends AbstractStrategy{
@Override
protected boolean isTargetDestination(){
var objParams = getObjectParameters();
if(objParams == null)
return false;
return objParams.getObjectMiddleHorizontal() <= getFieldWidth() / 2 &&
objParams.getObjectMiddleHorizontal() + getStep() >= getFieldWidth() / 2 &&
objParams.getObjectMiddleVertical() <= getFieldHeight() / 2 &&
objParams.getObjectMiddleVertical() + getStep() >= getFieldHeight() / 2;
}
@Override
protected void moveToTarget() {
ObjectParameters objParams = getObjectParameters();
if (objParams == null) {
return;
}
var diffX = objParams.getObjectMiddleHorizontal() - getFieldWidth() / 2;
if (Math.abs(diffX) > getStep()) {
if (diffX > 0) {
moveLeft();
}
else {
moveRight();
}
}
var diffY = objParams.getObjectMiddleVertical() - getFieldHeight() / 2;
if (Math.abs(diffY) > getStep()) {
if (diffY > 0) {
moveUp();
}
else {
moveDown();
}
}
}
}

5
src/Status.java Normal file
View File

@ -0,0 +1,5 @@
public enum Status {
NOT_INIT,
IN_PROGRESS,
FINISH
}