Snake Game with Javascript

Hi All, I don’t have any experience in game development. In free time I think lets try to make simple game with jQuery and javascript. So I start to do code to make simple basic snake game that was inbuilt with past simple model of Nokia mobile.

snake

Here, I just try to implement simple snake game with javascript and html. First, I made game console with html table and logically I have give number to each td of table.

Now, for generate snake on board I make one global numeric array variables ‘snake’. At starting I set snake array as [73,72,71,70] that means 73th td, 72th td, 71th td and 7th td are part of the snake and I set the background color of all these four td to black by adding snake css class (function – generateSnake()).

For generate cherry that snake need to eat will be a single td. Function generateCherry() – will generate random number withing the limit of our game console and which is not a part of snake.

Function runSnake() – for move snake in appropriate direction as per user input from keyboard arrow keys. We also have speed dropdown to set speed of snake. By using setTimeout(), runSnake method is recursively executes at certain interval as per the snake speed.

You can find complete code on my github repository, as well as find demo page here.
Any feedback and suggestion please revert back in comment section.

Advertisements

3 thoughts on “Snake Game with Javascript

  1. Thanks man for the post. It was short and good. Just try increasing the font size to make ure posts more easily readable

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s