Commit a384817
Changed files (1)
src
src/Q9/MovingRobot.java
@@ -16,22 +16,22 @@ public class MovingRobot extends Robot {
public boolean validateNextMove(int direction) {
switch (direction) {
- case Robot.UP:
- return canMoveUp();
- case Robot.RIGHT_UP_CORNER:
- return canMoveUp() && canMoveRight();
- case Robot.RIGHT:
- return canMoveRight();
- case Robot.RIGHT_DOWN_CORNER:
- return canMoveDown() && canMoveRight();
- case Robot.DOWN:
- return canMoveDown();
- case Robot.LEFT_DOWN_CORNER:
- return canMoveDown() && canMoveLeft();
- case Robot.LEFT:
- return canMoveLeft();
- case Robot.LEFT_UP_CORNER:
- return canMoveLeft() && canMoveUp();
+ case Robot.NORTH:
+ return canMoveNorth();
+ case Robot.NORTH_EAST:
+ return canMoveNorth() && canMoveEast();
+ case Robot.EAST:
+ return canMoveEast();
+ case Robot.SOUTH_EAST:
+ return canMoveSouth() && canMoveEast();
+ case Robot.SOUTH:
+ return canMoveSouth();
+ case Robot.SOUTH_WEST:
+ return canMoveSouth() && canMoveWest();
+ case Robot.WEST:
+ return canMoveWest();
+ case Robot.NORTH_WEST:
+ return canMoveWest() && canMoveNorth();
default:
return false;
}
@@ -76,33 +76,33 @@ public class MovingRobot extends Robot {
if (!validateNextMove(direction)) return;
switch (direction) {
- case Robot.UP:
- moveUp();
+ case Robot.NORTH:
+ moveNorth();
break;
- case Robot.RIGHT_UP_CORNER:
- moveUp();
- moveRight();
+ case Robot.NORTH_EAST:
+ moveNorth();
+ moveEast();
break;
- case Robot.RIGHT:
- moveRight();
+ case Robot.EAST:
+ moveEast();
break;
- case Robot.RIGHT_DOWN_CORNER:
- moveDown();
- moveRight();
+ case Robot.SOUTH_EAST:
+ moveSouth();
+ moveEast();
break;
- case Robot.DOWN:
- moveDown();
+ case Robot.SOUTH:
+ moveSouth();
break;
- case Robot.LEFT_DOWN_CORNER:
- moveDown();
- moveLeft();
+ case Robot.SOUTH_WEST:
+ moveSouth();
+ moveWest();
break;
- case Robot.LEFT:
- moveLeft();
+ case Robot.WEST:
+ moveWest();
break;
- case Robot.LEFT_UP_CORNER:
- moveLeft();
- moveUp();
+ case Robot.NORTH_WEST:
+ moveWest();
+ moveNorth();
break;
default:
return;
@@ -110,35 +110,35 @@ public class MovingRobot extends Robot {
moves.add(direction);
}
- private boolean canMoveUp() {
+ private boolean canMoveNorth() {
return this.getY() > 0;
}
- private boolean canMoveDown() {
+ private boolean canMoveSouth() {
return this.getY() < 9;
}
- private boolean canMoveRight() {
+ private boolean canMoveEast() {
return this.getX() < 9;
}
- private boolean canMoveLeft() {
+ private boolean canMoveWest() {
return this.getX() > 0;
}
- private void moveUp() {
+ private void moveNorth() {
this.setY(this.getY() - 1);
}
- private void moveDown() {
+ private void moveSouth() {
this.setY(this.getY() + 1);
}
- private void moveRight() {
+ private void moveEast() {
this.setX(this.getX() + 1);
}
- private void moveLeft() {
+ private void moveWest() {
this.setX(this.getX() - 1);
}