Last Updated: 2/13/2026
jrn: readme-mlhnrz5bf39e attention:
- op: file path: src/main.ts
- op: file path: README.md
- op: file path: README2.md
- op: file path: README3.md
Snake Game ๐
A modern, progressively challenging Snake game built with TypeScript and Vite. Features dynamic grid expansion, adjustable starting grid size, increasing difficulty levels, and a clean, responsive interface.
โจ Features
- Adjustable Starting Grid: Use +/- keys to change grid resolution (5x5 to 50x50) before the game starts
- Progressive Difficulty: Grid doubles in size when you fill 25% of the space
- Dynamic Levels: Game speed increases with each level
- Fixed Canvas Size: 300x300px canvas with dynamically calculated cell sizes
- High Score Tracking: Persistent high scores saved in local storage
- Responsive Controls: Support for both arrow keys and WASD
- Pause Functionality: Press โPโ to pause/resume the game
- Clean UI: Modern dark theme with smooth animations
- Mobile Responsive: Adapts to different screen sizes
- Check out more detail here Feature Detail
๐ฎ Coming Soon
- 2.5D Mode: Isometric view with 3D snake rendering for an enhanced visual experience
- 2 Snakes at Once: Simultaneous control of two snakes for an extra challenge
- Rename to โsnekโ: Future branding update planned
- Color Blind Mode: Accessibility feature to support players with color vision deficiencies
๐ฌ User Feedback
Weโve received valuable feedback from our community:
- Request for color blind mode to improve accessibility
- Interest in viewing other playersโ high scores (leaderboard feature)
These features are being considered for future releases. See README3.md for more user feedback.
๐ฎ How to Play
- Click New Game to start
- (Optional) Press + or - to adjust the starting grid size (5x5 to 50x50)
- Press any Arrow Key or WASD key to begin moving the snake
- Eat the red food to grow and increase your score
- Avoid hitting the walls or yourself
- Press P to pause the game at any time
- Press Shift+R to reset and return to the menu
- The grid expands when you fill 25% of the space, increasing the challenge!
๐ Getting Started
Prerequisites
- Node.js (version 14 or higher)
- npm or yarn
Installation
- Clone the repository:
git clone <repository-url>
cd snake-game- Install dependencies:
npm install- Start the development server:
npm run dev- Open your browser and navigate to
http://localhost:5173
๐ ๏ธ Build
To create a production build:
npm run buildThe built files will be in the dist directory.
To preview the production build:
npm run preview๐ฆ Tech Stack
- TypeScript: Type-safe game logic
- Vite: Fast build tool and dev server
- HTML5 Canvas: For rendering the game
- CSS3: Modern styling with animations
- LocalStorage: Persistent high score tracking
๐ฏ Game Mechanics
Scoring
- Each food item eaten = +1 point
- High scores are automatically saved
Level Progression
- Level 1: Starts with configurable grid (default 10x10, adjustable 5x5 to 50x50)
- Level 2+: Grid doubles (20x20, 40x40, etc.) when 25% filled
- Game speed increases with each level (update interval halves: 200ms โ 100ms โ 50ms, etc.)
Controls
| Key | Action |
|---|---|
| โ / W | Move Up |
| โ / S | Move Down |
| โ / A | Move Left |
| โ / D | Move Right |
| P | Pause/Resume |
| Shift+R | Reset to Menu |
| +/- | Adjust grid size (before game starts) |
๐ Project Structure
snake-game/
โโโ src/
โ โโโ main.ts # Game logic and class
โ โโโ style.css # Styling
โ โโโ typescript.svg # TypeScript logo
โโโ public/
โ โโโ vite.svg # Vite logo
โโโ index.html # Main HTML file
โโโ package.json # Dependencies and scripts
โโโ tsconfig.json # TypeScript configuration
โโโ README.md # Project documentation
โโโ README2.md # Future plans
โโโ README3.md # User feedback๐๏ธ Architecture
Component Overview
- SnakeGame Class: Core game controller managing all game logic
- Game State: Tracks snake position, food, score, level, and grid dimensions
- Rendering Engine: Handles all Canvas API drawing operations with fixed 300x300px canvas
- Input Handler: Processes keyboard events and game controls
- Game Loop: Manages game tick updates, collision detection, and progression
- LocalStorage: Persists high scores across sessions
๐จ Customization
You can easily customize the game by modifying these values in main.ts:
const CANVAS_SIZE = 300 // Fixed canvas size in pixels
private gridSize: number = 10 // Starting grid size
private initialGridSize: number = 10 // Default starting grid size
private gameSpeed: number = 200 // Initial game speed in ms
private baseSpeed: number = 200 // Base speed for calculationsThe cell size is automatically calculated as CANVAS_SIZE / gridSize, ensuring the grid always fits perfectly within the fixed canvas.
Color scheme can be modified in style.css:
--snake-color: #4ade80; /* Snake head color */
--snake-body: #22c55e; /* Snake body color */
--food-color: #ef4444; /* Food color */
--bg-color: #1a1a1a; /* Background color */๐ค Contributing
Contributions are welcome! Feel free to:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is open source and available under the MIT License.