I rebuilt snake, but with intentional limitation that everything is in JavaScript.
Here's a link to the main file
Everything, including the styling and instantiataion of HTML elements, is done in JavaScript.
I put a lot of consideration into algorithm efficiency, as a result no method has a time complexity greater than O(n).
I utilized OOP and SOLID principles to create a modular, reusuable design.
Notably, the rendering logic is kept seperate from the game logic, it is a design that can easily be reimplemented in any language.
JavaScript
NextJS
Vercel
Use the arrow keys, on your keyboard, to control the snake's direction.
Collect the food items to increase the length of the snake.
Avoid colliding with the walls or the snake's own body, as it's game over after that.
To run this locally, follow these steps:
git clone <repository-url>
cd javascript-snake-game
npm install
npm run dev
Then open your browser and visit http://localhost:3000 to play
Alternatively, take a look at my portfolio for a live deployment