Last Updated: 3/6/2026
Development Guide
This guide covers setting up your development environment, making changes, and deploying the Snake Game.
Prerequisites
- Node.js 16+ (18+ recommended)
- npm 7+ (comes with Node.js)
- A modern web browser (Chrome, Firefox, Safari, Edge)
Local Setup
1. Clone the Repository
git clone https://github.com/jeverest/snake-game.git
cd snake-game2. Install Dependencies
npm installThis installs:
vite- Fast build tool and dev servertypescript- Type checking and compilation
3. Start Development Server
npm run devThe game will be available at http://localhost:5173. The dev server supports:
- Hot Module Replacement (HMR): Changes reflect instantly
- TypeScript type checking: Errors shown in terminal and browser
- Source maps: Debug original TypeScript in browser DevTools
Project Commands
| Command | Description |
|---|---|
npm run dev | Start development server with HMR |
npm run build | Build for production (outputs to dist/) |
npm run preview | Preview production build locally |
Development Workflow
Making Changes
-
Game Logic: Edit
src/main.ts- The
SnakeGameclass contains all game logic - TypeScript provides type safety and IntelliSense
- The
-
Styling: Edit
src/style.css- UI styles for menus, overlays, and canvas container
- Dark theme variables at the top
-
HTML Structure: Edit
index.html- Game screens and UI elements
- Canvas element and script loading
Testing Changes
Currently, testing is manual:
- Run
npm run dev - Play the game and verify behavior
- Test edge cases (collision, grid expansion, pause)
- Check browser console for errors
Recommended test scenarios:
- Start game and move in all directions
- Eat food and verify score increment
- Fill 25% of grid to trigger expansion
- Pause and resume mid-game
- Adjust grid size before starting
- Rotate view with Q/E keys
- Adjust perspective with [ and ] keys
- Test collision detection at boundaries
- Verify high score persistence (close and reopen browser)
Debugging Tips
Browser DevTools
- Console: View
console.log()output and errors - Debugger: Set breakpoints in TypeScript source
- Performance: Profile canvas rendering performance
- Application: Inspect localStorage for high score
Common Issues
Game runs too fast/slow:
- Check
gameSpeedandbaseSpeedvalues - Verify
setIntervalis cleared on game over
Rendering glitches:
- Inspect
isoCachevalues in debugger - Verify
updateCanvasSize()is called on resize - Check painter’s algorithm sort order
Input not working:
- Ensure canvas has focus (click it)
- Check
handleKeyPressevent listener - Verify direction validation logic
Building for Production
Create Production Build
npm run buildThis:
- Compiles TypeScript to JavaScript
- Bundles and minifies code
- Optimizes assets
- Outputs to
dist/directory
Preview Production Build
npm run previewServes the production build locally to verify before deployment.
Deployment
The dist/ folder can be deployed to any static hosting service:
- Vercel:
vercel deploy - Netlify: Drag
dist/to Netlify dashboard - GitHub Pages: Push
dist/togh-pagesbranch - Cloudflare Pages: Connect repo and set build command to
npm run build
Code Style
The project uses TypeScript’s strict mode:
{
"compilerOptions": {
"strict": true,
"target": "ES2020",
"module": "ESNext"
}
}Guidelines:
- Use
constandlet, avoidvar - Prefer arrow functions for callbacks
- Add type annotations for public methods
- Use descriptive variable names
- Comment complex algorithms (e.g., isometric projection)
Performance Optimization
When making changes, consider:
- Canvas operations are expensive: Batch drawing calls
- Avoid recreating objects: Reuse
Positionobjects where possible - Pre-compute when possible: Use
isoCachefor grid coordinates - Profile before optimizing: Use browser Performance tools
Adding New Features
Example: Adding Sound Effects
- Add audio files to
public/sounds/ - Create
Audioinstances inSnakeGameconstructor - Play sounds on events (eat food, game over, level up)
private eatSound: HTMLAudioElement
constructor() {
this.eatSound = new Audio('/sounds/eat.mp3')
// ...
}
private update() {
// ...
if (head.x === this.food.x && head.y === this.food.y) {
this.eatSound.play()
this.score++
// ...
}
}Getting Help
- Check existing GitHub Issues
- Review the Architecture Overview for system design
- Read the Code Documentation for class details