Jump to content
Half Monk

[How To] Make TIC TAC TOE GAME NEW CONCEPT (C++ PROGRAM)

Recommended Posts

Here is the source code for c++.

 

#?include?<iostream.h> //opening headerfile iostream for in-out
#include<conio.h> //opening headerfile conio for clrscr();
#include<stdlib.h> //opening headerfile stdlib for
char tic[3][3]; //global matrix declerations
int d,e,f,a,t,i,j,x,y; //global variables declerations
void display(); //displays the matrix
void user(); //function for user's move
void newdisp(); //function for display of matrix after every move
void pc(); //function for pc's move
int check(); //function for finding out the winner
int horcheck(); //function for horizontal line check
int vercheck(); //function for vertical line check
int diagcheck(); //function for diagonal line check
main() //main function
{
clrscr(); //clears the previous output screen
randomize(); //initialize random function calling
int d=random(2); //random function call
for(i=0;i?;i++)
for(j=0;j?;j++)
tic[j]=' '; //assigning space ' ' to all elements of matrix
display(); //display function call
if(d==0)
{
user();
}
else
{ pc();
} //random starting of the game dependingo
getch(); //provides output by getting input withoutreturning to program
return 0; //return int to main function
}
void display() //display function definition
{
for(t=0;t?;t++)
{
cout<<" "<<tic[t][0]<<" | "<<tic[t][1]<<" | "<<tic[t][2]<<endl; //figure formation
if(t!=2)
cout<<" --|---|--"<<endl;
}
}
void user() //user function definition
{
cout<<endl<<endl<<endl;
cout<<"ENTER THE CO-ORDINATES WHERE YOU WANT TO PUT UR 'X'";
cout<<endl<<"Enter x(co-ordinate)";
cin>>x;
cout<<endl<<"Enter y(co-ordinate)";
cin>>y;
cout<<"Values are"<<x<<y;
cout<<endl;
if((x<0)||(x>2)&&(y<0)||(y>2)) //check for valid co-ordinates
{
cout<<" ENTER THE CORRECT CO-ORDINATES"<<endl;
user(); //user function call
}
else
{
if(tic[x][y]==' ') //check for vacant space at entered co-ordinates
{
tic[x][y]='X'; //assigning user 'X' to the co-ordinates
newdisp(); //newdisp function call
}
else
{

 

 

  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×