two player game, deployed in cloudflare
https://akib35.dev/tic-tac-toe/
- TypeScript 96.3%
- HTML 1.5%
- JavaScript 1.4%
- CSS 0.8%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
- Move logo to public directory - Remove horizontal dividers between sections - Add AI tools disclosure section |
||
| .forgejo/workflows | ||
| docs | ||
| public | ||
| src | ||
| .gitignore | ||
| dist.tar.gz | ||
| index.html | ||
| LICENSE | ||
| package.json | ||
| postcss.config.js | ||
| README.md | ||
| tailwind.config.js | ||
| tsconfig.app.json | ||
| tsconfig.json | ||
| tsconfig.worker.json | ||
| vite.config.js | ||
| wrangler.jsonc | ||
🎮 Real-Time Multiplayer Tic-Tac-Toe on Cloudflare
A modern, fullstack, real-time 2-player Tic-Tac-Toe multiplayer game built directly on Cloudflare Workers and Durable Objects.
✨ Features
- ⚡ Cloudflare Durable Objects Matchmaking: Instant matchmaking queue powered by a dedicated
MatchmakerDO with FIFO pairing and real-time queue position updates. - 🎮 Stateful Game Rooms (
TicTacToeGameDO):- WebSocket Hibernation API for real-time, low-latency, and cost-efficient game coordination.
- SQLite persistence (
ctx.storage.sql) for game state, running series scoreboards, and active sessions. - Automatic reconnection handling with persistent player sessions.
- 30-second disconnect grace period with DO alarms before forfeit.
- Interactive multi-round rematch system (alternating starting turns, preserved score tracking).
- In-game quick reactions & emoji popups with custom animations.
- 🔗 Private Rooms & Shareable Invite Links: Create private rooms and share one-click invite URLs (
?room=XYZ) with friends. - 🤖 Offline Bot Mode: Practice offline against an intelligent AI bot with Easy, Medium, and Unbeatable Minimax difficulty levels.
- 🔊 Web Audio API Sound Effects: Synthesized move chimes, win chords, and notification sounds with mute toggle (no external audio assets required).
- 🎉 Confetti & Visual Polish: Built with React 18, Tailwind CSS, Lucide icons, and canvas-confetti.
- 📦 Single-Worker Architecture: Frontend SPA served seamlessly via Cloudflare Workers Static Assets (
ASSETSbinding) alongside backend WebSockets and DOs.
🛠️ Architecture
┌────────────────────────────────────────┐
│ Cloudflare Worker │
│ (fetch router) │
└───────┬────────────────────────┬───────┘
│ │
Upgrade: WebSocket (/api/matchmake) │ Upgrade: WebSocket (/api/game/:id)
▼ ▼
┌───────────────────────────┐ ┌───────────────────────────┐
│ Matchmaker DO │ │ TicTacToeGame DO │
│ - Global FIFO Queue │ │ - Per-room DO instance │
│ - Auto-pairing │ │ - Hibernation WebSockets │
│ - SQLite Stats │ │ - SQLite Game Storage │
│ │ │ - Disconnect Alarms │
└───────────────────────────┘ └───────────────────────────┘
🚀 Getting Started
1. Install Dependencies
npm install
2. Local Development
You can run both the Vite frontend and Cloudflare Worker locally:
# Terminal 1: Run Cloudflare Worker & Durable Objects emulator
npm run worker:dev
# Terminal 2: Run Vite dev server with WebSocket proxy
npm run dev
Open http://localhost:5173 in your browser. Open multiple windows/tabs or an incognito tab to test real-time matchmaking!
☁️ Deployment to Cloudflare
To deploy to Cloudflare:
# 1. Login to Wrangler (if not already logged in)
npx wrangler login
# 2. Build frontend and deploy Worker + Assets + Durable Objects
npm run deploy
Your game will be live at https://tic-tac-toe.<your-subdomain>.workers.dev!
📁 Project Structure
├── src/
│ ├── client.tsx # React UI (Lobby, Queue, Game Room, AI Game)
│ ├── main.tsx # React DOM Entry
│ ├── server.ts # Cloudflare Worker, Matchmaker DO, Game DO
│ ├── types.ts # Shared TypeScript types & WS message contracts
│ ├── lib/
│ │ ├── ai.ts # Minimax AI algorithm & difficulty levels
│ │ └── sounds.ts # Web Audio API synthesizer
│ └── index.css # Tailwind styles & animations
├── wrangler.jsonc # Cloudflare Worker, DO bindings & SQLite migrations
├── vite.config.js # Vite config with /api proxy to Wrangler
├── package.json
└── tsconfig.json
📜 License
MIT
🚩 Disclosure
This repository has high influence from AI tools. Please report to owner if vulnarability found.