-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtictactoe.h
More file actions
65 lines (55 loc) · 1.48 KB
/
tictactoe.h
File metadata and controls
65 lines (55 loc) · 1.48 KB
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
#include <iostream>
#include <vector>
using namespace std;
void tictactoe()
{
vector<vector<char>> board(3, vector<char>(3, ' '));
char currentPlayer = 'O';
string charmove;
int move, flag = 0;
while (true)
{
printBoard(board, "User");
cout << "Player " << currentPlayer << ",\nEnter your move (1-9): ";
getline(cin, charmove);
move = ValidateMove(board, charmove);
if (move == -1 && flag == 1)
{
cout << "Invalid Move. Please Enter Valid Move" << endl;
getch();
continue;
}
else if (flag == 1)
{
int row, col;
convertMove(move, row, col);
board[row][col] = currentPlayer;
}
if (checkWin(board, currentPlayer))
{
printBoard(board, "User");
cout << "Player " << currentPlayer << " wins!" << endl;
break;
}
if (isBoardFull(board))
{
printBoard(board, "User");
cout << "It's a tie!" << endl;
cout << "Press any Key to Continue...";
getch();
system("cls");
break;
}
if (flag == 1)
{
currentPlayer = (currentPlayer == 'X') ? 'O' : 'X';
}
flag = 1;
}
}
// int main()
// {
// cout << "Welcome to Tic Tac Toe!" << endl;
// tictactoe();
// return 0;
// }