Pigeon Critter
<< Missile | GridworldTrailIndex | BlackHoleCritter >>
Watch a PigeonCritter in action
Create a homing PigeonCritter
. It should have a Location field which is its home
location. We don't want it to "eat" anything, so you need to override the default processActors
method, so nothing is removed. This is a good place to make sure that the Pigeon's Direction is facing toward its home
.
The only other method to override is the getMoveLocations()
method. If it is already home
, it should return an empty ArrayList<Location>
, otherwise it should find the adjacent location toward home, and if it is valid and unoccupied, that location alone should be returned. If that location is not valid, or else if it is occupied, then it should return a list of the empty adjacent locations.
Remember you can interact with the ActorWorld to move the Pigeon to another location and add rocks as obstacles and watch your Pigeon find home! If you add getter and setter methods, you can interact with your PigeonCritter
to move its home
location!
PigeonCritterRunner.java
import info.gridworld.actor.*; import info.gridworld.grid.*; public class PigeonCritterRunner { public static void main(String[] args) { ActorWorld world=new ActorWorld(); world.add(new Location(0,0), new PigeonCritter(new Location(9,9))); world.add(new Location(3,4), new Rock()); world.add(new Location(4,4), new Rock()); world.add(new Location(5,4), new Rock()); world.add(new Location(5,3), new Rock()); world.add(new Location(8,8), new Rock()); world.add(new Location(9,8), new Rock()); world.show(); } }