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)

  1. This is a Critter, so don't touch the act method.
  2. Which of the 5 methods in act should you change?
  3. Remember not to change the state in certain methods... like getActors
  4. You can process other AttractiveCritters, but should you include yourself? no (you move like a Critter, remember?)
  5. Remember, you can get the occupied Locations from the grid, but it is up to you to get the Actors in those Locations
  6. While processing actors, remember to check if their new location is valid, and not off the grid
  7. While processing actors, remember to check if their new location isn't already occupied.
  8. How do you tell the processed actor to go to the new Location? move or moveTo?