A real-time multiplayer quiz game with AI-powered question generation. Teams compete by answering questions of varying difficulty levels for points.
- Real-time Multiplayer: WebSocket-based gameplay with instant updates
- Team-Based Competition: Two teams battle for the highest score
- Dynamic Difficulty: Players choose between Easy (50pts), Medium (75pts), and Hard (100pts) questions
- AI-Powered Questions: Claude AI generates custom quiz questions on any topic
- Mock Mode: Pre-defined questions for testing without API costs
- Battle Theme: Engaging military/battle-inspired UI design
- Admin Controls: Host can manage games, view scores, and end games
- Responsive Design: Works on desktop and mobile devices
- Node.js 18+
- npm or yarn
# Clone the repository
git clone https://github.com/amrit-quizizz/battlemania.git
cd battlemania
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env
# Edit .env and configure QUIZ_MODE (mock or ai)
# Start the servers
npm run dev # Web app on http://localhost:5173
npm run dev:server # WebSocket server on ws://localhost:3002📖 For detailed setup instructions, see SETUP.md
- Navigate to the home screen
- Click "Start New Game"
- Enter a quiz topic (or leave blank for default)
- Share the 6-character game code with players
- Wait for players to join (minimum 1 per team)
- Click "Start Game" to begin
- Click "Join Game" from home screen
- Enter your name and the game code
- Get assigned to Team A or Team B
- Select difficulty level when your turn starts
- Answer the question before time runs out
- Watch scores update after each round
- 15-second timer for each turn (shared between level selection and answering)
- Early selection = more time to answer the question
- No selection = random difficulty assigned
- Points: Easy (50), Medium (75), Hard (100)
- Winner: Team with highest score when host ends game
QUIZ_MODE=mock- Uses pre-defined questions from
server/questions.json - No API key required
- Perfect for development and testing
- Topic input is ignored
QUIZ_MODE=ai
ANTHROPIC_API_KEY=sk-ant-api03-...- Generates custom questions using Claude AI
- Requires Anthropic API key
- Creates topic-specific questions
- 5 questions per difficulty level
- Frontend: React 18, TypeScript, Vite
- Backend: Node.js, WebSocket (ws)
- AI: Anthropic Claude API (Sonnet 4)
- Styling: CSS with battle-themed design
battlemania/
├── src/
│ ├── quiz/
│ │ ├── StartGame.tsx # Admin game creation
│ │ ├── JoinGame.tsx # Player join screen
│ │ ├── QuizGame.tsx # Admin game view
│ │ └── PlayerGame.tsx # Player game view
│ └── App.tsx
├── server/
│ ├── index.ts # WebSocket server & game logic
│ ├── quizGenerator.ts # AI quiz generation
│ └── questions.json # Default questions (mock mode)
├── .env.example # Environment template
├── SETUP.md # Detailed setup guide
└── package.json
| Variable | Required | Default | Description |
|---|---|---|---|
QUIZ_MODE |
No | mock |
mock or ai |
ANTHROPIC_API_KEY |
For AI mode | - | Claude API key |
WS_PORT |
No | 3002 |
WebSocket server port |
Edit server/questions.json:
{
"questions": [
{
"id": 1,
"difficulty": "low",
"question": "What is 2 + 2?",
"options": ["3", "4", "5", "6"],
"correctAnswer": 1
}
]
}WebSocket connection fails
# Check if server is running
lsof -ti:3002
# Restart the server
npm run dev:serverAI mode not working
- Verify
ANTHROPIC_API_KEYin.env - Check API credits at https://console.anthropic.com
- System falls back to mock mode on error
Players can't join
- Confirm WebSocket server is running on port 3002
- Check game code is correct (case-sensitive)
- Try refreshing the page
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Make your changes
- Test both mock and AI modes
- Commit:
git commit -m "Add my feature" - Push:
git push origin feature/my-feature - Open a Pull Request
Important: Never commit .env files with API keys!
MIT License - see LICENSE file for details
For issues and questions:
- Create an issue on GitHub
- Check SETUP.md for detailed documentation
Built with ⚡ using React, TypeScript, and Claude AI