A simple console-based Tic-Tac-Toe game implemented in C++. This project showcases basic game development, logic implementation, and use of standard C++ libraries. Ideal for beginners to understand the fundamentals of game development in C++.
- Introduction
- Features
- Getting Started
- How to Play
- Code Explanation
- Future Enhancements
- Contributing
- Contact
The Tic-Tac-Toe Game is a two-player game where each player takes turns marking a space on a 3x3 grid with either 'A' or 'B'. The first player to get three of their marks in a row (vertically, horizontally, or diagonally) wins the game.
- Two-player mode
- Simple text-based user interface
- Input validation to prevent overwriting moves
- Win detection for both players
To run this project, you need:
- A C++ compiler (e.g., GCC, Clang)
- Windows operating system (for
windows.h
library)
- Clone this repository to your local machine:
git clone https://github.com/Dhananjay-Kushwaha/tic-tac-toe.git
- Navigate to the project directory:
cd tic-tac-toe
- Compile the game using your C++ compiler:
g++ -o tic_tac_toe main.cpp
- Run the compiled program:
./tic_tac_toe
- The game starts with a 3x3 grid numbered from 1 to 9.
- Player A is prompted to enter a number corresponding to the grid position they want to mark.
- Player B takes their turn in the same manner.
- The game continues until one player has three of their marks in a row or all positions are filled.
- If a player tries to mark an already occupied position, they are prompted to try again.
The core logic of the game is implemented in a do-while
loop which runs until a win condition is met or the grid is full. The grid is represented by a 2D array of strings. Each player's move is validated to ensure the chosen position is not already occupied.
Key functions include:
- Displaying the game board
- Validating player input
- Checking for win conditions
- Implementing a single-player mode with AI
- Adding a graphical user interface
- Enhancing input validation and error handling
- Refactoring the code for better readability and maintainability
Contributions are welcome! Please fork the repository and submit a pull request for any improvements or additions.
If you have any questions or feedback, feel free to reach out:
- GitHub: Dhananjay-Kushwaha
- LinkedIn: Dhananjay-Kushwaha