A vanilla JavaScript implementation of the classic Snake Game, featuring modular architecture, persistent game state, and dynamic grid rendering.
- 🕹 Arrow Key Controls: Move the snake with Arrow Keys.
- 💾 State Persistence: Saves progress using
localStorage. - 🟢 Dynamic Grid Creation: No hardcoded HTML elements.
- 🛑 Tail Collision Detection: Ends the game if the snake bites itself.
- 🍏 Random Food Spawning: Food appears in an unoccupied space.
- 🎯 Edge Wrapping: Snake moves from one side to the other.
- 🔁 Restart Without Page Reload: Game resets dynamically without refreshing.
- Start the Game: The game automatically begins on page load.
- Move the Snake: Use
Arrow Keysto move. - Eat the Food: Grow by consuming food (
red blocks). - Avoid Your Tail: The game ends if you collide with yourself.
- Restart the Game: Click the
Restart Gamebutton.
Clone this repository and run it locally.
git clone https://github.com/yourusername/snake-game.git
cd snake-game
npm run startModify worldState.js:
const DEFAULT_STATE = {
rows: 15, // Change to your desired row count
cols: 30, // Change to your desired column count
};Modify main.js:
const startGameLoop = () => {
gameInterval = setInterval(() => {
movePlayer(gameState.moveDirectionName);
}, 150); // Adjust for speed (Lower = Faster)
};- [ ] Score System 🏆
- [ ] Sound Effects 🔊
- [ ] Mobile Touch Support 📱
- [ ] Multiplayer Mode 🎮
This project is licensed under the MIT License.
🚀 Built with JavaScript, HTML, and CSS. Enjoy coding! 🐍