INTRODUCING C PROGRAMME ON TIC TAC TOI GAME :-
DOWNLOAD LINK :-https://drive.google.com/open?id=0B7snCzdq8oJDR0lGdk5tRi1YbEE
PROGRAMME :-
//My First Game :- Tic Tac Toi
#include<stdio.h>
int check (int m,int n)
{
int err;
if (m<0||m>2||n<0||n>2)
{
err=1;
}
else
{
err=0;
}
return (err);
}
void main()
{
int i,m,n,j,k,l,err1,err2;
char ans;
do
{
int flag=0;
int a[3][3]={8,8,8,8,8,8,8,8,8};
printf ("POSITIONS :- X & Y cordinates are \n 11 | 12 | 13\n-------------------------\n 21 | 22 | 23\n-------------------------\n 31 | 32 | 33\n");
for (i=0;i<9;i++)
{
if (flag==0)
{
while (1)
{
printf ("enter the CHOISE of 1st user :-\n");
scanf ("%d%d",&m,&n);
m=m-1;n=n-1;
if (m<0||m>2||n<0||n>2)
{
printf ("*******ENTER THE VALID NO.*******\n ");
}
else {break;}
}
while (1)
{
if (a[m][n]!=0&&a[m][n]!=1)
{
a[m][n]=0;
flag=1;
break;
}
while(1)
{
printf ("*******ENTER THE the VALID NO .*******\n");
printf ("enter the CHOISE of 1st user :-\n");
scanf ("%d%d",&m,&n);
m=m-1;n=n-1;
err1=check(m,n);
if(err1==0)
{
break;
}
}
}
}
else if (flag==1)
{
while (1)
{
printf ("enter the CHOISE of 2nd user :-\n");
scanf ("%d%d",&m,&n);
m=m-1;n=n-1;
if (m<0||m>2||n<0||n>2)
{
printf ("*******ENTER THE VALID NO. *******\n");
}
else {break;}
}
while (1)
{
if (a[m][n]!=0&&a[m][n]!=1)
{
a[m][n]=1;
flag=0;
break;
}
while(1)
{
printf ("*******ENTER THE the VALID NO .*******\n");
printf ("enter the CHOISE of 2nd user :-\n");
scanf ("%d%d",&m,&n);
m=m-1;n=n-1;
err2=check(m,n);
if (err2==0)
{
break;
}
}
}
}
for (k=0;k<3;k++)
{
for (l=0;l<3;l++)
{
if (a[k][l]==0||a[k][l]==1)
{
if (a[k][l]==0)
{
printf (" 0");
}
else
{
printf (" X");
}
if(l<2)
{
printf ("\t|");
}
}
else
{
if(l<2)
{
printf (" \t|");
}
}
}
printf("\n");
if (k<2)
{
printf("-------------------------");
}
printf ("\n");
}
if (a[0][0]+a[0][1]+a[0][2]==0)
{
printf ("user 1 is winner");
break;
}
else if (a[0][0]+a[0][1]+a[0][2]==3)
{
printf ("user 2 is winner");
break;
}
else if (a[1][0]+a[1][1]+a[1][2]==0)
{
printf ("user 1 is winner");
break;
}
else if (a[1][0]+a[1][1]+a[1][2]==3)
{
printf ("user 2 is winner");
break;
}
else if (a[2][0]+a[2][1]+a[2][2]==0)
{
printf ("user 1 is winner");
break;
}
else if (a[2][0]+a[2][1]+a[2][2]==3)
{
printf ("user 2 is winner");
break;
}
else if (a[0][0]+a[1][0]+a[2][0]==0)
{
printf ("user 1 is winner");
break;
}
else if (a[0][0]+a[1][0]+a[2][0]==3)
{
printf ("user 2 is winner");
break;
}
else if (a[0][1]+a[1][1]+a[2][1]==3)
{
printf ("user 2 is winner");
break;
}
else if (a[0][1]+a[1][1]+a[2][1]==0)
{
printf ("user 1 is winner");
break;
}
else if (a[0][2]+a[1][2]+a[2][2]==3)
{
printf ("user 2 is winner");
break;
}
else if (a[0][2]+a[1][2]+a[2][2]==0)
{
printf ("user 1 is winner");
break;
}
else if (a[0][0]+a[1][1]+a[2][2]==3)
{
printf ("user 2 is winner");
break;
}
else if (a[0][0]+a[1][1]+a[2][2]==0)
{
printf ("user 1 is winner");
break;
}
else if (a[2][0]+a[0][2]+a[1][1]==3)
{
printf ("user 2 is winner");
break;
}
else if (a[2][0]+a[0][2]+a[1][1]==0)
{
printf ("user 1 is winner");
break;
}FO
else if (i==8)
{
printf ("OPPS! NO ONE WIN");
break;
}
}
printf ("\n\n WOULD YOU WANT TO PLAY MORE ?\n\n 'Y' FOR YES 'N' FOR NO :-\t");
scanf("%s",&ans);
}
while (ans=='y'||ans=='Y');
printf ("******THANKS FOR PLAYING*******");
}
ANOTHER PROGRAMMES ARE COMING SOON:-
FOLLOW ME ON :-
INSTAGRAM :- https://www.instagram.com/akshay_methaniya_2809/
FACEBOOK :- https://www.facebook.com/akshay.methaniya
Nice work. keep it up bro
ReplyDeleteThanks Bhai
ReplyDelete