The Basics

For fun I made this to prove-out that my MS Paint plugin could be extended nicely.

Amusingly the demo below uses three plugins I've written to make a larger game from the pieces.

It won't support multiple instances being played simultaneously.

Demos

Snake color Food color Background color

your high score: (we use cookies for this purpose only)

0 points -

Demo setup:

var $p = $('#points');
$p.levelup({'start' : 0, showThousands: true});

$('#container').snakeGame({rows: 40,
                           cols: 40,
                           speed: 250,
                           onPoint: function(increase) {
                               $p.levelup('increment', increase);
                           },
                           onGameOver: function() {
                               $('#over').text('Game over!');
                           }});
$('#start').on('click', function(event) {
    event.preventDefault();
    $('#log').empty();

    $('#points').text('0');
    $('#over').text('');

    $('#container').snakeGame('start');
});

Installation

Basically just include the file.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="/libs/jquery-snake-game/jquery.snake-game.js"></script>

<div id='container'></span>

<script>
    $('#container').snakeGame({rows: 20, cols: 20});
</script>

Usage

Name Type Default Description
rows integer 50 Number of rows.
cols integer 50 Number of columns.
speed integer 100 Speed of movement in milliseconds.
snakeColor css string blue Color of the snake.
foodColor css string blue Color of the food.
startLength integer 1 Starting length of the snake.
cornerFood boolean true Can food spawn in the corner?
wallFood boolean true Can food spawn against the outer wall?
onPoint callback null Function called with single parameter, the score increase.
onGameOver callback null Function called when the game ends.

method param type description
'start' start the game (or reset the game)
'turn' direction string turn the snake, left, right, up, down

License

Apache License 2.0