Gridworld+Case+Study

The Gridworld Case Study

1. The classes: hierarchy and overview

2. The Actor class - description and methods setColor, setDirection getColor, getLocation, getGrid, getDirection,
 * The Actor Class creates an actor object; a blue actor facing north.
 * It is the parent class for the bug, rock, flower, critter, boxbug, and chameleon critter classes.
 * It has the basic methods to set the color and direction of the objects:
 * It has the basic, acessor methods that get the color, location, grid position, and direction of the objects:
 * The actor is added and removed from the grid by using the putSelfInGrid and removeSelfFromGrid methods, respectively.
 * The two other methods in this class are act and moveTo, these are mostly used in the actors subclasses (see below), to be extended to accomodate actors with different behavior.

3. The Location class - description and methods

The location class encapsulates the coordinates for an actor's position on a grid. It also provides methods that determine the relationship between locations and compass directions. The eight constants for compass location are:
 * North = 0
 * East = 90
 * South = 180
 * West = 270
 * Northeast = 45
 * Southeast = 135
 * Southwest = 225
 * Northwest = 315

There are also constants for the turn angles:
 * LEFT = -90
 * RIGHT = 90
 * HALF_LEFT = -45
 * HALF_RIGHT = 45
 * FULL_CIRCLE = 360
 * HALF_CIRCLE = 180
 * AHEAD = 0

The methods include:
 * setDirection(getDirection + Location.HALF_RIGHT);
 * public Location getAdjacentLocation(int direction)
 * public int getDirectionToward(Location target)

The parameters for the location constructor are: public Location(int r, int c)

Two accessor methods that return the row and column for a location are: public int getRow public int getCol

4. The Rock and Flower classes - description and methods

The rock does nothing at all. The act method has an empty body. The flower acts by darkening but not moving at all. The act method reduces the value of the red, green, or blue by a constant amount.

5. The Bug and Boxbug classes - description and methods

A bug acts by moving forward and leaving a flower behind in its place. The bug class has three methods which specify how bugs move and turn. All of these methods are located in the act method.
 * canMove - tests if the bug can move forward into an empty space
 * move - moves the bug forward and leaves a flower in the previous location
 * turn - turns the bug 45 degrees

A boxBug uses the same exact methods as bug but overrides the act method. It uses the same methods and moves in a box format. It also has 2 instance variables, sideLength and steps, to keep track of its movement.

6. The Critter and Chameleon Critter class - description and methods 7. The Grid Interface - description and methods 8. The AbstractGrid class - description and methods 9. The BoundedGrid and UnboundedGrid classes - description and methods
 * bounded grid: stores the occupants of the grid into a two-dimensional array
 * unbounded grid: stores occupants into Map where E is the type of occupants in the grid