Lab2+
This commit is contained in:
parent
e59a8e2cd2
commit
f9487fc660
37
src/MoveToCenter.java
Normal file
37
src/MoveToCenter.java
Normal 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
5
src/Status.java
Normal file
@ -0,0 +1,5 @@
|
||||
public enum Status {
|
||||
NOT_INIT,
|
||||
IN_PROGRESS,
|
||||
FINISH
|
||||
}
|
Loading…
Reference in New Issue
Block a user