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-web
cd backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
Create 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.py
bash scripts/start_server.sh
or manually:
python app.py
cd frontend
pip install pygame requests socketio-client
bash ../backend/scripts/start_game.sh
or 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 main
scp -i your-key.pem backend/* ec2-user@your-instance:/home/ec2-user/
ssh -i your-key.pem ec2-user@your-instance
Use 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_URL
infrontend/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-server
This project is licensed under the MIT License.
๐ป Nuraj
๐ Happy Coding! ๐ฎ๐ฅ