diff options
| author | mo khan <mo@mokhan.ca> | 2019-08-05 13:26:56 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2019-08-05 13:26:56 -0600 |
| commit | a384817ca5137042eb83f40f52f9e4cd1036a389 (patch) | |
| tree | db648fe7f9216032aed934815cfea69d859902dc /src | |
| parent | 22555212598db087b128b2422b8693057ef1e88d (diff) | |
rename directions to follow known standards rather than made up confusing names
Diffstat (limited to 'src')
| -rw-r--r-- | src/Q9/MovingRobot.java | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/src/Q9/MovingRobot.java b/src/Q9/MovingRobot.java index 5e18f47..c1ffe42 100644 --- a/src/Q9/MovingRobot.java +++ b/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); } |
