FinalnoX
This commit is contained in:
parent
bcf06bda5f
commit
bd8f0464d0
BIN
IksOks/iksoks
BIN
IksOks/iksoks
Binary file not shown.
@ -12,29 +12,27 @@ cout << board[2][0] << " |" << board[2][1] << "| " << board[2][2] << endl;
|
||||
}
|
||||
|
||||
|
||||
void checkWin(char board[3][3], char player) {
|
||||
|
||||
for(int i = 0; i < 2; i++){
|
||||
if(board[i][0] == player && board[i][1] == player && board[i][2] == player){
|
||||
cout << board[i][0] << " WON!" << endl;}
|
||||
|
||||
if(board[0][i] == player && board[1][i] == player && board[2][i] == player){
|
||||
cout << board[i][0] << " WON!" << endl;}
|
||||
|
||||
};
|
||||
bool checkWin(char board[3][3], char player) {
|
||||
|
||||
if(board[0][0] == player && board[1][1] == player && board[2][2] == player){
|
||||
cout << board[0][0] << " WON!" << endl;}
|
||||
return true;}
|
||||
if(board[2][0] == player && board[1][1] == player && board[0][2] == player){
|
||||
cout << board[2][0] << " WON!" << endl;}
|
||||
return true;}
|
||||
|
||||
for(int i = 0; i < 3; i++){
|
||||
if(board[i][0] == player && board[i][1] == player && board[i][2] == player){
|
||||
return true;}
|
||||
|
||||
if(board[0][i] == player && board[1][i] == player && board[2][i] == player){
|
||||
return true;}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
int i;
|
||||
int row;
|
||||
int col;
|
||||
char player = 'X';
|
||||
@ -46,7 +44,7 @@ char board[3][3] = { { ' ', ' ', ' ' },
|
||||
|
||||
cout << "Welcome to Tic-Tac-Toe!\n";
|
||||
|
||||
for(i=0; i<9; i++){
|
||||
for(int i=0; i<9; i++){
|
||||
|
||||
drawBoard(board);
|
||||
|
||||
@ -69,6 +67,9 @@ for(i=0; i<9; i++){
|
||||
if(board[col-1][row-1] == ' '){
|
||||
board[col-1][row-1] = player;
|
||||
checkWin(board, player);
|
||||
if(checkWin(board, player)){
|
||||
break;
|
||||
}
|
||||
player = (player == 'X') ? 'O' : 'X';
|
||||
}
|
||||
|
||||
@ -79,10 +80,13 @@ for(i=0; i<9; i++){
|
||||
}
|
||||
}
|
||||
|
||||
if(i = 9){
|
||||
if(checkWin(board, player))
|
||||
cout << player << " WON!" << endl;
|
||||
else
|
||||
cout << "It's Draw\n";
|
||||
|
||||
drawBoard(board);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user