An instance of the BuggleWorld
class represents
a world consisting of a grid of cells that may be inhabited
by buggles and their bagels.
BuggleWorld programs are specified by declaring subclasses of
BuggleWorld
that override the default (do-nothing)
run
method. This method will be executed
when the Run button is pressed in an instance
of BuggleWorld
.
Instance Variables
public int rows
The number of rows in the BuggleWorld grid.
public int cols
The number of columns in the BuggleWorld grid.
Instance Methods
public void run ()
Execute specified buggle actions in this buggle world.
By default, this method does nothing, but it can be overridden by subclasses.
public void setDimensions (int c, int r)
Change the number of columns in the grid to be c
and
the number of rows to be r
.
public void setup()
Execute initialization actions to be performed when a BuggleWorld instance is created.
By default, this method does nothing, but it can be overridden by subclasses.
The only BuggleWorld state setup()
should manipulate
is rows
and cols
, typically by invoking
setDimensions()
. setup()
is also often used
to created ParameterFrames for specifying attributes of BuggleWorld
subclasses.
public void reset()
Initialize the state of this BuggleWorld instance.
The default reset()
method initializes
(but does not draw) the walls, buggles, bagels in a
BuggleWorld grid based on the values of
rows
and cols
.
This method may be overridden, but must invoke
super.reset()
to perform the basic state
initialization. No state other than rows
and cols
may be assumed to exist before super.reset()
is called.
But after super.reset()
is called, new walls, bagels,
and buggles may be created. The reset()
method should not
cause any drawing to occur.
Class Methods
public static void runAsApplication (final BuggleWorld applet, final String name)
Run BuggleWorld applet
as a stand-alone Java application within a window with name name
.
BuggleWorld applets are often easier to test and debug as applications. Many systems require a browser to view applets, and the applet-caching behavior of many browsers makes it necessary to quit and restart a browser every time an edit to an applet is made.