A simple, object-oriented console-based Tic-Tac-Toe game written in C++. The game features a main menu interface where players can play matches, track cumulative scores, customize player symbols, and handle edge cases like invalid moves and ties seamlessly.
- Object-Oriented Design: Developed using distinct classes (
board,symbol,score, andturn) to encapsulate game logic cleanly. - Persistent Scoreboard: Tracks wins for both Player 1 and Player 2 across multiple consecutive games during a single session.
- Customizable Symbols: Allows players to change their characters from the default 'O' and 'X' to any symbol of their choice via the settings menu.
- Cross-Platform Screen Clearing: Includes a preprocessor-supported
clearScreen()function that works seamlessly on both Windows (cls) and Unix-based (clear) systems. - Robust Input Validation: Prevents players from picking already-occupied cells or entering invalid coordinates outside the grid bounds.
When you run the executable, you will be greeted by the main command menu:
****************Tic-Tac-Toe****************
1) Play ( Enter p to play )
2) Score ( Enter s to check scores )
3) Characters / Symbols ( Enter c to check or update symbol of players )
4) Quit ( Enter q to quit )
Enter your command :
When a round begins, the game renders a 3x3 grid with row and column indexes. To place your symbol, enter a two-digit integer pair corresponding to the (Row, Column) index without spaces or commas:
* **Top-Left cell:** `11`
* **Center cell:** `22`
* **Bottom-Right cell:** `33`
| Class | Purpose | Key Methods |
|---|---|---|
board |
Handles the 3x3 underlying char matrix, checks for win/tie conditions, and prints the ASCII game board. | showboard(), validity(), check_winner(), check_status() |
symbol |
Manages custom or default character tokens assigned to each player. | getsymbol_p1(), update_symbol(), checksymbol() |
score |
Tracks continuous session wins for Player 1 and Player 2. | get_score_p1(), update_p1(), update_p2() |
turn |
Controls current turn states and alternates gameplay between participants. | check_turn(), update_turn() |
To compile and run this program, you will need a standard C++ compiler (such as g++).
Clone or download the repository files.
2. Open your terminal in the directory containing the source code file.
3. Compile the code using:
```bash
g++ -o tictactoe main.cpp
Run the compiled executable:
Windows: tictactoe.exe
Linux/macOS: ./tictactoe