Download presentation
Presentation is loading. Please wait.
Published byMaya Coughlin Modified over 11 years ago
1
GridWorld Case Study Part 2 Bug Variations A Summary by Jim Mims
2
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
3
Classes and Interfaces: Relationships
4
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.
5
Bug Class Methods public boolean canMove() tests whether the bug can move forward into a location that is empty or contains a flower public void move() moves the bug forward, putting a flower into the location it previously occupied public void turn() turns the bug 45 degrees to the right without changing its position
6
Extending Bug Class – BoxBug Class Moves in a square pattern No new methods need to be added Act method uses the 3 methods listed previously BoxBug class has 2 instance variables, sideLength and steps
7
Runner Classes A runner class is added to observe the behavior of one or more actors Runner class constructs an ActorWorld object places actors in it shows the world Act method uses the 3 methods listed previously For the bug, this class is BugRunner When you write your own classes that extend bug, you need to create a similar runner class
8
BoxBug Runner
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.