|
||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectRoom
public class Room
Provides a virtual room for a Vroomba to clean.
When a Room is created, it must contain a Vroomba. The Room's
clean()
method will then instruct that Vroomba to clean
the room, monitoring its progress.
The details of a room's geography are specified by a map of characters.
Room maps are normally read from file, but can be specified directly
as a 2D array of appropriate characters. Acceptable room features
(walls, empty floor, etc) are listed by this class as
char
constants.
Every map must include at least one square of floor space. If the map does not specify the location of the contained Vroomba, the Vroomba will be placed randomly on the floor. A map does not need to specify its borders with walls; any location off the map is assumed to be a WALL.
When instructing a Vroomba to clean, a Room monitors each move of the
Vroomba. It will stop the cleaning if the Vroomba should move over a DROP,
crash 3 consecutive times into the same obstruction, fail to move at all,
or exceeds the max number of moves allowed. Max moves are determined from
the amount of floor to clean and the MAX_MOVES_MODIFIER
.
Nested Class Summary | |
---|---|
class |
Room.GUI
Provides a graphical view of a Room and its cleaning process. |
static class |
Room.Result
An enumeration of the various possible outcomes of a Vroomba cleaning a room. |
Field Summary | |
---|---|
static char |
DIRT
|
static char |
DROP
|
static char |
FLOOR
|
static int |
MAX_MOVES_MODIFIER
A Vroomba must finish cleaning any room within (MAX_MOVES_MODIFIER * this.floorSpaces) moves. |
static char |
VROOMBA
|
static char |
WALL
|
Constructor Summary | |
---|---|
Room(char[][] map,
Vroomba v)
Construct a new Room with the given map, to be cleaned by the given Vroomba. |
|
Room(String mapFilename,
Vroomba v)
Constructs a room by loading the given file and using the given Vroomba. |
Method Summary | |
---|---|
String |
clean()
Has this room cleaned by its occupying Vroomba. |
protected int |
count(char feature)
Counts the number of times the given char is found in the current room map. |
int |
getCollision()
Returns the number of collisions this Room's Vroomba has had so far. |
protected char |
getFeature(Direction d)
Returns the room feature currently in the given direction from this Room's Vroomba. |
protected char |
getFeature(int row,
int col)
Returns the room feature at the given location in this room. |
int |
getMaxMoves()
Returns the maximum number of moves a Vroomba is allowed for this Room. |
int |
getMoves()
Returns the number of moves this Room's Vroomba has currently made. |
Room.Result |
getResult()
Returns the result of cleaning this room. |
String |
getStatus()
Returns the current status of this Room's Vroomba's cleaning performance as a single line of text. |
String |
getStatus(boolean asMove)
Returns the current status, formatted as per getStatus() . |
boolean |
isClean()
Returns whether this room currently contains any DIRT. |
protected boolean |
moveVroomba()
Instructs this room's Vroomba to take a turn of cleaning. |
String |
toString()
Returns a snapshot of this Room's current map as a string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final char FLOOR
public static final char DIRT
public static final char WALL
public static final char DROP
public static final char VROOMBA
public static final int MAX_MOVES_MODIFIER
(MAX_MOVES_MODIFIER * this.floorSpaces)
moves.
Current default: 3.
Constructor Detail |
---|
public Room(char[][] map, Vroomba v) throws InvalidMapException
Verifies that the map is valid: It must not contain any unrecoginzed chars. Every row of the map must be the same length. A map may not contain more than a single 'V' character, which is where the given Vroomba should be initially placed. If no such 'V' is found, the Vroomba will be placed randomly on the floor somewhere (on either a FLOOR or DIRTy square).
Thus, every map must contain at least one VROOMBA, FLOOR, or DIRT character.
InvalidMapException
- if the given map is invalidpublic Room(String mapFilename, Vroomba v) throws FileNotFoundException, InvalidMapException
The contents of the file will be converted to a 2D array of characters. File must exist, be readable, and contain a valid map.
FileNotFoundException
- if the given file does not exist
InvalidMapException
- if file does not contain a valid mapRoom(char[][], Vroomba)
Method Detail |
---|
public String clean()
moveVroomba()
for more.
Once called, additional calls to clean()
do nothing
and will return null.
Returns a transcript of the cleaning session as formed by
a call of getStatus()
every turn. The transcript includes
only moves, however, and does not include the finished result.
public int getCollision()
public int getMaxMoves()
public int getMoves()
public Room.Result getResult()
public String getStatus()
If still cleaning, the line returned will begin with "CLEANING:" and the direction of the last move. If done, the line will instead begin with "RESULT:" and the completion status. In either case, line also includes the number of moves made over the max allowed moves, as well as the number of collisions.
public String getStatus(boolean asMove)
getStatus()
.
However, if asMove
is true, will print the status
as if the Vroomba were still cleaning. This allows for printing
of the last move a Vroomba made before finishing the cleaning.
public boolean isClean()
public String toString()
toString
in class Object
protected int count(char feature)
protected char getFeature(int row, int col)
protected char getFeature(Direction d)
protected boolean moveVroomba()
Passes this room's Vroomba its current surroundings by calling
its Vroomba.move(char[])
method and then attempts to move
it in its requested direction.
After each move, determines whether the Vroomba is done cleaning. It is done if it chooses to move to Direction.HERE, if it has exceeded its max number of moves, if it goes over a drop, or if it crashes into the same obstruction from the same direction for 3 consecutive moves.
Returns whether this Vroomba needs to move again because it is not done cleaning.
|
||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |