35 lines
1012 B
Java
35 lines
1012 B
Java
package cat.hack3.codingtests.marsrover;
|
|
|
|
public class MarsRover {
|
|
private final MarsMap marsMap;
|
|
private final Coordinates currentCoordinates;
|
|
private Direction currentDirection;
|
|
|
|
public MarsRover(MarsMap marsMap, Coordinates startingCoordinates, Direction startingDirection) {
|
|
this.marsMap = marsMap;
|
|
currentCoordinates = startingCoordinates;
|
|
currentDirection = startingDirection;
|
|
}
|
|
|
|
public Coordinates moveForward() {
|
|
return currentCoordinates.updatePositionTowards(currentDirection);
|
|
}
|
|
|
|
public Coordinates moveBackwards() {
|
|
return currentCoordinates.updatePositionTowards(currentDirection.reversed());
|
|
}
|
|
|
|
public Direction turnLeft() {
|
|
currentDirection = currentDirection.changeDirectionToLeft();
|
|
return currentDirection;
|
|
}
|
|
|
|
public Coordinates getCurrentCoordinates() {
|
|
return currentCoordinates.copy();
|
|
}
|
|
|
|
public Direction getCurrentDirection() {
|
|
return currentDirection;
|
|
}
|
|
}
|