adapt UI to new commands design
This commit is contained in:
parent
535ae91e6c
commit
f0f3bf31fc
|
@ -1,6 +1,6 @@
|
|||
package cat.hack3.codingtests.marsrover.ui.console;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.MarsRover;
|
||||
import cat.hack3.codingtests.marsrover.RotableRiderRover;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
|
@ -13,8 +13,8 @@ public class ClientCommandInterface {
|
|||
|
||||
public static void main(String[] args) {
|
||||
try (var userInputSource = new Scanner(System.in)) {
|
||||
ClientCommandInterface userInterface = new ClientCommandInterface(userInputSource);
|
||||
userInterface.start();
|
||||
new ClientCommandInterface(userInputSource)
|
||||
.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,8 @@ public class ClientCommandInterface {
|
|||
private void start() {
|
||||
output(PresentationMessage.INTRO);
|
||||
|
||||
MarsRover rover = roverInitializer.autoInitialize();
|
||||
//MarsRover rover = roverInitializer.initializeFromUserInputs();
|
||||
//RotableRiderRover rover = roverInitializer.autoInitialize();
|
||||
RotableRiderRover rover = roverInitializer.initializeFromUserInputs();
|
||||
|
||||
var commandsPerformer = new RoverCommandsPerformer(reader, rover);
|
||||
commandsPerformer.acceptCommandsUntilExitSignal();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package cat.hack3.codingtests.marsrover.ui.console;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.MarsRover;
|
||||
import cat.hack3.codingtests.marsrover.*;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
|
@ -9,11 +9,19 @@ import static cat.hack3.codingtests.marsrover.ui.console.UICommons.output;
|
|||
|
||||
public class RoverCommandsPerformer {
|
||||
private final Scanner reader;
|
||||
private final MarsRover rover;
|
||||
private final RotableRiderRover rover;
|
||||
private final MarsRoverCommand moveForwardCommand;
|
||||
private final MarsRoverCommand moveBackwardsCommand;
|
||||
private final MarsRoverCommand turnLeftCommand;
|
||||
private final MarsRoverCommand turnRightCommand;
|
||||
|
||||
public RoverCommandsPerformer(Scanner reader, MarsRover rover) {
|
||||
public RoverCommandsPerformer(Scanner reader, RotableRiderRover rover) {
|
||||
this.reader = reader;
|
||||
this.rover = rover;
|
||||
moveForwardCommand = new MoveForwardCommand(rover);
|
||||
moveBackwardsCommand = new MoveBackwardsCommand(rover);
|
||||
turnLeftCommand = new TurnLeftCommand(rover);
|
||||
turnRightCommand = new TurnRightCommand(rover);
|
||||
}
|
||||
|
||||
public void acceptCommandsUntilExitSignal() {
|
||||
|
@ -22,10 +30,10 @@ public class RoverCommandsPerformer {
|
|||
output("Insert command (f = forward, b = backward, l = turn left, r = turn right, q = quit):");
|
||||
nextCommand = reader.next();
|
||||
switch (nextCommand) {
|
||||
case "f" -> rover.moveForward();
|
||||
case "b" -> rover.moveBackwards();
|
||||
case "l" -> rover.turnLeft();
|
||||
case "r" -> rover.turnRight();
|
||||
case "f" -> moveForwardCommand.execute();
|
||||
case "b" -> moveBackwardsCommand.execute();
|
||||
case "l" -> turnLeftCommand.execute();
|
||||
case "r" -> turnRightCommand.execute();
|
||||
case "q" -> output("Disconnecting from Mars...");
|
||||
default -> output("unknown command");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cat.hack3.codingtests.marsrover.ui.console;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.MarsRover;
|
||||
import cat.hack3.codingtests.marsrover.RotableRiderRover;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Coordinates;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Direction;
|
||||
import cat.hack3.codingtests.marsrover.cartography.MarsMap;
|
||||
|
@ -21,7 +22,7 @@ public class RoverInitializer {
|
|||
directionRetriever = new DirectionRetriever(reader);
|
||||
}
|
||||
|
||||
MarsRover initializeFromUserInputs() {
|
||||
RotableRiderRover initializeFromUserInputs() {
|
||||
output("Please, introduce the latitude map size:");
|
||||
int mapHeight = takeIntegerInput();
|
||||
output("Please, introduce the longitude map size:");
|
||||
|
@ -35,7 +36,7 @@ public class RoverInitializer {
|
|||
|
||||
Direction startingDirection = directionRetriever.retrieveDirection();
|
||||
|
||||
MarsRover rover = deployRover(mapHeight, mapWidth, latitudeStartingPoint, longitudeStartingPoint, startingDirection);
|
||||
RotableRiderRover rover = deployRover(mapHeight, mapWidth, latitudeStartingPoint, longitudeStartingPoint, startingDirection);
|
||||
|
||||
output(PresentationMessage.READY_MESSAGE);
|
||||
reader.next(); //input ignored
|
||||
|
@ -53,7 +54,7 @@ public class RoverInitializer {
|
|||
}
|
||||
}
|
||||
|
||||
MarsRover autoInitialize() { //to test more quickly
|
||||
RotableRiderRover autoInitialize() { //to test more quickly
|
||||
List<Coordinates> obstacles = List.of(
|
||||
Coordinates.of(3, 3),
|
||||
Coordinates.of(5, 5),
|
||||
|
@ -65,7 +66,7 @@ public class RoverInitializer {
|
|||
}
|
||||
|
||||
@SafeVarargs
|
||||
private MarsRover deployRover(int mapHeight, int mapWidth, int latitudeStartingPoint, int longitudeStartingPoint, Direction startingDirection, List<Coordinates>... obstaclesLocalizations) {
|
||||
private RotableRiderRover deployRover(int mapHeight, int mapWidth, int latitudeStartingPoint, int longitudeStartingPoint, Direction startingDirection, List<Coordinates>... obstaclesLocalizations) {
|
||||
var startingCoordinates = Coordinates.of(latitudeStartingPoint, longitudeStartingPoint);
|
||||
var marsMap = new MarsMap(mapHeight, mapWidth, startingCoordinates, obstaclesLocalizations);
|
||||
return new MarsRover(marsMap, startingDirection);
|
||||
|
|
Loading…
Reference in New Issue