Grid World Part 4 Meet the Critters Critters

  • Slides: 10
Download presentation
Grid. World Part 4 Meet the Critters

Grid. World Part 4 Meet the Critters

Critter’s act() if (get. Grid() == null) return; Array. List<Actor> actors = get. Actors();

Critter’s act() if (get. Grid() == null) return; Array. List<Actor> actors = get. Actors(); process. Actors(actors); Array. List<Location> move. Locs = get. Move. Locations(); Location loc = select. Move. Location(move. Locs); make. Move(loc);

get. Actors() v Gets all neighbors v Override to get Actors from different locations

get. Actors() v Gets all neighbors v Override to get Actors from different locations

process. Actors() Eats surrounding Actors unless they’re a Rock or a Critter v Use

process. Actors() Eats surrounding Actors unless they’re a Rock or a Critter v Use instance. Of v v v if (!(a instanceof Rock) && !(a instanceof Critter)) a. remove. Self. From. Grid(); Override to Add v Not eat v Eat differently v

get. Move. Locations() v Returns empty neighbors v Override to get possible locations differently

get. Move. Locations() v Returns empty neighbors v Override to get possible locations differently v Locations that are not empty

select. Move. Location(Array. List) v Randomly picks a location from Array. List<Location> v Override

select. Move. Location(Array. List) v Randomly picks a location from Array. List<Location> v Override to select by other method

make. Move(Location) v Moves to the new Location v Override to v Leave v

make. Move(Location) v Moves to the new Location v Override to v Leave v turn something in previous spot

Extending Critter

Extending Critter

Chameleon Critter v Overrides v process. Actors v If there is a neighbor, Matches

Chameleon Critter v Overrides v process. Actors v If there is a neighbor, Matches their color v make. Move v Turn in direction that it’s moving

Crab. Critter v Overrides v get. Actors v Only look front, front right, and

Crab. Critter v Overrides v get. Actors v Only look front, front right, and front left v get. Move. Locations() v Returns empty locations to the right and left v make. Move v Will randomly turn left or right if it doesn’t move