-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cpp
55 lines (45 loc) · 1.26 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
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include "ComputerPlayer.h"
#include "Game.h"
#include "Config.h"
#include "Counter.h"
#include "Player.h"
#include "Direction.h"
#include "BoardEvaluator.h"
Game::Game(Displayer *displayer, Player *humanPlayer) :
m_displayer(displayer),
m_board(displayer),
m_currentPlayer(0),
m_humanPlayer(humanPlayer),
m_computerPlayer(new ComputerPlayer(m_displayer, &m_boardEvaluator)) {
m_humanPlayer->SetColour(YELLOW);
m_computerPlayer->SetColour(RED);
}
Game::~Game() {
delete m_computerPlayer;
}
void Game::NextMove() {
Player *player = getCurrentPlayer();
player->Move(m_board);
if (player->IsMoveValid())
updateCurrentPlayer();
}
bool Game::IsFinished(unsigned int *winningColour) {
if (m_board.IsFull()) {
*winningColour = NULL_COLOUR;
return true;
}
return m_boardEvaluator.IsFinished(m_board, (Colour *)winningColour);
}
void Game::DisplayBoard() {
m_board.DisplayBoard();
}
Board &Game::getBoard() {
return m_board;
}
Player *Game::getCurrentPlayer() {
return m_currentPlayer == 0 ? m_humanPlayer : m_computerPlayer;
}
void Game::updateCurrentPlayer() {
m_currentPlayer = (m_currentPlayer == 0) ? 1 : 0;
}