Class AdvRoom

Object
  extended by AdvRoomMagicSuperclass
      extended by AdvRoom

public class AdvRoom
extends AdvRoomMagicSuperclass

This class defines a single room in the Adventure game. A room is characterized by the following properties:

The external format of the room file is described in the assignment handout.


Method Summary
 void addObject(AdvObject obj)
          Adds an object to the list of objects in the room.
 boolean containsObject(AdvObject obj)
          Checks whether the specified object is in the room.
 String[] getDescription()
          Returns a string array giving the long description of the room.
 AdvMotionTableEntry[] getMotionTable()
          Returns the motion table associated with this room, which is an array of directions, room numbers, and key objects stored in an AdvMotionTableEntry.
 String getName()
          Returns the room name, which is its one-line description.
 AdvObject getObject(int index)
          Returns the specified element from the list of objects in the room.
 int getObjectCount()
          Returns the number of objects in the room.
 int getRoomNumber()
          Returns the room number.
 boolean hasBeenVisited()
          Returns true if the room has previously been visited.
static AdvRoom readRoom(BufferedReader rd)
          Creates a new room by reading its data from the specified reader.
 void removeObject(AdvObject obj)
          Removes an object from the list of objects in the room.
 void setVisited(boolean flag)
          Sets a flag indicating whether this room has been visited.
 
Methods inherited from class AdvRoomMagicSuperclass
toString
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getRoomNumber

public int getRoomNumber()
Returns the room number.

Overrides:
getRoomNumber in class AdvRoomMagicSuperclass
Returns:
The room number

getName

public String getName()
Returns the room name, which is its one-line description.

Overrides:
getName in class AdvRoomMagicSuperclass
Returns:
The room name

addObject

public void addObject(AdvObject obj)
Adds an object to the list of objects in the room.

Overrides:
addObject in class AdvRoomMagicSuperclass
Parameters:
obj - The AdvObject to be added

removeObject

public void removeObject(AdvObject obj)
Removes an object from the list of objects in the room.

Overrides:
removeObject in class AdvRoomMagicSuperclass
Parameters:
obj - The AdvObject to be removed

containsObject

public boolean containsObject(AdvObject obj)
Checks whether the specified object is in the room.

Overrides:
containsObject in class AdvRoomMagicSuperclass
Parameters:
obj - The AdvObject being tested
Returns:
true if the object is in the room

getObjectCount

public int getObjectCount()
Returns the number of objects in the room.

Overrides:
getObjectCount in class AdvRoomMagicSuperclass
Returns:
The number of objects in the room

getObject

public AdvObject getObject(int index)
Returns the specified element from the list of objects in the room.

Overrides:
getObject in class AdvRoomMagicSuperclass
Returns:
The AdvObject at the specified index position

getDescription

public String[] getDescription()
Returns a string array giving the long description of the room.

Overrides:
getDescription in class AdvRoomMagicSuperclass
Returns:
A string array giving the long description of the room

setVisited

public void setVisited(boolean flag)
Sets a flag indicating whether this room has been visited. Calling setVisited(true) means that the room has been visited; calling setVisited(false) restores its initial unvisited state.

Overrides:
setVisited in class AdvRoomMagicSuperclass
Parameters:
flag - The new state of the "visited" flag

hasBeenVisited

public boolean hasBeenVisited()
Returns true if the room has previously been visited.

Overrides:
hasBeenVisited in class AdvRoomMagicSuperclass
Returns:
true if the room has been visited

getMotionTable

public AdvMotionTableEntry[] getMotionTable()
Returns the motion table associated with this room, which is an array of directions, room numbers, and key objects stored in an AdvMotionTableEntry.

Overrides:
getMotionTable in class AdvRoomMagicSuperclass
Returns:
The array of motion table entries associated with this room

readRoom

public static AdvRoom readRoom(BufferedReader rd)
Creates a new room by reading its data from the specified reader. If no data is left in the reader, this method returns null instead of an AdvRoom value. Note that this is a static method, which means that you need to call

     AdvRoom.readRoom(rd)

Parameters:
rd - The reader from which the room data is read