Giter Site home page Giter Site logo

snake-game's Introduction

Snake-Game

A basic version of the snake game using HTML and JS. Hope you like it.
https://jescortam.github.io/Snake-Game/

Screenshot 2023-05-05 232421

Controls:

  • Arrow keys to change the snake's direction.
  • Escape to pause the game.

Code explanation:

Snake properties

  • snakeBody: Array containing the coordinates for each square of the snake.
  • isPaused: Checks if the game is paused or not.
  • isAlive: Checks if the snake has died or not.
  • dir: The initial value is 39, which means right (39 is the key code for the right arrow key).
  • movement: Is the movement speed of the snake (can be customized in the menu).

Apple properties:

  • x: Location in the horizontal axis.
  • y: Location in the vertical axis.

General properties:

  • columns: Number of columns in the grid.
  • rows: Number of rows in the grid.
  • speed: Movement speed of the snake.
  • speedOptions: Array containing the different speed options available.
  • sizeColumns: Array containing the different options for the number of columns.
  • sizeWidths: Array containing the different cell widths available.

Functions:

  • refresh(): Updates the coloring of each cell every interval of time.
  • moveApple(): Changes the location of the apple when eaten.
  • createGrid(): Creates and displays the grid.
  • startButton.onClick(): Starts the game when the start button is clicked.
  • move(): Moves the snake in the direction it is facing.
  • action(): Does something depending on which key the player presses

snake-game's People

Contributors

jescortam avatar

Watchers

 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.