This project is a real-time Tic-Tac-Toe game with a FastAPI backend and a React frontend, allowing two players to compete against each other.
- Backend: FastAPI handles game logic, player moves, and game state.
- Frontend: React displays the game board and manages user input.
- WebSockets: Enables real-time communication between server and clients.
- Navigate to the
backend
directory. - Create a
.venv
using python3 - Install dependencies:
pip install -r requirements.txt
- Run the server:
uvicorn main:app --reload
- Navigate to the
frontend
directory. - Install dependencies:
npm install
- Start the React app:
npm start
- Open two browser windows.
- In each window, go to
http://localhost:3000
. - Players take turns clicking on squares to place their symbol (X or O).
- The game updates in real-time for both players.
- The game board is a 3x3 grid.
- Players take turns to place their symbol (X or O) on the board.
- The game checks for a win condition after each move.
- The first player to align three of their symbols in a row, column, or diagonal wins.
-
GameState:
- Represents the current state of a single Tic-Tac-Toe game.
- Manages the game board, current player, and win conditions.
- Contains methods to reset the game, make moves, and check for winners.
-
GameManager:
- Manages multiple game instances. in this case was tested only on one game.
- Responsible for creating new games and keeping track of active games.
- Provides methods to retrieve or reset game states based on game IDs.
-
WebSocketManager (implicit in the main file):
- Handles WebSocket connections for real-time communication between the server and clients.
- Listens for player actions (like moves and new game requests) and broadcasts game state updates to all connected players.
- When a player connects, a new
GameState
is created or retrieved by theGameManager
. - Players take turns making moves, which are processed by the
GameState
. - After each move, the game checks for if a winning series was created and updates the game state.
- The updated game state is sent to all players via WebSockets, ensuring real-time updates.
Enjoy playing!