@Override public Optional<Suggestion> requestPlayerSuggestion(Player player, Room room) { char userWantsToMakeSuggestion = '\0'; while (userWantsToMakeSuggestion != 'Y' && userWantsToMakeSuggestion != 'N') { this.out.println("Do you want to make an suggestion (Y/N)?"); this.out.println("Your cards are: " + player.cards); userWantsToMakeSuggestion = this.scanner.next().charAt(0); } if (userWantsToMakeSuggestion == 'Y') { this.out.printf("You suggest it was done in the %s, by: \n", room); Stream<String> suspects = Arrays.stream(CluedoCharacter.values()).map(CluedoCharacter::toString); CluedoCharacter suspect = CluedoCharacter.values()[this.selectOptionFromList(suspects)]; this.out.println("with the "); Stream<String> weapons = Arrays.stream(Weapon.values()).map(Weapon::toString); Weapon weapon = Weapon.values()[this.selectOptionFromList(weapons)]; return Optional.of(new Suggestion(suspect, weapon, room)); } else { return Optional.empty(); } }
@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 Optional<Suggestion> requestPlayerAccusation(Player player) { char userWantsToMakeAccusation = '\0'; while (userWantsToMakeAccusation != 'Y' && userWantsToMakeAccusation != 'N') { this.out.println("Do you want to make an accusation (Y/N)?"); userWantsToMakeAccusation = this.scanner.next().charAt(0); } if (userWantsToMakeAccusation == 'Y') { this.out.println("Choose your suspect:"); Stream<String> suspects = Arrays.stream(CluedoCharacter.values()) .filter(e -> !player.cards.contains(e)) .map(CluedoCharacter::toString); CluedoCharacter suspect = CluedoCharacter.values()[this.selectOptionFromList(suspects)]; this.out.println("Choose your weapon:"); Stream<String> weapons = Arrays.stream(Weapon.values()) .filter(e -> !player.cards.contains(e)) .map(Weapon::toString); Weapon weapon = Weapon.values()[this.selectOptionFromList(weapons)]; this.out.println("Choose your room:"); Stream<String> rooms = Arrays.stream(Room.values()).filter(e -> !player.cards.contains(e)).map(Room::toString); Room room = Room.values()[this.selectOptionFromList(rooms)]; return Optional.of(new Suggestion(suspect, weapon, room)); } else { return Optional.empty(); } }