2011 Attractive Critter
<< 2011 Sound | APQuestionsTrailIndex | 2011 FuelTank >>
Question 2 from 2011 asks you to write a GridWorld class called AttractiveCritter.
Click here to see the questions from 2011
Here is a 96 x 96 gif file 'AttactiveCritter.gif' so your working code looks like the College Board's example (if you download it to the correct location of your project):
AttractiveCritterRunner.java
import info.gridworld.actor.*;
import info.gridworld.grid.*;
import java.awt.Color;
public class AttractiveCritterRunner
{
public static void main(String[] args)
{
ActorWorld world = new ActorWorld();
world.setGrid(new BoundedGrid<Actor>(5,5));
world.add(new Location(4, 2), new Rock());
world.add(new Location(1, 1), new Flower(Color.BLUE));
world.add(new Location(1, 2), new AttractiveCritter());
world.show();
}
}
AttractiveCritter.java
import info.gridworld.actor.*;
import info.gridworld.grid.*;
import java.util.ArrayList;
public class AttractiveCritter extends Critter
{
}
Hints (if you need them)
- This is a
Critter, so don't touch theactmethod. - Which of the 5 methods in
actshould you change? - Remember not to change the state in certain methods... like
getActors - You can process other
AttractiveCritters, but should you include yourself? no (you move like aCritter, remember?) - Remember, you can get the occupied
Locationsfrom the grid, but it is up to you to get theActors in thoseLocations - While processing actors, remember to check if their new location is valid, and not off the grid
- While processing actors, remember to check if their new location isn't already occupied.
- How do you tell the processed actor to go to the new Location? move or moveTo?
