4.4.14

Greedy snake Game Programmed in Greenfoot - Problem with Random Bubbles Fixed:)



Project Download 

Concept:
Two Actor classes: Head and Part(green cirlces)

The movement of the head is controlled by arrow keys. Each coordinate of the head (the footstep) will be added to the coordinate list of all the eaten parts. If the head is over a new part, all the eaten parts will not move forward while the head moving forward (away from the freshly eaten new part), and the latest eaten part will be catenated directly to the head. Otherwise, if the head has not reached a new part, all the eaten parts will make one-step moves according to their coordinate lists.


Other possible programming method with 3 Actor classes:

1. My thought (not implemented yet): Another thought is to use 3 Actor classes: Head, Body and Cell. Whenever the Head has eaten a Body object, the cells will save the "moving direction" (orientation) of the head, each time the head passes by them. 
Body objects, which have been eaten will follow the "moving direction" saved in each cell.

2: Movement control with recursion:
In Head class, a field "next" is defined of type Part. And in Part class a field "next" of type Part is also defined. The movement of the head instance is controlled by arrows and each time the head moves, the movement is passed to the "next" instance recursively.