-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.cpp
61 lines (47 loc) · 1.23 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
56
57
58
59
60
61
#include <cmath>
#include "tictactoe.h"
using namespace std;
int main()
{
Board *board;
int choice;
while (1)
{
system("clear");
cout << "---Choose a board---\n1] 3 by 3\n2] 4 by 4\n3] 5 by 5\n\n9] Exit\n\n->";
cin >> choice;
if (choice == 1)
board = new Board_3x3();
else if (choice == 2)
board = new Board_4x4();
else if (choice == 3)
board = new Board_5x5();
else if (choice == 9)
return 0;
else
continue;
break;
}
while ((*board).isRunning())
{
system("clear");
cout << (*board);
cin >> (*board);
if (!(*board).isRunning())
break;
while (1)
{
int markPos = rand() % ((choice == 1 ? 9 : (choice == 2 ? 16 : 25)) + 1);
if ((*board).getMark(markPos) == -1)
(*board).setMark(markPos);
else
continue;
break;
}
}
system("clear");
cout << (*board);
cout << ((*board).getWinner() == Human ? "\nYou won!\n" : ((*board).getWinner() == Computer ? "\nComputer wins!\n" : "\nNo one won!\n"));
delete board;
return 0;
}