Java Reference
In-Depth Information
Code 6.5
continued
Source code of the
Room class
public Room(String description)
{
this .description = description;
exits = new HashMap<String, Room>();
}
/**
* Define the exits of this room. Every direction either
* leads to another room or is null (no exit there).
*/
public void setExits(Room north, Room east, Room south,
Room west)
{
if (north != null )
exits.put( "north" , north);
if (east != null )
exits.put( "east" , east);
if (south != null )
exits.put( "south" , south);
if (west != null )
exits.put( "west" , west);
}
/**
* 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.
*/
public Room getExit(String direction)
{
return exits.get(direction);
}
/**
* Return the description of the room (the one that was
* defined in the constructor).
*/
public String getDescription()
{
return description;
}
}
Search WWH ::




Custom Search