marvijo-code / code-racer-cc

A competitive coding quiz game with real-time racing mechanics. Built with React frontend and ASP.NET Core backend.

Repository from Github https://github.commarvijo-code/code-racer-ccRepository from Github https://github.commarvijo-code/code-racer-cc

๐ŸŽ๏ธ Code Racer

A Vite + React 2D racing game that teaches Software Engineering skills from beginner to Principal level. Race cars while answering programming questions at checkpoints, with semantic similarity detection to prevent duplicate questions.

๐Ÿš€ Quick Start

Prerequisites

  • Docker and Docker Compose
  • .NET 9 SDK
  • Node.js 18+

Option 1: Simple Startup (Recommended)

# Start backend and database
./start-simple.sh

# In a new terminal, start frontend
cd frontend
npm run dev

Option 2: Manual Setup

# 1. Start PostgreSQL
docker-compose up -d postgres

# 2. Setup database
cd backend
dotnet ef database update
cd ..

# 3. Start backend
cd backend
dotnet run --launch-profile http
# Backend will be available at http://localhost:5000

# 4. In a new terminal, start frontend
cd frontend
npm run dev
# Frontend will be available at http://localhost:5173

๐ŸŽฎ How to Play

  1. Start a Race: Click "๐Ÿ Start Race"
  2. Drive: Use arrow keys to control your car
    • โ†‘ Arrow: Accelerate
    • โ†“ Arrow: Brake/Reverse
    • โ† โ†’ Arrows: Steer
  3. Answer Questions: Hit orange checkpoints to trigger programming quizzes
  4. Lives System: You have 3 lives - lose one for each wrong answer
  5. Spectator Mode: After 3 wrong answers, watch the AI complete the race
  6. Leaderboard: Complete races are ranked by time and score

๐Ÿ—๏ธ Architecture

Frontend (React + TypeScript + Vite)

  • Game Engine: PIXI.js 60 FPS 2D rendering
  • State Management: Zustand with async API integration
  • Styling: Tailwind CSS
  • Real-time Communication: API calls with planned SignalR integration

Backend (.NET 9 + PostgreSQL)

  • APIs: Minimal APIs with Entity Framework Core 9
  • Database: PostgreSQL with EF Core migrations
  • Semantic Similarity: Cosine similarity for question uniqueness
  • Real-time: SignalR hubs for multiplayer features

Key Features

  • โœ… 60 FPS racing with physics
  • โœ… 10-second quiz countdown
  • โœ… Spectator mode after 3 wrong answers
  • โœ… Score submission and leaderboard
  • โœ… Semantic question similarity detection
  • โœ… Real-time multiplayer foundation

๐Ÿ”— API Endpoints

  • GET /health - Health check
  • POST /v1/sessions - Create new race session
  • PATCH /v1/sessions/{id}/answer - Submit quiz answer
  • GET /v1/questions/random - Get random question
  • GET /v1/leaderboards - Get top 10 leaderboard
  • POST /v1/admin/seed - Seed sample questions

๐Ÿงช Testing

# Test API health
curl http://localhost:5000/health

# Get a random question
curl http://localhost:5000/v1/questions/random

# View leaderboard
curl http://localhost:5000/v1/leaderboards

๐Ÿณ Docker Services

The docker-compose.yml includes:

  • PostgreSQL 16: Primary database
  • Milvus: Vector database for semantic similarity (planned)

๐Ÿ”ง Development

Backend

cd backend
dotnet build
dotnet test
dotnet run

Frontend

cd frontend
npm install
npm run dev
npm run build

๐Ÿ› ๏ธ Troubleshooting

Frontend Rollup Error

If you see "Cannot find module @rollup/rollup-*", run:

cd frontend
rm -rf node_modules package-lock.json
npm install

Backend Port Issues

Backend should run on port 5000. Check backend/Properties/launchSettings.json if needed.

Database Connection

Ensure PostgreSQL is running:

docker-compose up -d postgres

๐ŸŽฏ What's Next

This is the Minimal Playable Game (MPG) implementation. Future enhancements include:

  • User authentication and profiles
  • Advanced multiplayer with live race spectating
  • Full Milvus vector database integration
  • Cloud deployment (Azure AKS)
  • Mobile app (React Native)
  • AI-generated questions

๐Ÿ“ License

MIT License - see LICENSE file for details.

About

A competitive coding quiz game with real-time racing mechanics. Built with React frontend and ASP.NET Core backend.


Languages

Language:TypeScript 62.2%Language:C# 32.8%Language:Shell 2.9%Language:CSS 0.7%Language:JavaScript 0.6%Language:Dockerfile 0.5%Language:HTML 0.3%