Dear fellow Java-Programmers,
for my Programming-Course I have to come up with a Java-Implementation of the old C64 Classic "Serpentine", also known as "Snake". To put it in a nutshell, the player controls a snake with two keys, turning the snake right or left at a 90° angle. The snake itself goes forward automatically and cannot be stopped at any time. The goal of the game is to eat 10 apples just by running over them. If you have accomplished that, you advance to the next level, which might have a kind of obstacle (a wall) somewhere in the middle. If you steer the snake into a wall or into itself, it dies and loses one life.
The catch is that the snake, which is relatively small at the beginning, grows with each apple it eats. Thus, it gets harder with any apple the snake has eaten to avoid running into your own body.
So far for the game. I would like to know what your general approach to this programming task would be. What kind of Java-Object would you use for the snake itself, which one for the walls, which for the apples? How would you manage the collision detection etc.
I know these are not questions which can be answered in one or two sentences, but nevertheless, it would be just great if some of you could give me any hints or advice.
Thank you very much in advance,
I'd use a 2D array for the playing area, with int or enum elements. Values in the array would indicate whether the cell contains a wall, an apple, the snake's body, etc. You'd also need some variables for the location and direction of the snake's head, and maybe its tail.