-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cpp
46 lines (37 loc) · 1.09 KB
/
Game.cpp
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
#include "classes/Game.h"
#include <SFML/Graphics.hpp>
Game::Game(const int field_size, const int req_length, bool is_ai) : size(field_size), length(req_length) {
finished = false;
board = new Board(field_size);
winner = nullptr;
players[0] = new Player('o', false);
players[1] = new Player('x', is_ai);
}
Game::~Game() {
delete winner;
delete board;
}
Board* Game::get_board() {
return board;
}
Player* Game::get_winner() {
return winner;
}
void Game::set_field_owner(int x, int y, char sign) {
Player* new_owner;
if (players[0]->get_symbol() == sign) new_owner = players[0];
else if (players[1]->get_symbol() == sign) new_owner = players[1];
else return;
board->get_field(x, y)->set_owner(new_owner);
}
void Game::remove_field_owner(int x, int y) {
board->get_field(x, y)->set_owner(nullptr);
}
Player* Game::get_player_by_sign(char sign) {
if (players[0]->get_symbol() == sign) return players[0];
else if (players[1]->get_symbol() == sign) return players[1];
else return nullptr;
}
bool Game::is_finished() {
return finished;
}