GridWorld is a computer program case study written in Java for use with the AP Computer Science program.[1] It serves as an example of object-oriented programming (OOP) embedded in a more complicated design project than most students have worked with before. GridWorld is the successor to the Marine Biology Simulation Case Study, which was used from 2000–2007.
The GridWorld framework was designed and implemented by Cay Horstmann, based on the Marine Biology Simulation Case Study. The narrative was produced by Chris Nevison and Barbara Cloud Wells, Colgate University.
Contents |
The GridWorld Case Study employs an Actor class to construct objects in the grid. The Actor class manages the object's color, direction, location, what the object does in the simulation, and how the object interacts with other objects.
Actors are broken down into the classes "Flower", "Rock", "Bug", and "Critter", which inherit the Actor class and often override certain methods (most notably the Act method). Flowers can't move, and when forced to Act, they become darker. Flowers are dropped by Bugs and eaten by Critters. Rocks are also immobile and aren't dropped or eaten. Bugs move directly ahead of themselves, unless blocked by a rock or another bug, in which case the Bug will make a 45 degree turn and try again. They drop flowers in every space they occupy, eat flowers that are directly on their space of grid, and are consumed by Critters. Critters move in a random direction to a space that isn't occupied by a Rock or other Critter and consume Flowers and Bugs.
The Case Study also includes several extensions of the above classes. "BoxBug" extends "Bug" and moves in a box shape if its route is not blocked. "ChameleonCritter" extends "Critter" and does not eat other Actors, instead changing its color to match the color one of its neighbors. "Crab Critter" moves left or right and only eats Actors in front of it, but otherwise extends the "Critter" class.
Students often create their own extensions of the Actor class. Some common examples of student created extensions are Warden organisms and SimCity-like structures, in which objects of certain types create objects of other types based on their neighbors (much like the game of Life). Students have even created a version of the games Pac-Man, Fire Emblem, and Tetris.