ROOM:
Code
public interface IRoom
{
String getId();
String getDescription();
boolean canGoNorth();
boolean canGoSouth();
boolean canGoEast();
boolean canGoWest();
ILamp getLamp();
void clearLamp();
IKey getKey();
void clearKey();
IChest getChest();
boolean isDark();
boolean hasLamp();
boolean hasKey();
boolean hasChest();
}
Code
public class Room implements IRoom
{
private String description;
private boolean north;
private boolean south;
private boolean east;
private boolean west;
private boolean isDark;
private ILamp theLamp;
private IKey theKey;
private IChest theChest;
private String id;
public Room(String description, boolean north, boolean south, boolean east,
boolean west, boolean isDark, ILamp theLamp, IKey theKey,
IChest theChest, String id)
{
this.description = description;
this.north = north;
this.south = south;
this.east = east;
this.west = west;
this.isDark = isDark;
this.theLamp = theLamp;
this.theKey = theKey;
this.theChest = theChest;
this.id = id;
}
/**
* Returns the text description of this room
*/
public String getDescription() {
return description;
}
/**
* Returns true if the player can go north from this room
*/
public boolean canGoNorth() {
return north;
}
/**
* Returns true if the player can go south from this room
*/
public boolean canGoSouth() {
return south;
}
/**
* Returns true if the player can go east from this room
*/
public boolean canGoEast() {
return east;
}
/**
* Returns true if the player can go west from this room
*/
public boolean canGoWest() {
return west;
}
/**
* Returns the lamp object in this room.
* If no lamp is present, returns null
*/
public ILamp getLamp() {
return theLamp;
}
/**
* Sets the lamp variable in this room to null
*/
public void clearLamp() {
theLamp = null;
}
/**
* Returns the key object in this room.
* If no key is present, returns null
*/
public IKey getKey() {
return theKey;
}
/**
* Sets the key variable in this room to null
*/
public void clearKey() {
theKey = null;
}
/**
* Returns the chest object in this room.
* If no chest is present, returns null
*/
public IChest getChest() {
return theChest;
}
/**
* Returns true if there is no light in this room,
* veeeeeeeery dangerous!
*/
public boolean isDark() {
return isDark;
}
public boolean hasLamp()
{
return theLamp != null;
}
public boolean hasKey()
{
return theKey != null;
}
public boolean hasChest()
{
return theChest != null;
}
public String getId()
{
return id;
}
}
Code
public interface IRoomFactory
{
IRoom createRoom(String description, boolean north, boolean south, boolean east,
boolean west, boolean isDark, ILamp theLamp, IKey theKey,
IChest theChest, String id);
}
Code
public class RoomFactory implements IRoomFactory
{
public IRoom createRoom(String description, boolean north, boolean south, boolean east,
boolean west, boolean isDark, ILamp theLamp, IKey theKey,
IChest theChest, String id)
{
return new Room(description, north, south, east,
west,isDark, theLamp, theKey,
theChest, id);
}
}