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

Variable Index

 o CUT
Used to tag squares on the lawn as having been cut.
 o cutCount
Used to keep a count of how many squares have been cut.
 o lawn
Used to hold the state of each square of the lawn.
 o observed
True if the observer is wants to received state change information.
 o observer
A reference to an observer interested in monitoring the state of this lawn.
 o UNCUT
Used to tag squares as not having been cut.

Constructor Index

 o Lawn(int)
Create a square lawn of the specified dimension, with no observer.

Method Index

 o cut(int, int)
Sets the specified square on the lawn to the CUT state, and informs the observer of the event.
 o cutCount()
Gets a count of the number of squares on the lawn in the CUT state.
 o disableObserver()
Disables the observer from receiving change messages.
 o enableObserver()
Enables the observer to receive change messages.
 o grow()
Sets the all of the squares on the lawn to UNCUT state (grown).
 o setObserver(LawnObserver)
Set the observer of the lawn to the specified observer.

Variables

 o lawn
 int lawn[][]
Used to hold the state of each square of the lawn.

 o cutCount
 int cutCount
Used to keep a count of how many squares have been cut.

 o observed
 transient boolean observed
True if the observer is wants to received state change information.

 o observer
 transient LawnObserver observer
A reference to an observer interested in monitoring the state of this lawn.

 o CUT
 public static final int CUT
Used to tag squares on the lawn as having been cut.

 o UNCUT
 public static final int UNCUT
Used to tag squares as not having been cut.

Constructors

 o 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.

Methods

 o setObserver
 public void setObserver(LawnObserver lo)
Set the observer of the lawn to the specified observer.

Parameters:
lo - The observer of the lawn.
 o 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.

 o 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.
 o 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.
 o enableObserver
 public void enableObserver()
Enables the observer to receive change messages.

 o disableObserver
 public void disableObserver()
Disables the observer from receiving change messages.


All Packages  Class Hierarchy  This Package  Previous  Next  Index