GridWorld Case Study Part 3 GridWorld Classes and Interfaces A Summary by Jim Mims
Contents Introduction Part 1: Observing and Experimenting with GridWorld Part 2: Bug Variations Part 3: GridWorld Classes and Interfaces Part 4: Classes that Extend the Critter Class Part 5: Grid Data Structures
Classes and Interfaces: Relationships
Introduction The case study provides a graphical environment where visual objects inhabit and interact in a two-dimensional grid. Students design and creator actor objects, add them to a grid, and determine whether they behave according to specifications.
GridWorld Classes and Interfaces: Location Class Encapsulates coordinates for an actors position in the grid Every actor has a position and a direction Class provides 8 constants that specify compass directions Class provides 7 constants for turn directions
GridWorld Classes and Interfaces: Grid Interface Specifies the method for any grid that contain objects of type E BoundedGrid and UnboundedGrid implement the interface Methods allow you to put objects into a grid remove them get reference to an object in the grid Four other methods are used to collect information ref neighbors
GridWorld Classes and Interfaces: Actor Class Accessor methods provide information concerning state of the actor getColor getDirection) getGrid() getLocation() Mutator methods enable an actor to add or remove itself from a grid putSelfInGrid() removeSElfFromGrid() Additional methods that can be used setColor() setDirection() act()
GridWorld Classes and Interfaces: Extending Actor Class Bug, Flower, Rock classes override act method of the Actor class The behavior of these class is specified by how they override act()
Graphical User Interface is Not Tested World class makes connection between GUI and classes that are tested ActorWorld is a subclass of World ActorWorld provides a step method that invokes act on each actor Other worlds can be defined that contain occupants other than actors