-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
72 lines (47 loc) · 1.25 KB
/
main.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
#include <iostream>
#include <cstdlib>
#include "TicTacToe.h"
using namespace std;
int main()
{
//variable declaration
short board[3][3] = {0};
short _count = 0;
//current player
Player player = PlayerO;
//display board for first time
display(board);
//start a infinite loop here
while(true)
{
//get user input
getInput(player,board);
//increase _count here
_count++;
//clear previous screen
system("cls");
//display new board
display(board);
//if _count is 5 or more means there is a possibility of player's win
if(_count >= 5)
{
//get winner
Player p = getWinner(board);
//check winner if it is not none
if(p != 0)
{
std::cout<<"\nPlayer "<<toChar(p)<<" won."<<std::endl;
break;
}
}
//if _count == 9 means either win(in previous statement) or draw
if(_count == 9)
{
std::cout<<"Match is draw."<<std::endl;
break;
}
}
//pause the screen
system("pause");
return 0;
}