Levels:
Characters:
Items:
public void execute() {
this.setNewPosition();
// some code
if (!isMovePossible()) {
// some code
}
this.moveCharacter();
// some code
}
public boolean isMovePossible() {
return !this.outsideFieldBorders()
&& !this.clashesWithNeighborCharacter()
&& !this.clashesWithTool();
}
public boolean clashesWithTool() {
// some code
}
public boolean clashesWithNeighborCharacter() {
// some code
}
public void moveCharacter() {
this.field.moveCharacter(this.character, newPosition);
}
public abstract boolean outsideFieldBorders();
public abstract void setNewPosition();
MoveCommand.java
@Override
public boolean outsideFieldBorders() {
if (this.currentPosition.x == this.field.getElements()[0].length - 1) {
return true;
}
return false;
}
@Override
public void setNewPosition() {
this.newPosition = new Position(currentPosition.x + 1,
currentPosition.y);
}
DownCommand.java
@Override
public boolean outsideFieldBorders() {
if (this.currentPosition.y == 0) {
return true;
}
return false;
}
@Override
public void setNewPosition() {
this.newPosition = new Position(currentPosition.x,
currentPosition.y - 1);
}
LeftCommand.java