Skip to content

cleytonrs/snake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Snake Game

🐍 A browser-based Snake game built with vanilla HTML, CSS, and JavaScript. No frameworks, no build tools, no network requests β€” just open and play.

πŸ‘‰ Play the Live Demo here

How to Play

  1. Open index.html in any modern browser (Chrome, Firefox, Safari, Edge)
  2. Click Start Game or press Enter
  3. Control the snake with Arrow Keys or WASD
  4. Collect food to grow and increase your score
  5. Avoid walls and your own tail
  6. Your highest score is automatically saved locally, so you can try to beat it next time you play!

Controls

Action Keys
Move Arrow Keys / WASD
Pause Escape / P
Resume Escape / P / Resume button
Start / Restart Enter / Button click

Features

  • 20Γ—20 grid with smooth movement
  • Speed progression (10 levels) as you score
  • High score persisted across sessions via localStorage
  • Pause/resume with overlay
  • Auto-pause on window blur
  • Responsive layout (320px–1920px)
  • Dark theme with accessible contrast ratios
  • Win condition when the board is completely filled

Project Structure

β”œβ”€β”€ index.html       # Game UI with three screens
β”œβ”€β”€ style.css        # All styling and responsive layout
β”œβ”€β”€ game.js          # Game logic, controller, and rendering
β”œβ”€β”€ package.json     # Dev dependencies (fast-check for tests)
└── tests/           # Property-based and unit tests

Running Tests

To install dependencies and run the test suite, execute the following commands in the project root:

npm install
npm test

Tests use the Node.js built-in test runner and fast-check for property-based testing. All 68 tests validate 12 correctness properties covering movement, collisions, scoring, input handling, and persistence.

License

This project is licensed under the MIT License.

About

🐍 A lightweight, zero-build Snake game written in Vanilla HTML5/CSS3 and JavaScript. Features speed progression, localStorage persistence, and 60+ property-based tests using Node.js native test runner.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors