clean MArs rover from unneeded field
This commit is contained in:
parent
911358f2a2
commit
4bf2c88852
|
@ -64,4 +64,7 @@ public class MarsMap {
|
|||
private void decrementLongitude() {
|
||||
}
|
||||
|
||||
public Coordinates getCurrentPosition() {
|
||||
return currentPosition;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,30 +2,27 @@ package cat.hack3.codingtests.marsrover;
|
|||
|
||||
public class MarsRover {
|
||||
private final MarsMap marsMap;
|
||||
private Coordinates currentCoordinates;
|
||||
private Direction currentDirection;
|
||||
|
||||
public MarsRover(MarsMap marsMap, Coordinates startingCoordinates, Direction startingDirection) {
|
||||
public MarsRover(MarsMap marsMap, Direction startingDirection) {
|
||||
this.marsMap = marsMap;
|
||||
currentCoordinates = startingCoordinates;
|
||||
currentDirection = startingDirection;
|
||||
}
|
||||
|
||||
public Coordinates moveForward() {
|
||||
return currentCoordinates = marsMap.updatePositionTowards(currentDirection);
|
||||
return marsMap.updatePositionTowards(currentDirection);
|
||||
}
|
||||
|
||||
public Coordinates moveBackwards() {
|
||||
return currentCoordinates = marsMap.updatePositionTowards(currentDirection.reversed());
|
||||
return marsMap.updatePositionTowards(currentDirection.reversed());
|
||||
}
|
||||
|
||||
public Direction turnLeft() {
|
||||
currentDirection = currentDirection.changeDirectionToLeft();
|
||||
return currentDirection;
|
||||
return currentDirection = currentDirection.changeDirectionToLeft();
|
||||
}
|
||||
|
||||
public Coordinates getCurrentCoordinates() {
|
||||
return currentCoordinates;
|
||||
return marsMap.getCurrentPosition();
|
||||
}
|
||||
|
||||
public Direction getCurrentDirection() {
|
||||
|
|
|
@ -21,7 +21,7 @@ public class MarsRoverTest {
|
|||
int longitudeStartingPoint = 3;
|
||||
var startingCoordinates = Coordinates.of(latitudeStartingPoint, longitudeStartingPoint);
|
||||
var marsMap = new MarsMap(mapWidth, mapHeight, startingCoordinates);
|
||||
rover = new MarsRover(marsMap, startingCoordinates, SOUTH);
|
||||
rover = new MarsRover(marsMap, SOUTH);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue