This is a fully-featured Tic-Tac-Toe game built with Flask, Pygame, PostgreSQL/Firebase, and WebSockets.
It supports multiplayer matchmaking, AI opponents, chat system, leaderboards, animations, and sound effects.
✅ Classic Tic-Tac-Toe Gameplay (Pygame-based UI)
✅ Multiplayer Mode (Real-time matchmaking via Flask-SocketIO)
✅ Single-Player Mode (AI Opponent) (Minimax Algorithm)
✅ ELO-Based Ranking System
✅ In-Game Chat System
✅ Flashing Win Animation & Sound Effects
✅ Match History & Leaderboard
tic-tac-toe-web/
├── backend/ # Flask Backend
│ ├── models/ # Database Models
│ ├── routes/ # API Endpoints
│ ├── services/ # Business Logic
│ ├── utils/ # Utilities
│ ├── database/ # Database Setup
│ ├── scripts/ # Deployment & Server Management
│ ├── tests/ # Unit & Integration Tests
│ ├── config.py # Configuration
│ ├── app.py # Main Flask Application
│ ├── requirements.txt # Dependencies
│ ├── .env # Environment Variables
│ ├── README.md # Backend Documentation
├── frontend/ # Pygame Frontend
│ ├── assets/ # Game Assets (Images, Sounds)
│ ├── components/ # UI Components
│ ├── services/ # API & WebSocket Services
│ ├── main.py # Main Pygame Application
│ ├── settings.py # Game Configuration
│ ├── README.md # Frontend Documentation
├── README.md # Full Project Documentation
git clone https://github.com/Nuraj250/tic-tac-toe-web.git
cd tic-tac-toe-webcd backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txtCreate a .env file in backend/:
SECRET_KEY=your_secret_key
JWT_SECRET_KEY=your_jwt_secret
DATABASE_URL=postgresql://user:password@localhost/tic_tac_toe
SOCKETIO_MESSAGE_QUEUE=redis://python database/init_db.pybash scripts/start_server.shor manually:
python app.pycd frontend
pip install pygame requests socketio-clientbash ../backend/scripts/start_game.shor manually:
python main.py- Click on a cell to place your move.
- Wait for your turn (if multiplayer).
- Press "H" to view match history.
- Click "Restart" after a win to start a new game.
- The game automatically pairs two players.
- Wait in the lobby until an opponent joins.
- Moves are synced in real-time via WebSockets.
- Click on a cell to place "X".
- AI will automatically respond as "O".
- Try to win against the AI!
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/auth/register |
Register a new user |
POST |
/api/auth/login |
Login & get JWT token |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/game/play_move |
Submit a move |
GET |
/api/match/{id} |
Get match history |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/ai-move |
Get AI move suggestion |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/leaderboard |
Get top players |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/chat/send-message |
Send chat message |
- Moves are animated with a fade effect.
- Winning row flashes yellow before showing the restart button.
| Action | Sound File | Description |
|---|---|---|
| Move Placement | move_sound.wav |
Plays when a move is made |
| Click Sound | click_sound.wav |
Plays when clicking UI elements |
| Win Sound | win_sound.wav |
Plays when a player wins |
heroku login
heroku create tic-tac-toe-web
git push heroku mainscp -i your-key.pem backend/* ec2-user@your-instance:/home/ec2-user/
ssh -i your-key.pem ec2-user@your-instanceUse Docker:
docker build -t tic-tac-toe-backend .
docker run -p 5000:5000 tic-tac-toe-backend- Ensure Flask backend is running:
bash backend/scripts/start_server.sh- Check
API_BASE_URLinfrontend/settings.py.
- Ensure PostgreSQL is running:
sudo service postgresql start- Verify database URL in
.env.
- Install Redis:
sudo apt install redis-server- Start Redis:
redis-serverThis project is licensed under the MIT License.
💻 Nuraj
🚀 Happy Coding! 🎮🔥