@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 void showGame( Game game, Set<Location<Integer>> blockedLocations, Map<Room, Weapon> weaponLocations) { Board board = game.board; char[][] buffer = new char[2 * (board.width + 1)][2 * (board.height + 1)]; for (char[] line : buffer) { Arrays.fill(line, ' '); } for (int x = 0; x < board.width; x++) { for (int y = 0; y < board.height; y++) { // The actual tile is at buffer[2x + 1][2y + 1] // Walls: above is [2x + 1][2y], left is [2x][2y + 1] if (board.hasWallBetween( new Location<>(x, y), new Location<>(x, y - 1))) { // if there's a wall above the tile. buffer[2 * x + 1][2 * y] = '-'; } if (board.hasWallBetween( new Location<>(x, y), new Location<>(x - 1, y))) { // if there's a wall to the left of the tile. buffer[2 * x][2 * y + 1] = '|'; } } } for (int x = 0; x < board.width; x++) { buffer[2 * x + 1][2 * board.height] = '-'; } for (int y = 0; y < board.height; y++) { buffer[2 * board.width][2 * y + 1] = '|'; } for (Room room : Room.values()) { Location<Float> centre = board.centreLocationForRoom(room); String name = room.shortName(); int startX = 2 * centre.x.intValue() + 1 - name.length() / 2; int y = 2 * centre.y.intValue() + 1; for (int i = 0; i < +name.length(); i++) { buffer[startX + i][y] = name.charAt(i); } } for (Player player : game.allPlayers) { CluedoCharacter character = player.character; Location<Integer> location = player.location(); buffer[2 * location.x + 1][2 * location.y + 1] = this.asciiIconForCharacter(character); } for (int y = 0; y < 2 * (board.height + 1); y++) { for (int x = 0; x < 2 * (board.width + 1); x++) { this.out.print(buffer[x][y]); } this.out.print('\n'); } }
@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(); } }