Ejemplo n.º 1
0
  /**
   * 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());
    }
  }
Ejemplo n.º 2
0
 /** Print out the opening message for the player. */
 private void printWelcome() {
   System.out.println();
   System.out.println("Welcome to the World of Zuul!");
   System.out.println("World of Zuul is a new, incredibly boring adventure game.");
   System.out.println("Type 'help' if you need help.");
   System.out.println();
   Room currentRoom = roomList.get(currentRoomName);
   System.out.println(currentRoom.getLongDescription());
 }
Ejemplo n.º 3
0
 /**
  * "Look" was entered. Prints out the description of the room and the exits after they have been
  * originally printed.
  */
 private void look() {
   Room currentRoom = roomList.get(currentRoomName);
   System.out.println(currentRoom.getLongDescription());
 }
Ejemplo n.º 4
0
 @Override
 public String getLongDescription() {
   return simpleRoom.getLongDescription();
 }