0% found this document useful (0 votes)
2 views3 pages

Tic 085823

This document contains a C++ implementation of a Tic-Tac-Toe game. It includes functions for viewing the game board, resetting the board, and managing player turns until a win or draw occurs. The game allows players to input their moves and displays the results accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Tic 085823

This document contains a C++ implementation of a Tic-Tac-Toe game. It includes functions for viewing the game board, resetting the board, and managing player turns until a win or draw occurs. The game allows players to input their moves and displays the results accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

TIC-TAC-TOE PROJECT

#include <iostream>

using namespace std;

void viewboard();

void newGame();

char mv[10]={'0','1','2','3','4','5','6','7','8','9'};

void resetboard()

mv[1]='1',mv[2]='2',mv[3]='3',mv[4]='4',mv[5]='5',mv[6]='6',mv[7]='7',mv[8]='8',mv[9]='9';

void viewboard()

cout<<"\n+-----------+\n| "<<mv[1]<<" | "<<mv[2]<<" | "<<mv[3]<<" |\n+-----------+ \n| "<<mv[4]<<"


| "<<mv[5]<<" | "<<mv[6]<<" |\n+-----------+ \n| "<<mv[7]<<" | "<<mv[8]<<" | "<<mv[9]<<" |\n+------
-----+ \n";

void newGame()

int move,turn=0,win=0;

cout<<"\n A new game has started!";

viewboard();

char desicion;

do

resetboard();
do

char xo;

if(turn%2==0)

xo='X';

}else{

xo='O';

m: cout<<"\n PLayer "<<xo<<"! Enter a Valid move: ";

cin>>move;

if(move>9 || move<1)

goto m;

}else{

if(mv[move]=='X' || mv[move]=='O')

cout<<"Place is occupied!";

}else if(mv[move]!='X' || mv[move]!='O'){

turn++;

mv[move]=xo;

viewboard();

}else{

cout<<"error...";

if(mv[1]==xo && mv[2]==xo && mv[3]==xo)

cout<<"PLayer "<<xo<<" WINS!";


turn=9;

}else if(mv[1]==xo && mv[4]==xo && mv[7]==xo){

cout<<"PLayer "<<xo<<" WINS!";

turn=9;

}else if(mv[1]==xo && mv[5]==xo && mv[9]==xo){

cout<<"PLayer "<<xo<<" WINS!";

turn=9;

}else if(mv[3]==xo && mv[6]==xo && mv[9]==xo){

cout<<"PLayer "<<xo<<" WINS!";

turn=9;

}else if(mv[3]==xo && mv[5]==xo && mv[7]==xo){

cout<<"PLayer "<<xo<<" WINS!";

turn=9;

}else if(mv[7]==xo && mv[8]==xo && mv[9]==xo){

cout<<"PLayer "<<xo<<" WINS!";

turn=9;

}else if(turn==9){

cout<<"It's a DRAW!";

}while(turn!=9);

cout<<"\n\n>> Do you want to play again? (y/n)\n";

cin>>desicion;

}while(desicion=='y');

int main()

newGame();

return 0;

You might also like