My Project
 
Loading...
Searching...
No Matches
TicTacToeWindow Class Reference

Handles the Tic Tac Toe game logic and user interface. More...

#include <TicTacToeWindow.h>

Inheritance diagram for TicTacToeWindow:

Public Member Functions

 TicTacToeWindow (int x, int y, int width, int height, const std::string &title)
 Constructs a TicTacToeWindow object.
 
void play ()
 Starts the game loop.
 

Private Member Functions

void draw_board ()
 Draws the Tic Tac Toe board.
 
void draw_marks ()
 Draws the marks (X and O) on the board.
 
void draw_winning_line ()
 Draws a line to indicate the winning combination.
 
void handle_click (int x, int y)
 Handles mouse click events to place marks.
 
bool check_winner ()
 Checks if there is a winner.
 
bool check_draw ()
 Checks if the game is a draw.
 
void reset_game ()
 Resets the game to its initial state.
 
void write_result_to_file (const std::string &result)
 Writes the game result to a file.
 
void cb_reset ()
 Callback function for the reset button.
 
void cb_quit ()
 Callback function for the quit button.
 

Private Attributes

std::vector< std::vector< char > > board
 3x3 board representation.
 
char current_player
 Current player ('X' or 'O').
 
char last_player
 Last player to have made a move.
 
Button reset_button
 Button to reset the game.
 
Button quit_button
 Button to quit the game.
 
bool game_over
 Flag indicating if the game is over.
 
std::string result_text
 Text indicating the winner.
 
std::pair< Point, Point > winning_line
 Coordinates for the winning line.
 

Detailed Description

Handles the Tic Tac Toe game logic and user interface.

Constructor & Destructor Documentation

◆ TicTacToeWindow()

TicTacToeWindow::TicTacToeWindow ( int x,
int y,
int width,
int height,
const std::string & title )

Constructs a TicTacToeWindow object.

Constructs the TicTacToeWindow object and initializes the game.

Parameters
xX-coordinate of the window.
yY-coordinate of the window.
widthWidth of the window.
heightHeight of the window.
titleTitle of the window.

Member Function Documentation

◆ cb_quit()

void TicTacToeWindow::cb_quit ( )
private

Callback function for the quit button.

◆ cb_reset()

void TicTacToeWindow::cb_reset ( )
private

Callback function for the reset button.

◆ check_draw()

bool TicTacToeWindow::check_draw ( )
private

Checks if the game is a draw.

Checks if the game has ended in a draw.

Returns
true if the game is a draw, false otherwise.

◆ check_winner()

bool TicTacToeWindow::check_winner ( )
private

Checks if there is a winner.

Checks if there is a winner in the game.

Returns
true if a player has won, false otherwise.
true if there is a winner, false otherwise.

◆ draw_board()

void TicTacToeWindow::draw_board ( )
private

Draws the Tic Tac Toe board.

Draws the Tic Tac Toe board grid.

◆ draw_marks()

void TicTacToeWindow::draw_marks ( )
private

Draws the marks (X and O) on the board.

◆ draw_winning_line()

void TicTacToeWindow::draw_winning_line ( )
private

Draws a line to indicate the winning combination.

Draws the line indicating the winning combination on the board.

◆ handle_click()

void TicTacToeWindow::handle_click ( int x,
int y )
private

Handles mouse click events to place marks.

Handles mouse click events and updates the board with marks.

Parameters
xX-coordinate of the click.
yY-coordinate of the click.
xX-coordinate of the mouse click.
yY-coordinate of the mouse click.
Exceptions
std::out_of_rangeif the clicked position is outside the board.

◆ play()

void TicTacToeWindow::play ( )

Starts the game loop.

◆ reset_game()

void TicTacToeWindow::reset_game ( )
private

Resets the game to its initial state.

◆ write_result_to_file()

void TicTacToeWindow::write_result_to_file ( const std::string & result)
private

Writes the game result to a file.

Parameters
resultThe result string to write.

Member Data Documentation

◆ board

std::vector<std::vector<char> > TicTacToeWindow::board
private

3x3 board representation.

◆ current_player

char TicTacToeWindow::current_player
private

Current player ('X' or 'O').

◆ game_over

bool TicTacToeWindow::game_over
private

Flag indicating if the game is over.

◆ last_player

char TicTacToeWindow::last_player
private

Last player to have made a move.

◆ quit_button

Button TicTacToeWindow::quit_button
private

Button to quit the game.

◆ reset_button

Button TicTacToeWindow::reset_button
private

Button to reset the game.

◆ result_text

std::string TicTacToeWindow::result_text
private

Text indicating the winner.

◆ winning_line

std::pair<Point, Point> TicTacToeWindow::winning_line
private

Coordinates for the winning line.


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