All Packages Class Hierarchy This Package Previous Next Index
Class gpsys.lawnmower.Lawn
java.lang.Object
|
+----gpsys.lawnmower.Lawn
- public class Lawn
- extends Object
- implements Serializable
The lawn consists of a torroidal grid of squares upon which the "grass
grows". The lawn can be grown, and cut. In addition, an observer can be
set which gets update messages each time the state of the lawn changes.
- Author:
- Adil Qureshi
Department of Computer Science,
University College London,
Gower St,
London WC1E 6BT,
UK.
- See Also:
- LawnObserver
-
CUT
- Used to tag squares on the lawn as having been cut.
-
cutCount
- Used to keep a count of how many squares have been cut.
-
lawn
- Used to hold the state of each square of the lawn.
-
observed
- True if the observer is wants to received state change information.
-
observer
- A reference to an observer interested in monitoring the state of this
lawn.
-
UNCUT
- Used to tag squares as not having been cut.
-
Lawn(int)
- Create a square lawn of the specified dimension, with no observer.
-
cut(int, int)
- Sets the specified square on the lawn to the CUT state, and informs the
observer of the event.
-
cutCount()
- Gets a count of the number of squares on the lawn in the CUT state.
-
disableObserver()
- Disables the observer from receiving change messages.
-
enableObserver()
- Enables the observer to receive change messages.
-
grow()
- Sets the all of the squares on the lawn to UNCUT state (grown).
-
setObserver(LawnObserver)
- Set the observer of the lawn to the specified observer.
lawn
int lawn[][]
- Used to hold the state of each square of the lawn.
cutCount
int cutCount
- Used to keep a count of how many squares have been cut.
observed
transient boolean observed
- True if the observer is wants to received state change information.
observer
transient LawnObserver observer
- A reference to an observer interested in monitoring the state of this
lawn.
CUT
public static final int CUT
- Used to tag squares on the lawn as having been cut.
UNCUT
public static final int UNCUT
- Used to tag squares as not having been cut.
Lawn
public Lawn(int dimension)
- Create a square lawn of the specified dimension, with no observer.
- Parameters:
- dimension - The value to be used for both the height and width
of the lawn.
setObserver
public void setObserver(LawnObserver lo)
- Set the observer of the lawn to the specified observer.
- Parameters:
- lo - The observer of the lawn.
grow
public final void grow()
- Sets the all of the squares on the lawn to UNCUT state (grown). The
observer is notified of this change.
cut
public final void cut(int x,
int y)
- Sets the specified square on the lawn to the CUT state, and informs the
observer of the event.
- Parameters:
- x - The X coordinate of the square to be cut.
- y - The Y coordinate of the square to be cut.
cutCount
public final int cutCount()
- Gets a count of the number of squares on the lawn in the CUT state.
- Returns:
- The number of squares on the lawn in the CUT state.
enableObserver
public void enableObserver()
- Enables the observer to receive change messages.
disableObserver
public void disableObserver()
- Disables the observer from receiving change messages.
All Packages Class Hierarchy This Package Previous Next Index