Skip to content

anmol95subedi/tictactoe-in-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Tic-Tac-Toe in C++

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.

Features

  • Object-Oriented Design: Developed using distinct classes (board, symbol, score, and turn) 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.

How to Play

1. Main Menu Navigation

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 :

2. Making a Move

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 Architecture Overview

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()

Prerequisites & Compilation

To compile and run this program, you will need a standard C++ compiler (such as g++).

Using GCC via Terminal/Command Prompt:

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

About

This project demonstrates the progression of my C++ skills from basic syntax to implementing oop along with array to handle the games grid and classes to control the logic. A simple CLI is made to provide user with multiple options such as to play, check score,change playing symbols,etc.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages