|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object | +--Room
A Room is a "location" in the adventure game. A Room has a name, a description, and it connects to other rooms. In addition, a Room is a container for Things, and you can iterate over the Things in the Room.
Each Room you create should have a unique name. The Room class
keeps track of all Rooms that you create.
Given a Room theRoom, theRoom.getName() will return its name.
Given a name roomName, Room.getRoom(roomName) will return the
Room with that name.
You should NOT alter this class unless you want to give new behaviors to ALL Rooms.
| Field Summary | |
private java.util.Vector |
contents
|
private java.lang.String |
description
|
private java.lang.String |
name
|
private java.util.Hashtable |
paths
|
private static java.util.Hashtable |
rooms
|
| Constructor Summary | |
Room(java.lang.String name)
Constructor for objects of class Room. |
|
| Method Summary | |
void |
add(Thing thing)
Puts the given Thing into the room. |
void |
addPath(java.lang.String direction,
Room destination)
Creates a new path, in the given direction, to the given Room. |
boolean |
contains(Thing thing)
Tests whether the given Thing is in this Room. |
java.util.Vector |
contents()
|
java.util.Vector |
exits()
|
java.lang.String |
getDescription()
Returns the full description of this Room. |
static Room |
getRoom(java.lang.String name)
|
boolean |
isPath(java.lang.String direction)
Tests whether there is a path from this Room in the indicated direction. |
Room |
nextRoom(java.lang.String direction)
Returns the Room that will be reached if you go in the given direction from this Room. |
void |
remove(Thing thing)
Removes the given Thing from this Room. |
void |
removePath(java.lang.String direction)
Removes the path going from this Room in the given direction. |
void |
setDescription(java.lang.String description)
Replaces the description of this Room with something more appropriate. |
java.util.Iterator |
thingIterator()
Returns an iterator for the Things in the room. |
java.lang.String |
toString()
Returns the name of this Room. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
private java.lang.String name
private java.lang.String description
private java.util.Hashtable paths
private java.util.Vector contents
private static java.util.Hashtable rooms
| Constructor Detail |
public Room(java.lang.String name)
| Method Detail |
public java.lang.String toString()
toString in class java.lang.Objectpublic static Room getRoom(java.lang.String name)
public java.lang.String getDescription()
public void setDescription(java.lang.String description)
description - One or more complete sentences describing this Room.
public void addPath(java.lang.String direction,
Room destination)
If there was a prior path in that direction, it is replaced by the new one.
direction - One of "north", "south", "east", "west", "up", or "down".destination - To what room the direction leads.public void removePath(java.lang.String direction)
If there is no path in the given direction, this method does nothing.
direction - One of "north", "south", "east", "west", "up", or "down".public boolean isPath(java.lang.String direction)
direction - One of "north", "south", "east", "west", "up", or "down".public Room nextRoom(java.lang.String direction)
direction - One of "north", "south", "east", "west", "up", or "down".public java.util.Iterator thingIterator()
public void add(Thing thing)
thing - The thing to be placed in the room.public void remove(Thing thing)
thing - The thing to be removed the room.public boolean contains(Thing thing)
thing - The Thing to look for in this Room.public java.util.Vector contents()
public java.util.Vector exits()
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||