forked from RivkaSchuss/ReversiGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cpp
54 lines (47 loc) · 1.2 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
//
// Created by yarin on 06/11/17.
//
#include <iostream>
#include "Game.h"
using namespace std;
/**
* The constructor.
* @param blackPlayer the 'X' player.
* @param whitePlayer the 'O' player.
* @param board the board of the game.
* @param logic the game logic of the game.
*/
Game::Game(Player* blackPlayer, Player* whitePlayer, Board* board, GameLogic* logic) :
blackPlayer(blackPlayer), whitePlayer(whitePlayer), board(board), logic(logic) {
}
/**
* The destructor.
*/
Game::~Game() {
delete blackPlayer;
delete whitePlayer;
delete board;
delete logic;
delete this;
}
/**
* This method runs the game loop.
*/
void Game::run() {
while (logic->isRunning() != 0) {
board->print();
logic->playOneTurn(board);
if (logic->getTurn() == black) {
logic->setTurn(white);
} else {
logic->setTurn(black);
}
}
if (logic->checkScore(board->getTable(), board->getSize()) == 1) {
cout << "X: Congrats, you win!" << endl;
} else if (logic->checkScore(board->getTable(), board->getSize()) == 2) {
cout << "O: Congrats, you win!" << endl;
} else {
cout << "It's a TIE!" << endl;
}
}