
ShorterNameGenComplete
By:
ace on
Apr 9th, 2010 | syntax:
None | size: 1.37 KB | hits: 24 | expires: Never
import java.util.HashMap;
// class comment omitted
class Room
{
private String description;
private HashMap<Room> exits;
/**
* Create a room described "description". Initially, it has
* no exits. "description" is something like "a kitchen" or
* "an open court yard".
*/
public Room(String description)
{
this.description = description;
exits = new HashMap<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;
}
}