š Snake Game Project
A classic Snake Game built with HTML, Tailwind CSS, and vanilla JavaScript. This game allows players to control a snake that grows longer every time it eats food. The objective is to eat as much food as possible without running into the walls or the snake's own body.
š Table of Contents
š® Demo
Try out the game live here: Snake Game Demo
⨠Features
- Real-time snake movement controlled by arrow keys.
- Randomly generated food positions on the board.
- Score tracking system with high score saved in
localStorage
.
- Responsive design that adjusts to different screen sizes.
- Clean UI styled with Tailwind CSS.
š Tech Stack
The following technologies were used to build this project:
- HTML: For creating the structure of the game.
- Tailwind CSS: For styling the game board and UI elements.
- JavaScript: For game logic, including snake movement, food generation, and collision detection.
š Installation
To run the project locally, follow these steps:
Clone the repository:
git clone https://github.com/Sushank-ghimire/snake-game.git
Navigate to the project folder:
cd snake-game
Open the index.html
file in your browser:
You can simply double-click the index.html
file or use a live server extension in your code editor (like VSCode).
That's it! The game should be running in your browser.
š® Gameplay Instructions
- Click the "Start Game" button to begin.
- Control the snake using the arrow keys:
- Up Arrow: Move Up
- Down Arrow: Move Down
- Left Arrow: Move Left
- Right Arrow: Move Right
- The snake will grow longer each time it eats the yellow food block.
- The game ends if the snake hits the walls or itself.
- Your score will be displayed on the screen, and the highest score is saved in your browser.
āļø How It Works
Game Mechanics
- Snake Movement: The snake moves continuously in the direction of the arrow key pressed by the player.
- Food Generation: Food is placed randomly on the board. When the snake eats the food, its length increases.
- Collision Detection: The game detects collisions with the walls and the snake's own body to determine if the game is over.
- Score Tracking: The game tracks the player's score and saves the high score in
localStorage
, allowing it to persist across sessions.
Code Highlights
- The game board is rendered using an HTML
<canvas>
element.
- JavaScript handles the game loop, updating the snake's position and checking for collisions.
- Tailwind CSS is used to style the game board and buttons.
š Project Structure
snake-game/
āāā index.html # The main HTML file
āāā styles.css # Tailwind CSS styles
āāā script.js # JavaScript game logic
āāā README.md # Project documentation
š License
This project is licensed under the MIT License.