/**
   * Try to in to one direction. If there is an exit, enter the new room, otherwise print an error
   * message.
   */
  private void goRoom(Command command) {
    if (!command.hasSecondWord()) {
      // if there is no second word, we don't know where to go...
      System.out.println("Go where?");
      return;
    }

    String direction =
        command.getSecondWord(); // direction is a string that is the second word, such as "east" or
    // "up"

    // Try to leave current room.
    Room currentRoom = roomList.get(currentRoomName);
    String nextRoomName = currentRoom.getExit(direction);
    Room nextRoom = roomList.get(nextRoomName);

    if (nextRoom == null) {
      System.out.println("There is no door!");
    } else {
      currentRoomName =
          nextRoomName; // The name of the current room is set to the name of the room we're going
      // into, which sets the current room to the next room.
      System.out.println(nextRoom.getLongDescription());
    }
  }
示例#2
0
文件: Game.java 项目: cjnickel/Clue
  private void goRoom(Command command) {
    if (!command.hasSecondWord()) {
      // if there is no second word, we don't know where to go...
      System.out.println("Go where?");
      return;
    }

    /**
     * Make a temporary room that is equal to the player's current room. Then set the next room to
     * the room in the direction the player wishes to go.
     */
    String direction = command.getSecondWord();
    Room tempCurrentRoom = player.getCurrentRoom();
    Room nextRoom = tempCurrentRoom.getExit(direction);
    if (nextRoom == null) {
      System.out.print("There is no door!");
    } else {
      // If there is a door then set current room to the next room.
      player.setPreviousRooms(tempCurrentRoom);
      player.setCurrentRoom(nextRoom);
      printLocationInfo();
    }
    System.out.println();
  }
 @Override
 public Room getExit(String direction) {
   return simpleRoom.getExit(direction);
 }