blob: 49765b3c3227fd6587416357fecbba6d21d238b7 (
plain)
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 <iostream>
#include "Player.h"
#include "Gameboard.h"
using namespace std;
int main()
{
// Initialize game
cout << "Welcome to TicTacToe!" << endl << endl;
// Initialize gameboard
Gameboard gameboard;
// Initialize players
Player player1(1);
Player player2(2);
// Do gameloop
int endGame = 0;
while(!endGame) {
gameboard.printGameboard();
cout << player1.getName() << "'s turn:" << endl;
gameboard.playMove(player1.getSymbol(),player1.getMoveY(),player1.getMoveX());
endGame = gameboard.checkWin(player1.getPlayerID(),player1.getSymbol());
if(endGame){break;}
gameboard.printGameboard();
cout << player2.getName() << "'s turn:" << endl;
gameboard.playMove(player2.getSymbol(),player2.getMoveY(),player2.getMoveX());
endGame = gameboard.checkWin(player2.getPlayerID(),player2.getSymbol());
}
// Print final gameboard
gameboard.printGameboard();
// Print winning player
if(endGame == player1.getPlayerID()) {
cout << player1.getName() << " Wins!" << endl;
}
if(endGame == player2.getPlayerID()) {
cout << player2.getName() << " Wins!" << endl;
}
return 0;
}
|