Jiangyue Zhu

Impossible is Nothing

Leave a comment

Greedy Snake Game–Using HTML5 Canvas and JavaScript

A couple weeks ago, I used HTML5 canvas and JavaScript, jQuery to implement a greedy snake game. The logic is pretty simple, compared to some complex animation game. And the all of the implementation is based on HTML5+JavaScript+CSS, without any usage of Flash.


The UI is simple but the functionality is working fine, what the users need to do is to use keyboards(up-arrow, right-arrow, down-arrow, left-arrow) to control directions of the snake. The score will be recorded once the snake hit the targe and the snake’s size will be auto-increment. The game will end if the snake hit itself or the edge.

The source code can be found on GitHub: https://github.com/zhujy8833/Snake

There is another version which I put in jsFiddle: http://jsfiddle.net/zhujy_8833/bRMjV/

Click Here to view the live demo.