gpsys.lawnmower
Class Lawn

java.lang.Object
  |
  +--gpsys.lawnmower.Lawn

public class Lawn
extends java.lang.Object
implements java.io.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.

Version:
$Revision: 1.1 $, $Date: 2000/07/05 16:26:49 $
Author:
Adil Qureshi
Department of Computer Science,
University College London,
Gower St,
London WC1E 6BT,
UK.
See Also:
LawnObserver, Serialized Form

Field Summary
static int CUT
          Used to tag squares on the lawn as having been cut.
(package private)  int cutCount
          Used to keep a count of how many squares have been cut.
(package private)  int[][] lawn
          Used to hold the state of each square of the lawn.
(package private)  boolean observed
          True if the observer is wants to received state change information.
(package private)  LawnObserver observer
          A reference to an observer interested in monitoring the state of this lawn.
static int UNCUT
          Used to tag squares as not having been cut.
 
Constructor Summary
Lawn(int dimension)
          Create a square lawn of the specified dimension, with no observer.
 
Method Summary
 void cut(int x, int y)
          Sets the specified square on the lawn to the CUT state, and informs the observer of the event.
 int cutCount()
          Gets a count of the number of squares on the lawn in the CUT state.
 void disableObserver()
          Disables the observer from receiving change messages.
 void enableObserver()
          Enables the observer to receive change messages.
 void grow()
          Sets the all of the squares on the lawn to UNCUT state (grown).
 void setObserver(LawnObserver lo)
          Set the observer of the lawn to the specified observer.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

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.
Constructor Detail

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.
Method Detail

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.