The entire game consists of the following three main components: Game Board, Snake, and Food Cells.
The game is created around the following points:
- Create the Game Board using a Matrix
- Each cell in-board is identified using a unique id
- Snake is handled using a Singly Linked List
- Food is randomly generated using a utility function.
- Initializing snake movement and food cell
- Handling snake movements through arrow keys by attaching an event listener to the board
- Whenever a snake consumes food, then handling the growth of snake.There are two kinds of food available to a snake, an apple or a frog.
- In the case of an apple, the snake will consume it and grow in size by one cell. The score will be incremented by one.
- In the case of a frog, the snake will consume it and grow in size by one cell. And the score will be incremented by two. Also, the snake will reverse its direction.
- If the snake collides with itself or the boundary of the board then the game is over
- Displaying score
- Reset when game is over