My Project
 
Loading...
Searching...
No Matches
TicTacToeWindow.h
Go to the documentation of this file.
1
10
11#pragma once
12
13#include "AnimationWindow.h"
14#include "widgets/Button.h"
15#include <vector>
16#include <fstream>
17#include <stdexcept>
18
19using namespace TDT4102;
20
25class TicTacToeWindow : public TDT4102::AnimationWindow {
26public:
35 TicTacToeWindow(int x, int y, int width, int height, const std::string& title);
36
40 void play();
41
42private:
46 void draw_board();
47
51 void draw_marks();
52
56 void draw_winning_line();
57
63 void handle_click(int x, int y);
64
69 bool check_winner();
70
75 bool check_draw();
76
80 void reset_game();
81
86 void write_result_to_file(const std::string& result);
87
91 void cb_reset();
92
96 void cb_quit();
97
98 std::vector<std::vector<char>> board;
102 Button quit_button;
104 std::string result_text;
105 std::pair<Point, Point> winning_line;
106};
void play()
Starts the game loop.
Definition TicTacToeWindow.cpp:48
std::pair< Point, Point > winning_line
Coordinates for the winning line.
Definition TicTacToeWindow.h:105
void reset_game()
Resets the game to its initial state.
Definition TicTacToeWindow.cpp:189
TicTacToeWindow(int x, int y, int width, int height, const std::string &title)
Constructs a TicTacToeWindow object.
Definition TicTacToeWindow.cpp:36
bool check_draw()
Checks if the game is a draw.
Definition TicTacToeWindow.cpp:175
bool game_over
Flag indicating if the game is over.
Definition TicTacToeWindow.h:103
void cb_reset()
Callback function for the reset button.
Definition TicTacToeWindow.cpp:217
void handle_click(int x, int y)
Handles mouse click events to place marks.
Definition TicTacToeWindow.cpp:126
void draw_marks()
Draws the marks (X and O) on the board.
Definition TicTacToeWindow.cpp:101
void write_result_to_file(const std::string &result)
Writes the game result to a file.
Definition TicTacToeWindow.cpp:202
std::string result_text
Text indicating the winner.
Definition TicTacToeWindow.h:104
Button reset_button
Button to reset the game.
Definition TicTacToeWindow.h:101
std::vector< std::vector< char > > board
3x3 board representation.
Definition TicTacToeWindow.h:98
Button quit_button
Button to quit the game.
Definition TicTacToeWindow.h:102
void draw_winning_line()
Draws a line to indicate the winning combination.
Definition TicTacToeWindow.cpp:116
char current_player
Current player ('X' or 'O').
Definition TicTacToeWindow.h:99
void draw_board()
Draws the Tic Tac Toe board.
Definition TicTacToeWindow.cpp:91
void cb_quit()
Callback function for the quit button.
Definition TicTacToeWindow.cpp:225
bool check_winner()
Checks if there is a winner.
Definition TicTacToeWindow.cpp:145
char last_player
Last player to have made a move.
Definition TicTacToeWindow.h:100