Tuesday, 22 February 2011

Grid World Part 4 part 1

1
page 30
What methods are implemented in Critter?
The act(), getActors(), processActors(), getMoveLocations(), and selectMoveLocation() methods are implemented in Critter, although it still contains methods from it's superclass Actor.


2
What are the five basic actions common to all critters when they act?  
 The actors are collected from the grid, they all invoke the processActors() method, they get their moves through getMoveLocations(), they select a location through selectMoveLocation(), and finally make a move through makeMove().


3
Should subclasses of Critter override the getActors()   method?
Explain
No, because the getActors() method is used to collect all actors on the grid, and if a subclass of critter overrides it, it might not even get to act because it won't be collected into the list of actors.
 

4
Describe three ways that a critter could process actors. 
  It could change the state of the critter and the actor, it could change the state of the critter based on the actor, or change the actor (i.e. removing it).


5
What three methods must be invoked to make a critter move?
 Explain each of  these methods. 
processActors(), getMoveLocations(), and selectedMoveLocation() must be implemented in order for the critter to move. 


6
Why is there no Critter constructor?
This is because the critter class is an abstract class. Furthermore, it implements methods for its subclasses to use, but can't make any objects.
 
page 33
1
Why does act() cause a ChameleonCritter to act differently from a Critter even though ChameleonCritter does not override act()?
ChameleonCritter acts differently from a Critter even though it doesn't override act() because it has a different implementation of the processActors() method which it does override to make it's color that of its neighbors.


2
Why does the makeMove() method of ChameleonCritter call super.makeMove?
ChameleonCritter calls super.makeMove() because it wants to override the makeMove method but at the same time implement the previous implementation of the method as part of the new method.
 

3
How would you make the ChameleonCritter drop flowers in its old location when it moves?
You would put an implementation of dropping flowers in the beginning of the makeMove() method, so that for each call to the makeMove() method it would drop a flower thereby putting a flower where it was.
 

4
Why doesn’t ChameleonCritter override the getActors() method? 
The ChameleonCritter class doesn't override the getActors() method because it wants to use the same implementation that the critter class used in order to find the actors currently on the grid.


5
Which class contains the getLocation() method? 
Actor contains the getLocation() method.


6
How can a Critter access its own grid?
If by grid, what is meant is location, then the critter can simply call the getLocation() method since it is implemented in the Actor class.

No comments:

Post a Comment