Part1-2
1. Test the setDirection method with the following inputs and complete the table, giving the compass direction each input represents.
Answer:
Degress | Compass Direction |
---|---|
0 | North |
45 | Northeast |
90 | East |
135 | Southeast |
180 | South |
225 | Southwest |
270 | West |
315 | Northwest |
360 | North |
2. Move a bug to a different location using the moveTo method. In which directions can you move it? How far can you move it? What happens if you try to move the bug outside the grid?
Answer:
①When using the moveTo method, I can move a bug in any direction and distance as long as the destination is a empty cell in the grid. But the original direction of the bug does not change.
② If I try to move the bug outside the grid, a dialog will show up (throw java.lang.illegalArgumentException
) and tell me that the location is invalid. And the bug will stay in its original location.
3. Change the color of a bug, a flower, and a rock. Which method did you use?
Answer:
Each of these actor has a setColor()
method, which can change the color itself.
4. Move a rock on top of a bug and then move the rock again. What happened to the bug?
Answer:
①After a few attempts, I found that if I moved a rock above a bug, it would disappear from the grid.
② When the rock is moved to another cell, the previous cell remains empty, as if the bug has been removed from the grid.
GUI Summary
Mouse Action | Keyboard Shortcut | Result |
---|---|---|
Click on an empty location | Select empty location with cursor keys and press the Enter key | Shows the constructor menu |
Click on an occupied location | Select occupied location with cursor keys and press the Enter key | Shows the method menu |
Select the Location -> Delete menu item | Press the Delete key | Removes the occupant in the currently selected location from the grid |
Click on the Step button | After clicking step once, press the space key | Calls act on each actor |
Click on the Run button | None | Starts run mode (in run mode, the action of the Step button is carried out repeatedly) |
Click on the Stop button | After clicking run once, press the space key | Stops run mode |
Adjust the Slow/Fast slider | None | Changes speed of run mode |
Select the Location -> Zoom in/Zoom out menu item | Press the Ctrl+PgUp / Ctrl+PgDn keys | Zooms grid display in or out |
Adjust the scroll bars next to grid | Move the location with the cursor keys | Scrolls to other parts of the grid (if the grid is too large to fit inside the window) |
Select the World -> Set grid menu item | Press the Alt+W key,and Enter key. Then use Up or Down to chose World -> Set grid menu item and press Enter key | Changes between bounded and unbounded grids |
Select the World -> Quit menu item | Press the Ctrl+Q keys Q | Quits GridWorld |
What’s more, if you want to Select the Location menu item, please press the Ctrl+L keys.
If you want to Select the Help menu item, please press the Ctrl+H keys.