Sunday, 6 February 2011

Grid World Page 6 + Page 8

1. Does the bug always move to a new location? Explain.
If there is rock infront or bug reaches corner/boundary of the grind, it turn clockwise. 
2. In which direction does the bug move?
The bug will always move straight by default but with every turn or corner the direction of straight changes.
3. What does the bug do if it does not move?
Clockwise
4. What does a bug leave behind when it moves?
A flower.
5. What happens when the bug is at an edge of the grid? (Consider whether the bug
is facing the edge as well as whether the bug is facing some other direction when
answering this question.)
Clockwise, when bug hits the edge. 
6. What happens when a bug has a rock in the location immediately in front of it?
Every edge the bug turns clockwise, the rock is therefore also treated like an edge and it turn clockwise. 
7. Does a flower move?
Nope
8. What behavior does a flower have?
Flower slowly fades to black. 
9. Does a rock move or have any other behavior?
Rock is always stationary.
10. Can more than one actor (bug, flower, rock) be in the same location in the grid at
the same time?
Nope, only one object at a time. 

PAGE 8
1. Test the setDirection()   method with the following inputs and complete the table, giving the compass direction each input represents.


degrees
compass direction
0
North
45
NE
90
135
SE
180
S
225
SW
270
W
315
NW
360
 N
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?
The moveTo() takes the co-ordinate of the bug into consideration, which is the row and the column where the bug is.We can place the bug anywhere in the grid, according to the coordinates. If we try to place it outside the grid, we will get an error. 
3. Change the color of a bug, a flower, and a rock.

Which method did you use?
setColor() is a method of the superclass. It is implemented into all the classes and can be used to change the colour of all the objects inside the grid. So the stone, the bug the flower, their colours can be changed using this method.
4. Move a rock on top of a bug and then move the rock again.

What happened to the bug?
There is no more bug. This is because their is only space for 1 bug to fit into each space of the grid. When we try to place a bug on top of a place of an existing bug, the previous bug will be deleted and the new bug will take its place.

No comments:

Post a Comment