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() {
|
private void decrementLongitude() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Coordinates getCurrentPosition() {
|
||||||
|
return currentPosition;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,30 +2,27 @@ package cat.hack3.codingtests.marsrover;
|
||||||
|
|
||||||
public class MarsRover {
|
public class MarsRover {
|
||||||
private final MarsMap marsMap;
|
private final MarsMap marsMap;
|
||||||
private Coordinates currentCoordinates;
|
|
||||||
private Direction currentDirection;
|
private Direction currentDirection;
|
||||||
|
|
||||||
public MarsRover(MarsMap marsMap, Coordinates startingCoordinates, Direction startingDirection) {
|
public MarsRover(MarsMap marsMap, Direction startingDirection) {
|
||||||
this.marsMap = marsMap;
|
this.marsMap = marsMap;
|
||||||
currentCoordinates = startingCoordinates;
|
|
||||||
currentDirection = startingDirection;
|
currentDirection = startingDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Coordinates moveForward() {
|
public Coordinates moveForward() {
|
||||||
return currentCoordinates = marsMap.updatePositionTowards(currentDirection);
|
return marsMap.updatePositionTowards(currentDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Coordinates moveBackwards() {
|
public Coordinates moveBackwards() {
|
||||||
return currentCoordinates = marsMap.updatePositionTowards(currentDirection.reversed());
|
return marsMap.updatePositionTowards(currentDirection.reversed());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Direction turnLeft() {
|
public Direction turnLeft() {
|
||||||
currentDirection = currentDirection.changeDirectionToLeft();
|
return currentDirection = currentDirection.changeDirectionToLeft();
|
||||||
return currentDirection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Coordinates getCurrentCoordinates() {
|
public Coordinates getCurrentCoordinates() {
|
||||||
return currentCoordinates;
|
return marsMap.getCurrentPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Direction getCurrentDirection() {
|
public Direction getCurrentDirection() {
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class MarsRoverTest {
|
||||||
int longitudeStartingPoint = 3;
|
int longitudeStartingPoint = 3;
|
||||||
var startingCoordinates = Coordinates.of(latitudeStartingPoint, longitudeStartingPoint);
|
var startingCoordinates = Coordinates.of(latitudeStartingPoint, longitudeStartingPoint);
|
||||||
var marsMap = new MarsMap(mapWidth, mapHeight, startingCoordinates);
|
var marsMap = new MarsMap(mapWidth, mapHeight, startingCoordinates);
|
||||||
rover = new MarsRover(marsMap, startingCoordinates, SOUTH);
|
rover = new MarsRover(marsMap, SOUTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue