#java.util.scanner
Вопрос:
Работаю над текстовой приключенческой игрой, и я пытаюсь заставить игрока ходить по дому. Я считаю, что код настроен правильно, и он работал ранее, но затем он начал печатать вывод дважды.
Scanner sc = new Scanner(System.in);
int roomID = 0, roomID1 = 5;
int itemID = 0, itemID1 = 1, itemID2 = 2;
int puzzleID = 0;
boolean startGame = true;
while (startGame) {
System.out.println("You are in " Map.getRooms().get(roomID).getRoomName() " n" "Where would you like to go? (N, E, S, W)");
String playerInput = sc.nextLine();
if (playerInput.equalsIgnoreCase("n") || playerInput.equalsIgnoreCase("north")) {
String direction = Map.getRooms().get(roomID).getNorth();
player.map.getRoom(direction);
}
else if (playerInput.equalsIgnoreCase("e") || playerInput.equalsIgnoreCase("east")) {
String direction = Map.getRooms().get(roomID).getEast();
player.map.getRoom(direction);
}
else if (playerInput.equalsIgnoreCase("s") || playerInput.equalsIgnoreCase("south")) {
String direction = Map.getRooms().get(roomID).getSouth();
player.map.getRoom(direction);
}
else if (playerInput.equalsIgnoreCase("w") || playerInput.equalsIgnoreCase("west")) {
String direction = Map.getRooms().get(roomID).getWest();
player.map.getRoom(direction);
}
else if (playerInput.equalsIgnoreCase("explore")) {
System.out.println(Map.getRooms().get(roomID).getRoomDesc());
}
else if (playerInput.equalsIgnoreCase("quit")) {
System.out.println("Quitting Game...");
startGame = false;
}
Вот пример вывода:
You are in Bathroom
Where would you like to go? (N, E, S, W)
n
You see a Key
You are in Bedroom
Where would you like to go? (N, E, S, W)
You see a Key
You are in Bedroom
Where would you like to go? (N, E, S, W)