DEV Community

wiz-aiimages
wiz-aiimages

Posted on

How To Make A Snake Game In JavaScript : A Beginners Guide



Basic Snake HTML and JavaScript Game

Snake is a fun game to make as it doesn't require a lot of code (less than 100 lines with all comments removed). This is a basic implementation of the snake game, but it's missing a few things intentionally and they're left as further exploration for the reader.

Create a fun Snake game with <100 lines of code using HTML and JavaScript. Basic version with room for exploration.






Further Exploration<!--more-->

  • Score
    • When the snake eats an apple, the score should increase by one. Use context.fillText() to display the score on the screen
  • Mobile and touchscreen support
  • Better apple spawning
    • Currently, the apple spawns in any random grid in the game, even if the snake is already on that spot. Improve it so it only spawns in empty grid locations
    • READ MORE

Top comments (0)