A multiplayer trivia game where two players compete head-to-head answering questions generated by AI. Players use different keyboard controls (WASD vs Arrow keys) in a Kahoot-style format with timed questions.
- Two-Player Gameplay: Player 1 uses WASD, Player 2 uses Arrow keys
- AI-Generated Questions: Questions are generated based on any topic you choose
- Timed Questions: 15-second timer for each question with visual countdown
- Real-time Scoring: Track scores for both players throughout the game
- Modern UI: Beautiful, responsive design with smooth animations
- Flexible Topics: Enter any topic and get relevant trivia questions
- Fallback System: Works even when API is unavailable
- Choose a Topic: Enter any topic you'd like to be quizzed on (e.g., "Science", "Movies", "History")
- Start the Game: Click "Start Game" to begin generating questions
- Answer Questions: When questions appear, players select answers using their assigned keys:
- Player 1: W (top), A (left), S (bottom), D (right)
- Player 2: ↑ (top), ← (left), ↓ (bottom), → (right)
- Beat the Timer: You have 15 seconds per question to make your selection
- See Results: After 5 questions, see who won and play again!
-
Install Dependencies:
npm install
-
Start the Server:
npm start
-
Open Your Browser: Navigate to
http://localhost:3000
Simply open index.html in your web browser. The game will work with fallback questions when the API server isn't running.
triviaGame/
├── index.html # Main game interface
├── style.css # Styling and animations
├── script.js # Game logic and client-side code
├── api-server.js # Node.js server for API calls
├── package.json # Dependencies and scripts
└── README.md # This file
- Frontend: Pure HTML, CSS, and JavaScript (no frameworks)
- Backend: Express.js server for API integration
- AI Integration: Ready for LLM APIs (OpenAI, Anthropic, etc.)
- Responsive Design: Works on desktop and mobile devices
The game is designed to integrate with LLM APIs for question generation. Currently uses mock data, but can be easily connected to:
- OpenAI GPT API
- Anthropic Claude API
- Google Gemini API
- Any other text generation API
To integrate a real LLM API:
- Add your API key to environment variables
- Uncomment and modify the
generateQuestionsWithLLMfunction inapi-server.js - Install additional dependencies as needed (e.g.,
openaipackage)
// In api-server.js, replace the mock function with:
const OpenAI = require('openai');
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
async function generateQuestionsWithLLM(topic) {
const response = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [{
role: "user",
content: `Generate 5 trivia questions about ${topic}...`
}]
});
// Parse and return questions
}- Modify
style.cssto change colors, fonts, and layout - The design uses CSS Grid and Flexbox for responsive layouts
- Custom CSS animations for smooth transitions
- Change timer duration in
script.js(currently 15 seconds) - Modify number of questions per game
- Adjust scoring system
- Add sound effects or music
- Key bindings are defined in the
bindKeyboardEvents()method - Easy to modify or add additional control schemes
- Chrome/Chromium (recommended)
- Firefox
- Safari
- Edge
MIT License - feel free to modify and distribute!
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
- Questions not loading: Check if the server is running on port 3000
- Keys not working: Make sure the game screen is in focus
- Styling issues: Clear browser cache and reload
- API errors: Check console for detailed error messages
- Use browser developer tools to debug
- Check the console for error messages
- Test with different topics to ensure robustness
- Verify responsive design on different screen sizes
- Add sound effects and background music
- Implement difficulty levels
- Add more visual feedback for correct/incorrect answers
- Create tournament mode for multiple rounds
- Add player name customization
- Implement question categories
- Add statistics and score history
- Create mobile app version
Enjoy playing Trivia Showdown! 🎉