-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameManager.cpp
More file actions
41 lines (34 loc) · 1010 Bytes
/
Copy pathGameManager.cpp
File metadata and controls
41 lines (34 loc) · 1010 Bytes
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
// Class definition for XO_GameManager class
// Author: Mohammad El-Ramly
// Date: 10/10/2022
// Version: 1
#include <iostream>
#include "BoardGame_Classes.hpp"
//#include"../include/BoardGame_Classes.hpp"
using namespace std;
GameManager::GameManager(Board* bPtr, Player* playerPtr[2] ) {
boardPtr = bPtr;
players[0] = playerPtr[0];
players[1] = playerPtr[1];
}
void GameManager::run() {
int x, y;
boardPtr->display_board();
while (!boardPtr->game_is_over()) {
for (int i:{0,1}) {
players[i]->get_move(x, y);
while (!boardPtr->update_board (x, y, players[i]->get_symbol())){
players[i]->get_move(x, y);
}
boardPtr->display_board();
if (boardPtr->is_winner()){
cout << players[i]->to_string() << " wins\n";
return;
}
if (boardPtr->is_draw()){
cout << "Draw!\n";
return;
}
}
}
}