Class Room

java.lang.Object
  extended by Room

public class Room
extends Object

Class Room - a room in an adventure game. This class is part of the "World of Zuul" application. "World of Zuul" is a very simple, text based adventure game. A "Room" represents one location in the scenery of the game. It is connected to other rooms via exits. For each existing exit, the room stores a reference to the neighboring room.

Version:
28/1/2015
Author:
Michael Kölling, David J. Barnes and Olaf Chitil

Constructor Summary
Room(String description)
          Create a room described "description".
 
Method Summary
 Room getExit(String direction)
          Return the room that is reached if we go from this room in direction "direction".
 String getLongDescription()
          Return a description of the room in the form: You are in the kitchen.
 String getShortDescription()
           
 void sane()
          Class invariant: getShortDescription() and getLongDescription() don't return null.
 void setExit(String direction, Room neighbor)
          Define an exit from this room.
 
Methods inherited from class
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Room

public Room(String description)
Create a room described "description". Initially, it has no exits. "description" is something like "a kitchen" or "an open court yard".

Parameters:
description - The room's description. Pre-condition: description is not null.
Method Detail

getExit

public Room getExit(String direction)
Return the room that is reached if we go from this room in direction "direction". If there is no room in that direction, return null.

Parameters:
direction - The exit's direction.
Returns:
The room in the given direction. Pre-condition: direction is not null

getLongDescription

public String getLongDescription()
Return a description of the room in the form: You are in the kitchen. Exits: north west

Returns:
A long description of this room

getShortDescription

public String getShortDescription()
Returns:
The short description of the room (the one that was defined in the constructor).

sane

public void sane()
Class invariant: getShortDescription() and getLongDescription() don't return null.


setExit

public void setExit(String direction,
                    Room neighbor)
Define an exit from this room.

Parameters:
direction - The direction of the exit.
neighbor - The room to which the exit leads. Pre-condition: neither direction nor neighbor are null; there is no room in given direction yet.