1. Write a class CircleBug that is identical to BoxBug, except that in the act() method the turn() method is called once instead of twice. How is its behavior different from aBoxBug? | Done it. I had a little difficulty but I got some help. I made two new classes, CircleBugEat and CircleBug. The CircleBugEat produces the grid and puts the CircleBug in it. The CircleBug only extends the Bug class and overrides its act method, that will bring change its behavior. |
2. Write a class SpiralBug that drops flowers in a spiral pattern. Hint: Imitate BoxBug, but adjust the side length when the bug turns. You may want to change the world to an UnboundedGrid to see the spiral pattern more clearly. | Not easy. I had to do is change the act() method of the CircleBug create the SpiralBug. |
3. Write a class ZBug to implement bugs that move in a “Z” pattern, starting in the top left corner. After completing one “Z” pattern, a ZBug should stop moving. In any step, if a ZBug can’t move and is still attempting to complete its “Z” pattern, the ZBug does not move and should not turn to start a new side. Supply the length of the “Z” as a parameter in the constructor. The following image shows a “Z” pattern of length 4. Hint: Notice that a ZBug needs to be facing east before beginning its “Z” pattern. | Question to ask. I did not understand how to work with this. Will get some Help asap. |
4. Write a class DancingBug that “dances” by making different turns before each move. The DancingBug constructor has an integer array as parameter. The integer entries in the array represent how many times the bug turns before it moves. For example, an array entry of 5 represents a turn of 225 degrees (recall one turn is 45 degrees). When a dancing bug acts, it should turn the number of times given by the current array entry, then act like a Bug. In the next move, it should use the next entry in the array. After carrying out the last turn in the array, it should start again with the initial array value so that the dancing bug continually repeats the same turning pattern. The DancingBugRunner class should create an array and pass it as a parameter to the DancingBug constructor. | Done. I tried to create this but I understand that I had to work with the act()method, and bring alterations but that was not working for me so I got stuck. |
5. Study the code for the BoxBugRunner class. Summarize the steps you would use to add another BoxBug actor to the grid. | Firstly we need to initialize the new BoxBug, and the another step is to put it inside the grid. |
Sunday, 6 February 2011
Grid World Page 13-15
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment