-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoard.hpp
53 lines (37 loc) · 1.36 KB
/
Board.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef BOARD
#define BOARD
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
class Board
{
private:
unsigned int size;
unsigned int taken_fields = 0;
unsigned int winning_condition;
char first_player_symbol;
char second_player_symbol;
char** board_table;
void allocate_board_table();
void deallocate_board_table();
char& get_field(unsigned int row, unsigned int column);
public:
Board() : size(3), first_player_symbol('O'), second_player_symbol('X') {allocate_board_table();}
Board(unsigned int s, unsigned int win_cond) : size(s), winning_condition(win_cond), first_player_symbol('O'), second_player_symbol('X') {allocate_board_table();}
Board(unsigned int s, unsigned int win_cond, char p1, char p2) : size(s), winning_condition(win_cond), first_player_symbol(p1), second_player_symbol(p2) {allocate_board_table();}
~Board() {deallocate_board_table();}
bool make_move(unsigned int row, unsigned int col, bool first_player = true);
bool undo_move(unsigned int row, unsigned int col);
bool check_win(bool first_player);
void print_board();
void draw_board_graphical(sf::RenderWindow *window, unsigned int cell_size);
bool no_more_fields() const
{
return (size*size <= taken_fields);
}
unsigned int get_size() const
{
return size;
}
};
#endif