@Override public Board.Path requestPlayerMove( Player player, Board board, Set<Location<Integer>> blockedLocations, int distance) { this.out.printf("Enter a move of length %d.\n", distance); this.out.printf( "Moves are in the format UDLR, where such a move would mean go up, then down, then left, then right.\n\n"); List<Direction> moveSequence = new ArrayList<>(); String charSequence = this.scanner.next(); if (charSequence.length() != distance) { return this.requestPlayerMove(player, board, blockedLocations, distance); } for (int i = 0; i < charSequence.length(); i++) { char c = charSequence.charAt(i); Direction dir = Direction.fromCharacter(c); if (dir == null) { return this.requestPlayerMove(player, board, blockedLocations, distance); } moveSequence.add(dir); } Optional<Board.Path> path = board.directionsToPath(player.location(), moveSequence, blockedLocations); return path.isPresent() ? path.get() : this.requestPlayerMove(player, board, blockedLocations, distance); }
@Override public Pair<Optional<String>, CluedoCharacter> askForNameAndCharacter( List<CluedoCharacter> availableCharacters) { Stream<String> characterNames = availableCharacters.stream().map(CluedoCharacter::toString); this.out.println("Select a character:\n"); int index = this.selectOptionFromList(characterNames); return new Pair<>(Optional.empty(), availableCharacters.get(index)); }
@Override public SuggestionResponse requestPlayerResponse( Player player, List<SuggestionResponse> possibleResponses) { this.out.printf( "%s can disprove this suggestion. %s, what do you want to disprove?\n", player.character, player.character); Stream<String> responseStrings = possibleResponses.stream().map(SuggestionResponse::toString); return possibleResponses.get(this.selectOptionFromList(responseStrings)); }