Excerpt from Description of Exercise

Objective: To gain experience working with 2 dimensional arrays.

The Scenario

Below is a picture of Nibbles:

Nibbles is a snake. Nibbles moves around a field, looking for food. In the picture, Nibbles is the winding green ribbon that looks a bit like the top of a question mark. The small red rectangle is the food.

Unfortunately, Nibbles is not a very clever snake. It will try to eat anything it can reach. When it eats food, it grows. When it eats the electric fence around its field, it dies. When it gets all twisted up, it can even try to eat itself, which also causes it to die.

A player controls the movement of the snake with the arrow keys on the keyboard. The objective, of course, it to eat as much food (and grow) as much as possible, without dying. The snake constantly moves by extending its ``head'' in the direction indicated by the last arrow key the user presses. While it is hard to tell from the picture, when the picture was taken, the snake's head was the square just below and to the right of the food. It was moving to the left of the screen. The square at the bottom of the question mark is the end of the snake's tail. Normally, each time the head moves into a new cell, the last cell of the snake's tail is removed from the screen. If the snake manages to eat the food, it becomes a few squares longer.

Handouts Describing the Exercise

Student Resources for Lab Exercise

Sample solutions