GithubHelp home page GithubHelp logo

dy05 / snake-game Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sidikfaha/snake-game

0.0 1.0 0.0 402 KB

Snake game created with JavaScript just for fun

License: MIT License

HTML 6.84% JavaScript 7.44% SCSS 12.95% TypeScript 72.28% Shell 0.49%

snake-game's Introduction

SNAKE GAME

Just for fun... I just wanted to realise something but I want to do somethig different of the classic game that every body know.

Usage

HTML

You just need to import the javascript file and follow these steps :

  1. Import css and js files
  2. A div element with id="table" and you give him both width and height. It'll be used to display the game
  3. A span or any other element with id="score" to display score
  4. A span or any element with id="level" to display level

JS

Just create a new Snake object by giving the level in parameter

const game = new Snake( {level: 2} ) // For normal level

// Overriding gameOver function
game.gameOver = () => {
    alert('Custom game over function')
    game.stop() // Do never forget this line
}

// When all is ok, just star de game
game.start()

Code example

<!doctyle html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Snake Game</title>
        <link rel="stylesheet" href="css/style.css">
    </head>
    <body>
        <p>Level : <span id="level"> </p>
        <p>Score : <span id="score"> </p>
        <!-- width=100% and height=400px (very important) -->
        <div style="height: 400px;" id="table"></div>

        <script src="js/snake.ts"></script>
        <script>
            const game = new Snake( {level: 3} ).start()
        </script>
    </body>
</html>

snake-game's People

Contributors

sidikfaha avatar dy05 avatar dependabot[bot] 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.