Skip to content

About

Web app that lets you choose trivia topic and play as a 2 player game

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

🧠 Trivia Showdown

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.

✨ Features

  • 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

🎮 How to Play

  1. Choose a Topic: Enter any topic you'd like to be quizzed on (e.g., "Science", "Movies", "History")
  2. Start the Game: Click "Start Game" to begin generating questions
  3. 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)
  4. Beat the Timer: You have 15 seconds per question to make your selection
  5. See Results: After 5 questions, see who won and play again!

🚀 Quick Start

Option 1: With Node.js Server (Recommended)

  1. Install Dependencies:

    npm install
  2. Start the Server:

    npm start
  3. Open Your Browser: Navigate to http://localhost:3000

Option 2: Static Files Only

Simply open index.html in your web browser. The game will work with fallback questions when the API server isn't running.

🛠️ Technical Details

File Structure

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

Key Components

  • 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

🔧 API Integration

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:

  1. Add your API key to environment variables
  2. Uncomment and modify the generateQuestionsWithLLM function in api-server.js
  3. Install additional dependencies as needed (e.g., openai package)

Example OpenAI Integration

// 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
}

🎨 Customization

Styling

  • Modify style.css to change colors, fonts, and layout
  • The design uses CSS Grid and Flexbox for responsive layouts
  • Custom CSS animations for smooth transitions

Game Settings

  • Change timer duration in script.js (currently 15 seconds)
  • Modify number of questions per game
  • Adjust scoring system
  • Add sound effects or music

Controls

  • Key bindings are defined in the bindKeyboardEvents() method
  • Easy to modify or add additional control schemes

🌐 Browser Compatibility

  • Chrome/Chromium (recommended)
  • Firefox
  • Safari
  • Edge

📝 License

MIT License - feel free to modify and distribute!

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

🐛 Troubleshooting

Common Issues

  1. Questions not loading: Check if the server is running on port 3000
  2. Keys not working: Make sure the game screen is in focus
  3. Styling issues: Clear browser cache and reload
  4. API errors: Check console for detailed error messages

Development Tips

  • 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

🎯 Future Enhancements

  • 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! 🎉

About

Web app that lets you choose trivia topic and play as a 2 player game

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages