A competitive multiplayer maze game where players race against time to navigate through procedurally generated mazes. Built with Node.js, Express, Socket.io, React, and Canvas API.
- Real-time Multiplayer: Synchronized gameplay for 2-16 players
- Procedural Maze Generation: Unique mazes using DFS algorithm
- 3 Difficulty Levels: Easy (15×15), Medium (25×25), Hard (35×35)
- Competitive Rankings: Based on completion time and distance
- Live Timer: With countdown warnings at 60s, 30s, and 10s
- Beautiful Modern Interface: Glassmorphism design with smooth animations
- Responsive Canvas Rendering: Real-time maze visualization
- Player Indicators: Color-coded players with position tracking
- Live Statistics: Timer, player count, and finish tracking
- Results Screen: Comprehensive rankings with medals and statistics
- WebSocket Communication: Low-latency real-time updates
- A* Pathfinding: Accurate distance calculations
- Room Management: Create/join system with 6-character codes
- Auto-cleanup: Inactive room removal
- Keyboard Controls: Arrow keys or WASD
- Reconnection Handling: Graceful disconnect management
- Node.js 16.0.0 or higher
- npm or yarn
- Clone the repository
git clone <repository-url>
cd multimaze- Install Backend Dependencies
cd backend
npm install- Install Frontend Dependencies
cd ../frontend
npm install- Configure Environment Variables
Backend (backend/.env):
PORT=3000
NODE_ENV=development
CORS_ORIGIN=http://localhost:5173
MAX_ROOMS=50
MAX_PLAYERS_PER_ROOM=16
ROOM_INACTIVITY_TIMEOUT=600000
POSITION_UPDATE_INTERVAL=100Terminal 1 - Backend:
cd backend
npm startTerminal 2 - Frontend:
cd frontend
npm run devBackend (with auto-reload):
cd backend
npm run devFrontend:
cd frontend
npm run dev- Frontend: http://localhost:5173
- Backend API: http://localhost:3000
- Health Check: http://localhost:3000/api/health
- Open http://localhost:5173
- Click "Create Room"
- Enter your username
- Configure game settings:
- Difficulty (Easy/Medium/Hard)
- Timer duration (2-10 minutes)
- Max players (2-16)
- Click "Create Room"
- Share the 6-character room code with friends
- Open http://localhost:5173
- Click "Join Room"
- Enter your username
- Enter the 6-character room code
- Click "Join Room"
- Wait for players to join
- Click "Ready Up" when ready
- Host can "Start Game" when ready
- Movement: Use Arrow Keys (↑ ↓ ← →) or WASD
- Goal: Navigate to the yellow endpoint before time runs out
- Win Condition: First player to reach the endpoint wins!
- Rankings: If time expires, closest player to endpoint wins
| Key | Action |
|---|---|
| ↑ or W | Move Up |
| ↓ or S | Move Down |
| ← or A | Move Left |
| → or D | Move Right |
multimaze/
├── backend/ # Node.js Express Backend
│ ├── config/ # Configuration files
│ ├── middleware/ # Express middleware
│ ├── models/ # Data models (Room, Player, Maze)
│ ├── routes/ # REST API routes
│ ├── services/ # Business logic
│ │ ├── mazeGenerator.js # Maze generation algorithm
│ │ ├── roomManager.js # Room management
│ │ └── rankingService.js # Ranking calculations
│ ├── sockets/ # Socket.io event handlers
│ ├── utils/ # Utility functions
│ │ ├── pathfinding.js # A* algorithm
│ │ └── validation.js # Input validation
│ ├── server.js # Main server file
│ └── package.json
│
├── frontend/ # React Frontend
│ ├── src/
│ │ ├── components/ # React components
│ │ │ ├── Home.jsx # Landing page
│ │ │ ├── Lobby.jsx # Waiting room
│ │ │ ├── Game.jsx # Main game screen
│ │ │ └── Results.jsx # Results screen
│ │ ├── context/ # React Context
│ │ │ └── GameContext.jsx # Global state management
│ │ ├── services/ # Services
│ │ │ └── socket.js # Socket.io client
│ │ ├── App.jsx # Main app component
│ │ ├── main.jsx # Entry point
│ │ └── index.css # Global styles
│ ├── index.html
│ ├── vite.config.js
│ └── package.json
│
├── docs/ # Documentation
│ └── PRODUCT_SPEC.md # Product specification
│
└── README.md # This file
GET / Server info
GET /api/health Health check
GET /api/stats Server statistics
GET /api/rooms List public rooms
GET /api/rooms/:roomId Get room details
POST /api/rooms/validate Validate room code
| Event | Description | Payload |
|---|---|---|
create-room |
Create new room | {username, settings} |
join-room |
Join existing room | {roomCode, username} |
leave-room |
Leave current room | - |
player-ready |
Toggle ready status | {isReady} |
start-game |
Start the game (host only) | - |
player-move |
Move player | {direction} |
| Event | Description | Data |
|---|---|---|
room-updated |
Room state changed | Room data |
player-joined |
New player joined | Player info |
player-left |
Player left | Player info |
game-started |
Game begins | Room + Maze data |
player-moved |
Player position update | Position data |
player-finished |
Player reached endpoint | Player + time |
winner-announced |
First player finished | Winner info |
timer-update |
Timer tick (1s) | Time remaining |
timer-warning |
Time warning | Seconds left |
game-ended |
Game over | Rankings + stats |
room-closed |
Room was closed | Message |
player-disconnected |
Player disconnected | Player info |
error |
Error occurred | Error message |
- Express.js: HTTP server and REST API
- Socket.io: WebSocket server for real-time communication
- In-Memory Storage: Rooms and players (no database required)
- Maze Generation: Randomized DFS algorithm
- Pathfinding: A* algorithm for distance calculations
- Ranking System: Time-based and distance-based rankings
- React: Component-based UI
- Context API: Global state management
- Socket.io Client: Real-time communication
- Canvas API: Maze rendering
- Tailwind CSS: Styling with glassmorphism
- Vite: Fast development and building
- Glassmorphism UI: Modern frosted glass effect
- Gradient Backgrounds: Dynamic color schemes
- Smooth Animations: Fade-ins, transitions, and hover effects
- Responsive Layout: Works on desktop, tablet, and mobile
- Color-coded Players: Easy player identification
- Medal System: 🥇 🥈 🥉 for top 3 players
- One-click Room Copying: Share room codes easily
- Real-time Updates: Instant player join/leave notifications
- Progress Indicators: Loading states and ready status
- Keyboard Shortcuts: Fast navigation
- Error Handling: User-friendly error messages
- Reconnection Support: Automatic reconnection on disconnect
# Health check
curl http://localhost:3000/api/health
# Server stats
curl http://localhost:3000/api/stats
# List rooms
curl http://localhost:3000/api/rooms- Open http://localhost:5173 in two browsers
- Create a room in Browser 1
- Copy the room code
- Join the room in Browser 2
- Start the game and race!
- Algorithm: Randomized Depth-First Search (DFS)
- Grid-based: Every cell is either a wall or path
- Guaranteed Solvable: Always has a path from start to end
- Multiple Start Positions: Players start in different locations
- Finished Players: Ranked by completion time (faster = better)
- Unfinished Players: Ranked by distance to endpoint (closer = better)
- Tie-breaker: Number of moves (fewer = better)
- Primary: First player to reach endpoint
- Time-based: If timer expires, closest player wins
- Distance: Calculated using A* shortest path algorithm
| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 3000 |
NODE_ENV |
Environment | development |
CORS_ORIGIN |
Frontend URL | http://localhost:5173 |
MAX_ROOMS |
Max concurrent rooms | 50 |
MAX_PLAYERS_PER_ROOM |
Max players per room | 16 |
ROOM_INACTIVITY_TIMEOUT |
Room cleanup time (ms) | 600000 (10 min) |
POSITION_UPDATE_INTERVAL |
Update frequency (ms) | 100 |
| Difficulty | Grid Size | Complexity |
|---|---|---|
| Easy | 15×15 | Low |
| Medium | 25×25 | Moderate |
| Hard | 35×35 | High |
- Minimum: 2 minutes (120s)
- Maximum: 10 minutes (600s)
- Default: 5 minutes (300s)
- Warnings: At 60s, 30s, and 10s remaining
Port already in use:
# Find and kill process on port 3000
lsof -ti:3000 | xargs killConnection refused:
- Check if backend is running
- Verify CORS_ORIGIN matches frontend URL
- Check firewall settings
Can't connect to backend:
- Verify backend is running on port 3000
- Check
SOCKET_URLinfrontend/src/services/socket.js - Check browser console for errors
Vite not found:
cd frontend
npm install --forceRoom code invalid:
- Room codes are 6 characters
- Must be uppercase letters/numbers
- Check if room still exists (may have been cleaned up)
- ✅ 50+ concurrent rooms
- ✅ 500+ concurrent users
- ✅ <100ms response time
- ✅ Position updates every 100ms
- ✅ Auto-cleanup every 60s
- ✅ 60 FPS rendering
- ✅ <2s page load time
- ✅ Smooth animations
- ✅ Responsive canvas scaling
- Runtime: Node.js 16+
- Framework: Express.js 4.18
- WebSocket: Socket.io 4.6
- Security: Helmet, CORS, Rate Limiting
- Utilities: UUID, Compression
- Framework: React 18
- Build Tool: Vite 5
- Styling: Tailwind CSS 3.4
- Icons: Lucide React
- WebSocket: Socket.io Client 4.6
MIT
Built following the MultiMaze Product Specification (see docs/PRODUCT_SPEC.md)
Enjoy playing MultiMaze with your friends! May the fastest navigator win! 🏆
For issues or questions, please check the troubleshooting section or review the product specification in /docs/PRODUCT_SPEC.md.