factoid-trivia
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data โ all from the browser, and deployed in milliseconds.
index.ts
https://bmitchinson--9127face487a11f08b4576b3cceeab13.web.val.run
A realtime trivia game themed like a USPS post office, supporting up to 30 concurrent users.
https://www.val.town/x/bmitchinson/factoid-trivia
- USPS post office themed design
- Real-time user presence (see who's online)
- Name entry and user management
- Support for up to 30 concurrent players
- NEW: Complete trivia game functionality:
- Fact submission by each player
- Random fact selection for rounds
- Voting system where players guess whose fact it is
- Real-time vote tracking and display
- Answer reveal with vote results
- Scoring system and leaderboard
- Skip functionality for rounds
- Join the Game: Enter your name to join the post office
- Submit a Fact: Each player submits an interesting fact about themselves
- Wait for Others: Game can start when at least 2 players have submitted facts
- Vote on Facts: When a fact is displayed, guess which player it belongs to
- See Results: After voting, reveal answers to see who was correct
- Earn Points: Get 1 point for each correct guess
- Climb the Leaderboard: Track your score against other players
Join Game โ All Players Submit Facts โ Facts Get Queued โ
Vote on Random Facts โ See Results โ Earn Points โ
Next Round โ Repeat Until All Facts Used
- Everyone Submits Facts: All players can and should submit facts
- Random Queue System: Facts are randomly selected from the queue for each round
- Flexible Start: Game can start with 2+ facts, or wait for everyone
- Real-time Progress: See who has/hasn't submitted facts yet
- Complete Fact Usage: All submitted facts will eventually be used in rounds
โโโ backend/
โ โโโ index.ts # Main Hono server with game API endpoints
โ โโโ database/
โ โ โโโ migrations.ts # SQLite schema for users, facts, votes, rounds
โ โ โโโ queries.ts # Database query functions for game logic
โ โโโ routes/
โ โโโ websocket.ts # WebSocket connection handling (future)
โโโ frontend/
โ โโโ index.html # Main HTML template
โ โโโ index.tsx # React frontend entry point
โ โโโ components/
โ โ โโโ App.tsx # Main app component with game state management
โ โ โโโ NameEntry.tsx # Name entry form
โ โ โโโ FactEntry.tsx # Fact submission form
โ โ โโโ GameLobby.tsx # Waiting area showing fact collection progress
โ โ โโโ GameRound.tsx # Active round with voting interface
โ โ โโโ Leaderboard.tsx # Score tracking display
โ โ โโโ UserList.tsx # Online users display
โ โโโ style.css # USPS-themed styles
โโโ shared/
โโโ types.ts # Shared TypeScript types for game objects
- The backend runs on Hono with WebSocket support for real-time features
- Frontend uses React with WebSocket client for real-time updates
- SQLite stores user sessions and game state
- USPS-themed styling with postal colors and typography
- โ User name entry and management
- โ Real-time user presence (up to 30 players)
- โ USPS theming and design
- โ Fact submission system
- โ Random fact selection for rounds
- โ Voting system with real-time updates
- โ Answer reveal and vote result display
- โ Scoring system and leaderboard
- โ Skip round functionality
- โ Complete game flow from start to finish
GET /api/game-state- Get current game state including users, rounds, leaderboardPOST /api/join- Join the game with a namePOST /api/leave- Leave the gamePOST /api/submit-fact- Submit a personal factPOST /api/start-round- Start a new round with a random factPOST /api/vote- Cast a vote for who you think the fact belongs toPOST /api/reveal- Reveal the answer and award pointsPOST /api/skip- Skip the current roundPOST /api/admin/kick-all- [ADMIN] Clear all game data and kick all players
The game includes an admin panel accessible through a discrete "Admin" link at the bottom of the page. This provides:
- Kick All Players: Immediately disconnects all connected players and clears all game data including:
- All user sessions
- All submitted facts
- All votes and rounds
- All scores and leaderboard data
- Current game state
โ ๏ธ Warning: The kick all function is irreversible and will completely reset the game to its initial state.