View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide

Lesson 4 Key

Lesson 4 - The Actor Class
Exercise B Key, Chapter 5

1. return (neighbor = = null) || (neighbor instanceof Flower);

2. This is the position of the Actor for which a move is being contemplated.

3. The move method

4. Grid gr = getGrid( );

    if ( !gr.isValid(next) )
    return false
    Actor neighbor = gr.get(next);


5. Location loc = getLocation( );
    Location next = loc.getAdjacentLocation( getDirection( ) );
    if( !gr.isValid(next) )
    return false;


6. The Actor object removes itself from the Grid.

7. 6 times

8. In the move method of the Bug class, we have the following code:
    Flower flower = new Flower( getColor( ) );
    //getColor( ) retrieves the color of the Bug.


9. The move method:
    Flower flower = new Flower(getColor( ));
    flower.putSelfInGrid(gr, loc);


10. Location next = ( getLocation( ) ).getAdjacentLocation(getDirection( ) );

    flower.putSelfInGrid( gr, getLocation( ) );


11. Nothing, its code body is empty.

12. Yes

13. The Flower is darkened.

Link to this Page