This is a simple snake game available in both WIN32 and JavaScript versions. The WIN32 version was written in 2010 – small but complete. Looking back, I’m quite impressed with myself from over five years ago. The jQuery version was written in 2015.
GitHub download link: https://github.com/hujiulin/snake
jQuery demo: http://www.coinidea.com/game/snake/
The overall interface looks like this:
WIN32 Version:

jQuery Version:

WIN32 Framework Code:
| |
Snake Definition
The entire snake is a List, with a head squarehead, a direction with four possible values, a speed, and the current snake length List.size().
Collision Detection
- When the snake’s head encounters a randomly generated
squarein the currentdirection, it means food has been eaten. - When the snake turns back and hits its own body, or hits the boundary, the game is over.