-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRun.cpp
97 lines (79 loc) · 1.94 KB
/
Run.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "Machine.h"
#include "Game.h"
#include <iostream>
#include <stdlib.h>
#define LENGTH 30
#define CONTINUE_SIZE 40
using namespace std;
char playerSymbol='X';
char machineSymbol='O';
void printMenu(Game g){
char choosenSymbol=' ';
for(int i=0;i<LENGTH;i++){
cout<<"-";
}
cout<<endl;
//Choose the symbol
while(choosenSymbol!='X' && choosenSymbol!='O'){
cout<<"Choose your symbol (X or O): ";
cin >>choosenSymbol;
if(choosenSymbol=='X'){
g.playerSymbol='X';
playerSymbol='X';
g.machineSymbol='O';
machineSymbol='O';
}
else if(choosenSymbol=='O'){
g.playerSymbol='O';
playerSymbol='O';
g.machineSymbol='X';
machineSymbol='X';
}
}
}
int main(){
//Array we save some content if we want to continue
char *wannaContinue=new char[CONTINUE_SIZE];
int row=15,col=15;
//We create the game
Game fun(machineSymbol,playerSymbol);
while(true){
//Print the menu
printMenu(fun);
cout<<"PLAYER: "<<playerSymbol<<" MACHINE: "<<machineSymbol<<endl;
//Create the machine part
Machine mach(machineSymbol,playerSymbol);
//Play until some one loses
while(true){
if(fun.someOneWins()==1){
fun.printArr();
cout<<"Player Wins!"<<endl;
break;
}
else if(fun.someOneWins()==2){
fun.printArr();
cout<<"Machine Wins!"<<endl;
fun.resetArray();
break ;
}
else if(fun.someOneWins()==3){
fun.printArr();
cout<<"No one wins!"<<endl;
fun.resetArray();
return 0;
}
do{
cout<<"Choose row and col: ";
cin>>row;
cin>>col;
}while(row>SIZE-1 || col>SIZE-1 || row <0 || col <0 || fun.isFilled(row,col));
//Set element
fun.setElement(row,col);
fun.printArr();
mach.machineThink(fun.ticArray,playerSymbol,machineSymbol);
fun.printArr();
}
}
//Free Memory
fun.freeMemory();
}