Giter Site home page Giter Site logo

christian0730 / javascript-snake-game Goto Github PK

View Code? Open in Web Editor NEW

This project forked from artenes/javascript-snake-game

0.0 1.0 0.0 16 KB

A simple Javascript snake game to exercise some JS knowledge

License: MIT License

HTML 8.35% JavaScript 91.65%

javascript-snake-game's Introduction

Simple Javascript snake game

Javascript Snake Game

Just download or clone the repository. Open snake.html in your browser and play!

Start the game by pressing Enter and use the arrow keys to move the snake.

You can also just grab the snake.js file and include it in your own html page.

To run the game in your page, you just have to create an instance of the Game class, like this:

<script src="snake.js"></script>

<script type="text/javascript">

	var game = new Game(20, 10, "stage", "score", "deaths", "max_score");

</script>

The arguments are, respectively:

  • size of the stage: It will always be a square.
  • frames per second: How fast will the game run?
  • id of a element in the DOM to display the stage: here is where the snake will appear.
  • id of a element in the DOM to display the score: here you will see your score.
  • id of a element in the DOM to display the number of deaths: here you will see how bad you are.
  • id of a element in the DOM to display the max score: here you will see your max score.

Credits

The game's logic is based on the implementation of Jamie Nichols of the same game. You can find a quick video he made explaining each part of the code.

I've changed the code to adapt it to my "code style" and added:

  • some comentaries to the code;
  • colors to the game;
  • high score and death counts;
  • pause feature;
  • more customization through the class constructor.

javascript-snake-game's People

Contributors

artenes avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.