Download presentation
Presentation is loading. Please wait.
Published byAntonio McLaughlin Modified over 11 years ago
1
GridWorld Case Study The Classes A Summary by Jim Mims
2
Contents Tested Implementations (method bodies or definitions) Tested APIs (application programming interfaces) Not Tested
3
Classes and Interfaces: Relationships
4
Tested Implementations AbstractGrid Contains the methods that are common to grid implementations. BoundedGrid A rectangulr grid with a finite number of rows and columns. BoxBug A BoxBug traces out a rectangular box of a given size. Bug A Bug is an actor that an move and turn. It drops flowers as it moves. ChameleonCritter A ChameleonCritter takes on the color of neighboring actors as it moves through the grid.
5
Tested Implementations (continued) Critter A critter is an actor that moves through its world, processing other actors in some way and then picking a new location UnboundedGrid An UnboundedGrid is a rectangular grid with an unbounded number of rows and columns
6
Tested APIs Actor An Actor is an entity that can act. It has a color and direction. Flower A Flower is an actor that darkens over time. Some actors drop flowers as they move. Rock A Rock is an actor that does nothing. It is commonly used to block othre actors from moving. Grid Grid provides an interface for a two-dimensional grid-like environment containing arbitrary objects. Location A Location object represents the row and column of a location in a two-dimensional grid.
7
Not Tested ActorWorld An ActorWorld is occupied by actors. BoxBugRunner This class runs a world that contains box bugs. BugRunner This class runs a world that contains a bug and a rock, added at random locations. ChameleonRunner This class runs a world that ocntains chameleon critters.
8
Not Tested (continued) CrabCritter A CrabCritter looks at a limited set of neighbors when it eats and moves. CrabRunner This class runs a world that contains crab critters. CritterRunner This class runs a world that contains critters. World A world is the mediator between a grid and the GridWorld GUI.
9
Summary Tested Implementations: 7 Tested APIs: 5 Not Tested: 4
10
The Classes - Methods
11
Location Class: Implements Comparable (concrete) public Location(int r, int c) public int getRow() public int getCol() public Location getAdjacentLocation(int direction) public int GetDirectionToward(Location target) public boolean equals(Object other) public int hashCode() public int compareTo(Object other) public String toString() NORTH, EAST, SOUTH, WEST, NORTHEAST, SOUTHEAST, NORTHWEST, SOUTHWEST, LIEF, RIGHT, HALF_LEFT, HALF_RIGHT, FULL_CIRCLE, HALF_CIRCLE, AHEAD
12
Grid Interface: uses Location int getNumRows int getNumCols) boolean isValidLocation loc) E put(Location loc, E obj) E remove(Location loc) E get(Location loc) ArrayList getOccupiedLocations) ArrayList getValidAdjacentLocations(Location loc) ArrayList getEmptyAdjacentLocations(Location loc) ArrayList getOccupiedAdjacentLocations(Location loc) ArrayList getNeighbors(Location loc) what is the difference between the last 2?
13
AbstractGrid
14
AbstractGrid: Implements Grid public ArrayList getNeighbors(Location loc) public ArrayList getValidAdjacentLocations(Location loc) public ArrayList getEmptyAdjacentLocation(Location loc) public ArrayList getOccupiedAdjacentLocations(Location loc) public Sgtring toString()
15
BoundedGrid: extends AbstractGrid public BoundedGrid(int rows, int cols) public int getNumRows() public int getNumCols() public boolean isValid(Location loc) public ArrayList getOccupiedLocations() public E get(Location loc) public E put(Location loc) public E remove(Location loc) BoundedGrid: extends AbstractGrid public UnBoundedGrid( ) public int getNumRows() public int getNumCols() public boolean isValid(Location loc) public ArrayList getOccupiedLocations() public E get(Location loc) public E put(Location loc) public E remove(Location loc)
16
Actor
17
Actor uses Location and Grid public Actor() public Color getColor() public void setColor(Color newColor public int getDirection() public voiid setDirection (int newDirection) public Grid getGrid() public Location getLocation() public void putSelfInGrid(Grid gr, Location loc) public void removeSelfFromGrid() public void moveTo(Location newLocation) public void act() public String toString()
18
Critter extends Actor public void act() public ArrayList getActors() public void processActors(ArrayList actors public ArrayList getMoveLocations() puboic Location selectMoveLocation(ArrayList locs) public void makeMove(Location loc
19
ChameleonCritter extends Critter public void processActors(rrayList actors) public void makeMove(Location loc)
20
CrabCritter extends Critter Note tested
21
Bug, Flower, and Rock
22
Bug extends Actor public Bug() public Bug(Color bugColor) public void act() public void turn() puiblic void move() public boolean canMove() Flower extends Actor public Flower() public Flower(Color initialColor) public void act() Rock extends Actor public Rock() public Rock(Color rockColor) public void act()
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.