A modern, sleek reimagining of the classic Snake game โ built with React, TypeScript, and AI-assisted development.
This is a modern take on the classic Snake game, featuring a clean, gradient-rich UI with smooth animations. Built entirely using React 19, TypeScript, and Vite with Tailwind CSS v4 and shadcn/ui components, this project showcases how AI-assisted development can rapidly prototype and polish a complete game experience.
The game includes all the nostalgia of the original โ eat food, grow longer, avoid walls and yourself โ with modern UX enhancements like dynamic difficulty, high score persistence, and keyboard-friendly controls.
This project was designed, architected, and implemented using AI Vibe Coding โ an AI-assisted development approach where:
- AI handles the heavy lifting: Code generation, pattern implementation, refactoring, and bug detection
- Human provides direction: Feature requirements, design decisions, and quality oversight
- Iterative collaboration: Continuous feedback loop between developer intent and AI execution
โ
Architecture design โ Component structure, state management with custom hooks, game loop patterns
โ
Code implementation โ TypeScript interfaces, React components, game logic algorithms
โ
UI/UX polish โ shadcn/ui integration, Tailwind styling, responsive layouts
โ
Problem solving โ Handling stale closures in game loops, optimizing re-renders with memo()
โ
Documentation โ Inline comments, type definitions, and this README
This approach allowed rapid development while maintaining clean, production-quality code.
- ๐ฏ Classic Snake mechanics โ Navigate, eat, grow, survive
- ๐ Dynamic difficulty โ Speed increases progressively as you score points
- ๐ High score tracking โ Your best score persists across sessions (localStorage)
- โธ๏ธ Pause & Resume โ Take a break anytime with Space or Escape
- ๐จ Modern design โ Gradient backgrounds, smooth animations, rounded corners
- ๐ผ๏ธ Clean grid layout โ 20ร20 game board with subtle grid lines
- ๐ฑ Responsive components โ Built with shadcn/ui + Radix primitives
- ๐ญ Game state overlays โ Visual feedback for idle, paused, and game over states
- โก Vite HMR โ Instant hot module replacement during development
- ๐ฃ Custom React hooks โ
useSnakeGameencapsulates all game logic - ๐ Ref-based direction system โ Prevents stale closure bugs in game loop
- ๐พ LocalStorage persistence โ High scores survive page refreshes
| Technology | Purpose |
|---|---|
| React 19 | UI library with modern concurrent features |
| TypeScript 5.9 | Type-safe development |
| Vite 7 | Lightning-fast build tool with HMR |
| Yarn 4 | Modern package manager |
| Tailwind CSS v4 | Utility-first CSS framework (new CSS-first config) |
| shadcn/ui | Accessible component system (Radix UI + CVA) |
| Lucide React | Beautiful, consistent icons |
- Node.js 18+ (20+ recommended)
- Yarn 4.x (included via Corepack)
-
Clone the repository
git clone <your-repo-url> cd snake-game
-
Install dependencies
yarn
-
Start development server
yarn dev
-
Open in browser
http://localhost:5173
yarn build # TypeScript check + Vite build
yarn preview # Preview production build locallyyarn lint # Run ESLint with React 19 rules| Key | Action |
|---|---|
Arrow Keys (โ โ โ โ) |
Move the snake |
| Space / Escape | Pause / Resume game |
| Click or Any Arrow Key | Start game when idle |
- Eat the food (๐) to grow longer and score points (+10 per food)
- Avoid collisions with walls or your own body
- Speed increases as your score grows โ stay sharp!
- Beat your high score โ it's saved automatically
- 10 points per food eaten
- Dynamic speed โ Game speeds up every time you eat (from 150ms to minimum 50ms per tick)
- High score โ Displayed at the top, persists in localStorage
snake-game/
โโโ src/
โ โโโ components/ # React components
โ โ โโโ ui/ # shadcn/ui primitives (Button, Card, etc.)
โ โ โโโ GameBoard.tsx # Main game grid + overlays
โ โ โโโ Snake.tsx # Snake rendering component
โ โ โโโ Food.tsx # Food rendering component
โ โ โโโ ScoreBoard.tsx # Score display
โ โ โโโ Controls.tsx # Control buttons
โ โโโ hooks/
โ โ โโโ useSnakeGame.ts # Core game logic hook
โ โโโ utils/
โ โ โโโ gameLogic.ts # Pure game functions (movement, collision, etc.)
โ โ โโโ storage.ts # localStorage wrapper
โ โโโ lib/
โ โ โโโ utils.ts # cn() utility for class merging
โ โโโ App.tsx # Root component
โ โโโ main.tsx # Entry point
โโโ public/ # Static assets
โโโ .github/
โ โโโ copilot-instructions.md # AI coding agent guidelines
โโโ package.json # Dependencies & scripts
Potential enhancements for v2.0:
- ๐ต Sound effects โ Eating, game over, high score sounds
- ๐ Themes โ Dark mode, color schemes (green, blue, neon)
- ๐ฑ Mobile controls โ Touch-based swipe gestures
- ๐ Achievements โ Unlock badges for milestones
- ๐ Leaderboard โ Global high scores with backend integration
- ๐๏ธ Difficulty levels โ Easy/Medium/Hard presets
- ๐ Power-ups โ Slow-motion, invincibility, double points
- ๐ฌ Animations โ Snake slithering, food spawning effects
This project is a personal learning project built to explore modern React patterns, TypeScript best practices, and AI-assisted development workflows.
- Development: Human-guided, AI-executed (AI Vibe Coding)
- UI Components: shadcn/ui + Radix UI
- Icons: Lucide React
- Build Tool: Vite
This is primarily a showcase project, but suggestions and feedback are welcome! Feel free to:
- ๐ Open issues for bugs
- ๐ก Suggest features
- ๐ Submit pull requests
Special thanks to the AI coding tools that made this rapid development possible, and to the open-source community for the incredible frameworks and libraries that power modern web development.
Enjoy the game! ๐๐ฎ
Made with โค๏ธ and ๐ค | View on GitHub