• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • Weโ€™re hiring!
Log inSign up
bmitchinson

bmitchinson

factoid-trivia

Public
Like
factoid-trivia
Home
Code
8
.bruno
1
backend
3
frontend
4
shared
1
.instructions.md
.vtignore
README.md
deno.json
Branches
2
Pull requests
Remixes
History
Environment variables
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.
Sign up now
Code
/
Code
/
Search
index.ts
https://bmitchinson--9127face487a11f08b4576b3cceeab13.web.val.run
README.md

Trivia Game

A realtime trivia game themed like a USPS post office, supporting up to 30 concurrent users.

https://www.val.town/x/bmitchinson/factoid-trivia

Features

  • 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

How to Play

  1. Join the Game: Enter your name to join the post office
  2. Submit a Fact: Each player submits an interesting fact about themselves
  3. Wait for Others: Game can start when at least 2 players have submitted facts
  4. Vote on Facts: When a fact is displayed, guess which player it belongs to
  5. See Results: After voting, reveal answers to see who was correct
  6. Earn Points: Get 1 point for each correct guess
  7. Climb the Leaderboard: Track your score against other players

Game Flow

Join Game โ†’ All Players Submit Facts โ†’ Facts Get Queued โ†’
Vote on Random Facts โ†’ See Results โ†’ Earn Points โ†’
Next Round โ†’ Repeat Until All Facts Used

Key Features

  • 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

Project Structure

โ”œโ”€โ”€ 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

Getting Started

  1. The backend runs on Hono with WebSocket support for real-time features
  2. Frontend uses React with WebSocket client for real-time updates
  3. SQLite stores user sessions and game state
  4. USPS-themed styling with postal colors and typography

Current Status

  • โœ… 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

API Endpoints

  • GET /api/game-state - Get current game state including users, rounds, leaderboard
  • POST /api/join - Join the game with a name
  • POST /api/leave - Leave the game
  • POST /api/submit-fact - Submit a personal fact
  • POST /api/start-round - Start a new round with a random fact
  • POST /api/vote - Cast a vote for who you think the fact belongs to
  • POST /api/reveal - Reveal the answer and award points
  • POST /api/skip - Skip the current round
  • POST /api/admin/kick-all - [ADMIN] Clear all game data and kick all players

Admin Features

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.

HTTP
  • index.ts
    bmitchinson--91โ€ฆ13.web.val.run
Code
.brunobackendfrontendshared.instructions.md.vtignoreREADME.mddeno.json
FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
Weโ€™re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
ยฉ 2025 Val Town, Inc.