|
||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectVroomba
public class Vroomba
A Vroomba models a virtual robotic vacuum cleaner.
Vroombas are usually used to clean a Room
.
A Vroomba is always on, so any DIRT it moves over is always removed,
leaving spotlessly clean FLOORs behind!
A Vroomba moves in a turn-based way, deciding which direction to head next each time its move method is called. Because its sensors are short-ranged, the move method only tells the Vroomba what is in its surrounding 8 "squares".
A Vroomba may or may not try to internally map the room based on the information it receives each move/turn. When a Vroomba believes the room to be clean, it may decline to move further. Not all Vroombas stop on their own, however; some just keep cleaning until turned off.
A variety of different Vroombas can be created by extending this class.
Room
,
Direction
Constructor Summary | |
---|---|
Vroomba()
|
Method Summary | |
---|---|
Direction |
move(char[] surroundings)
Provides this Vroomba its current surroundings and asks it to choose a direction to move. |
void |
reset()
Instructs this Vroomba to reset itself, such as when it is being transferred to a new room. |
protected void |
validateSurroundings(char[] surroundings)
Handy for double-checking that passed surroundings are valid (though the only reason they wouldn't be is programmer error somewhere). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Vroomba()
Method Detail |
---|
public Direction move(char[] surroundings) throws IllegalArgumentException
The surroundings should contain 8 entries, for
This Vroomba will then return the Direction it would like to move.
If it no longer wishes to move (usually because it believes its containing
Room is clean), it may return Direction.HERE to stop.
This behavior will depend on the overriding performed by any specific,
extending Vroomba. This default Vroomba always returns Direction.HERE.
surroundings[Direction.N.ordinal()],
surroundings[Direction.NE.ordinal()], surroundings[Direction.E.ordinal()],
... surroundings[Direction.NW.ordinal()].
Each character contained should be a valid feature of a Room.
IllegalArgument
- if the passed surroundings are invalid
IllegalArgumentException
public void reset()
This method currently does nothing. It needs to be overridden only by Vroombas that attempt to maintain state about the room they are currently in.
protected void validateSurroundings(char[] surroundings) throws IllegalArgumentException
Returns if everything's fine, or throws an IllegalArgumentException if not.
IllegalArgumentException
move(char[])
|
||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |