//designed by codenation
//22:41 thu 22/10/2020
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define true 1
#define false 0
int main()
{
printf("this code is designed by codenation");
int p,toss,c,r,i=0,j,game_over=false,beg,count=1;
time_t t;
char name1[20],name2[20],ch1,a[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
a[i][j]='_';
}
}
srand((unsigned) time(&t));
toss=rand()%2;
printf("\n??welcome to tic-tac-toe??\n");
printf("enter first player name :\n");
scanf("%s",name1);
printf("enter the second player name :\n");
scanf("%s",name2);
printf("are you ready to play %s & %s?\n",name1,name2);
printf("y-yes/n-no\n");
scanf(" %c",&ch1);
if(ch1=='y')
{
printf("who will start first or toss?\n");
printf("1-name /0-toss\n");
scanf("%d",&r);
if(r==1)
{
printf("enter beginer player number(1/2) :\n");
scanf(" %d",&beg);
}
else
{
printf("anyone choose 0 or 1\n");
printf("enter choice :\n");
scanf("%d",&c);
if(c==0 || c==1)
{
printf("tossing....\n");
printf("....\n");
printf("....\n");
printf("toss is %d\n",toss);
printf("enter beginer player number(1/2):\n");
scanf("%d",&beg);
}
else
{
printf("wrong input\n");
}
}
printf("lets play\n");
printf("beginner will start with x\n");
printf("positions\n");
for(i=1;i<10;i++)
{
for(j=0;j<3;j++)
{
printf("[%d]\t",i);
i++;
}
i--;
printf("\n");
}
while(game_over!=true)
{
if(count%2!=0 && count<10)
{
count++;
printf("**first player turn**\n");
printf("enter the position of x as per positions\n");
scanf("%d",&p);
switch(p)
{
case 1:
a[0][0]='x';
break;
case 2:
a[0][1]='x';
break;
case 3:
a[0][2]='x';
break;
case 4:
a[1][0]='x';
break;
case 5:
a[1][1]='x';
break;
case 6:
a[1][2]='x';
break;
case 7:
a[2][0]='x';
break;
case 8:
a[2][1]='x';
break;
case 9:
a[2][2]='x';
break;
}
}
else
if(count%2==0 && count<10)
{
count++;
printf("**second player turn**\n");
printf("enter the position of O as per positions\n");
scanf("%d",&p);
switch(p)
{
case 1:
a[0][0]='O';
break;
case 2:
a[0][1]='O';
break;
case 3:
a[0][2]='O';
break;
case 4:
a[1][0]='O';
break;
case 5:
a[1][1]='O';
break;
case 6:
a[1][2]='O';
break;
case 7:
a[2][0]='O';
break;
case 8:
a[2][1]='O';
break;
case 9:
a[2][2]='O';
break;
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%c\t",a[i][j]);
}
printf("\n");
}
if((a[0][0]=='x'&&a[0][1]=='x'&&a[0][2]=='x') || (a[1][0]=='x'&&a[1][1]=='x'&&a[1][2]=='x') || (a[2][0]=='x'&&a[2][1]=='x'&&a[2][2]=='x'))
{
if(beg==1)
printf("¶¶%s won the game¶¶\n",name1);
else
printf("¶¶%s won the game¶¶\n",name2);
game_over=true;
}
if((a[0][0]=='O'&&a[0][1]=='O'&&a[0][2]=='O') || (a[1][0]=='O'&&a[1][1]=='O'&&a[1][2]=='O') || (a[2][0]=='O'&&a[2][1]=='O'&&a[2][2]=='O'))
{
if(beg==1)
printf("¶¶%s won the game¶¶\n",name1);
else
printf("¶¶%s won the game¶¶\n",name2);
game_over=true;
}
if((a[0][0]=='O'&&a[1][0]=='O'&&a[2][0]=='O') || (a[0][1]=='O'&&a[1][1]=='O'&&a[2][1]=='O') || (a[0][2]=='O'&&a[1][2]=='O'&&a[2][2]=='O'))
{
if(beg==1)
printf("¶¶%s won the game¶¶\n",name1);
else
printf("¶¶%s won the game¶¶\n",name2);
game_over=true;
}
if((a[0][0]=='x'&&a[1][0]=='x'&&a[2][0]=='x') || (a[0][1]=='x'&&a[1][1]=='x'&&a[2][1]=='x') || (a[0][2]=='x'&&a[1][2]=='x'&&a[2][2]=='x'))
{
if(beg==1)
printf("¶¶%s won the game¶¶\n",name1);
else
printf("¶¶%s won the game¶¶\n",name2);
game_over=true;
}
if((a[0][0]=='x'&&a[1][1]=='x'&&a[2][2]=='x') || (a[0][2]=='x'&&a[1][1]=='x'&&a[2][0]=='x'))
{
if(beg==1)
printf("¶¶%s won the game¶¶\n",name1);
else
printf("¶¶%s won the game¶¶\n",name2);
game_over=true;
}
if((a[0][0]=='O'&&a[1][1]=='O'&&a[2][2]=='O') || (a[0][2]=='O'&&a[1][1]=='O'&&a[2][0]=='O'))
{
if(beg==1)
printf("¶¶%s won the game¶¶\n",name1);
else
printf("¶¶%s won the game¶¶\n",name2);
game_over=true;
}
if(count==9)
{
printf("¶¶the game is draw¶¶\n");
game_over= true;
}
}
}
printf("¶¶thanks for playing¶¶\n");
printf("this code is designed by codenation");
return 0;
}
Comments
Post a Comment