Skip to content

Riviix/TicTacToe-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tic-Tac-Toe

C++ Windows Linux

A classic Tic-Tac-Toe game implementation in C++ with console interface.

Features

  • Two-player gameplay - Classic X vs O gameplay
  • Input validation - Prevents invalid moves and coordinates
  • Win detection - Automatic detection of wins and draws
  • Replay option - Play multiple games in succession
  • Cross-platform - Works on Windows, Linux, and macOS
  • Multiple compilers - Support for g++, Visual Studio, and Embarcadero

Game Preview

  Current Board:
     0   1   2
   +---+---+---+
 0 |   | X |   |
   +---+---+---+
 1 | O | X | O |
   +---+---+---+
 2 |   | X |   |
   +---+---+---+

Player X wins!

Quick Start

Windows

build.bat
run.bat

Linux/macOS

make
make run

Build Instructions

Automatic Build (Windows)

The build script automatically detects your compiler:

build.bat

Supported compilers (in detection order):

  1. Embarcadero C++ Builder (bcc32c)
  2. MinGW/g++ (g++)
  3. Visual Studio (cl)

Manual Compilation

Compiler Command
g++/MinGW g++ -std=c++11 -Wall -Wextra -O2 main.cpp TicTacToe.cpp -o tictactoe.exe
Embarcadero bcc32c -std=c++11 -O2 -etictactoe.exe main.cpp TicTacToe.cpp
Visual Studio cl /EHsc /std:c++14 /O2 main.cpp TicTacToe.cpp /Fe:tictactoe.exe

Using Make

make           # Build the project
make run       # Build and run
make clean     # Clean build files

How to Play

  1. The game displays a 3x3 grid with coordinate labels
  2. Players alternate turns (X goes first)
  3. Enter coordinates as row column (e.g., 1 2)
  4. Coordinates range from 0 to 2
  5. First player to get three in a row wins
  6. Game detects wins (horizontal, vertical, diagonal) and draws

Example Game Flow

Player X's turn
Enter row and column (0-2): 1 1

Player O's turn  
Enter row and column (0-2): 0 0

Player X's turn
Enter row and column (0-2): 1 2

Project Structure

tic-tac-toe/
├── src/
│   ├── TicTacToe.h          # Class declaration
│   ├── TicTacToe.cpp        # Game logic implementation
│   └── main.cpp             # Entry point
├── build.bat                # Windows build script
├── run.bat                  # Windows run script
├── Makefile                 # Unix build configuration
└── README.md                # This file

Requirements

Minimum Requirements

  • C++11 compatible compiler
  • Windows 7+ or Linux or macOS

Compiler Options

Platform Recommended Compiler Installation
Windows MinGW-w64 MSYS2
Windows Visual Studio VS Community
Windows Embarcadero C++ RAD Studio
Linux g++ sudo apt install g++
macOS clang++ xcode-select --install

Development

Class Overview

class TicTacToe {
private:
    std::vector<std::vector<char>> board;
    char currentPlayer;
    bool gameOver;
    char winner;

public:
    void displayBoard();
    bool makeMove(int row, int col);
    bool checkWin();
    bool checkDraw();
    void switchPlayer();
    void playGame();
    void resetGame();
};

Key Methods

  • displayBoard() - Renders the current game state
  • makeMove() - Validates and executes player moves
  • checkWin() - Detects winning conditions
  • checkDraw() - Detects draw conditions
  • playGame() - Main game loop

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

Not licensed so feel free to do whatever you want.

Acknowledgments

  • Classic Tic-Tac-Toe game rules
  • Console-based user interface design
  • Cross-platform C++ development practices

Built with C++ | Cross-platform | Open Source

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published