TheCOSCGameProject  1.0
Public Member Functions | List of all members
TicTacToe Class Reference

Implements the TicTacToe mini-game. More...

#include <minigames.h>

Inheritance diagram for TicTacToe:
Inheritance graph
[legend]
Collaboration diagram for TicTacToe:
Collaboration graph
[legend]

Public Member Functions

void printBoard ()
 Prints the TicTacToe board. More...
 
char getSquare (int row, int col) const
 Gets the value of a specific square on the board. More...
 
void playerMove (int row, int col)
 Handles the player's move. More...
 
void computerTurn ()
 Handles the computer's move. More...
 
bool checkForWin ()
 Checks if there is a winner. More...
 
bool start () override
 Starts the TicTacToe game. More...
 
bool handlePlayerTurn ()
 
bool getPlayerMove (int &row, int &col)
 
bool isValidMove (int row, int col)
 
void makeMove (int row, int col, char symbol)
 
bool isGameOver (int moveCount)
 
bool processComputerTurn ()
 
void setBoard (char newBoard[3][3])
 
void delayTurn ()
 
std::string getGameName () override
 Gets the name of the game. More...
 
- Public Member Functions inherited from Game
virtual ~Game ()
 Virtual destructor for proper cleanup of derived classes. More...
 

Detailed Description

Implements the TicTacToe mini-game.

The TicTacToe class allows two players (or a player and the computer) to play a game of TicTacToe.

Member Function Documentation

◆ checkForWin()

bool TicTacToe::checkForWin ( )

Checks if there is a winner.

Check if there is a winner in TicTacToe.

Returns
True if there is a winner, otherwise false.
True if there is a winner, false otherwise.

Checks all rows, columns, and diagonals for three matching symbols ('X' or 'O').

◆ computerTurn()

void TicTacToe::computerTurn ( )

Handles the computer's move.

Handle the computer's turn in TicTacToe.

The computer randomly selects an empty square to place its 'O'.

◆ delayTurn()

void TicTacToe::delayTurn ( )

◆ getGameName()

std::string TicTacToe::getGameName ( )
overridevirtual

Gets the name of the game.

Get the name of the TicTacToe game.

Returns
A string representing the name of the game.

Implements Game.

◆ getPlayerMove()

bool TicTacToe::getPlayerMove ( int &  row,
int &  col 
)

◆ getSquare()

char TicTacToe::getSquare ( int  row,
int  col 
) const

Gets the value of a specific square on the board.

Get the value at a specific square on the TicTacToe board.

Parameters
rowThe row of the square.
colThe column of the square.
Returns
The character at the specified position on the board.
Parameters
rowThe row of the square (0-indexed).
colThe column of the square (0-indexed).
Returns
The character ('X', 'O', or ' ') at the specified square.

◆ handlePlayerTurn()

bool TicTacToe::handlePlayerTurn ( )

◆ isGameOver()

bool TicTacToe::isGameOver ( int  moveCount)

◆ isValidMove()

bool TicTacToe::isValidMove ( int  row,
int  col 
)

◆ makeMove()

void TicTacToe::makeMove ( int  row,
int  col,
char  symbol 
)

◆ playerMove()

void TicTacToe::playerMove ( int  row,
int  col 
)

Handles the player's move.

Handle the player's move in TicTacToe.

Parameters
rowThe row of the square where the player wants to move.
colThe column of the square where the player wants to move.
rowThe row where the player wants to place their 'X' (1-indexed).
colThe column where the player wants to place their 'X' (1-indexed).

◆ printBoard()

void TicTacToe::printBoard ( )

Prints the TicTacToe board.

Print the current state of the TicTacToe board.

Displays the current state of the TicTacToe board, showing the positions of 'X', 'O', and empty spaces.

◆ processComputerTurn()

bool TicTacToe::processComputerTurn ( )

◆ setBoard()

void TicTacToe::setBoard ( char  newBoard[3][3])

◆ start()

bool TicTacToe::start ( )
overridevirtual

Starts the TicTacToe game.

Returns
True if the game was completed successfully, otherwise false.

Implements Game.


The documentation for this class was generated from the following files: