two player game, deployed in cloudflare https://akib35.dev/tic-tac-toe/
  • TypeScript 96.3%
  • HTML 1.5%
  • JavaScript 1.4%
  • CSS 0.8%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
akib-cdda 4f583d7346 Update README formatting and add AI disclosure
- Move logo to public directory
- Remove horizontal dividers between sections
- Add AI tools disclosure section
2026-09-20 11:36:00 +06:00
.forgejo/workflows new logo 2026-09-20 11:30:07 +06:00
docs Update deployment documentation and configuration for Cloudflare integration 2026-07-01 16:37:46 +06:00
public new logo 2026-09-20 11:30:07 +06:00
src fix: verify turnstile once on page load and maintain active session across matches 2026-09-20 10:40:23 +06:00
.gitignore Add .idea to gitignore 2026-09-17 15:25:07 +06:00
dist.tar.gz new logo 2026-09-20 11:30:07 +06:00
index.html fix: turnstile type narrowing and add favicon site icon 2026-09-17 16:25:33 +06:00
LICENSE Initial commit 2026-06-30 04:27:45 +00:00
package.json update with DO 2026-09-17 14:24:36 +06:00
postcss.config.js implement in local 2026-06-30 17:31:14 +06:00
README.md Update README formatting and add AI disclosure 2026-09-20 11:36:00 +06:00
tailwind.config.js implement in local 2026-06-30 17:31:14 +06:00
tsconfig.app.json update with DO 2026-09-17 14:24:36 +06:00
tsconfig.json update with DO 2026-09-17 14:24:36 +06:00
tsconfig.worker.json update with DO 2026-09-17 14:24:36 +06:00
vite.config.js Add offline bot gameplay with AI opponent 2026-09-17 14:49:24 +06:00
wrangler.jsonc feat: add invisible Cloudflare Turnstile protection 2026-09-17 16:08:00 +06:00

Tic-Tac-Toe Logo

🎮 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 Matchmaker DO with FIFO pairing and real-time queue position updates.
  • 🎮 Stateful Game Rooms (TicTacToeGame DO):
    • 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 (ASSETS binding) 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.