#include<stdio.h>
void intro();
int check(char a[][3],char v);
void select(char a[][3], int s,char i);
int main()
{
char a[3][3],v,ch;
int s,w,i,j,d,g,h,z,n;
intro();
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
a[i][j]=' ';
}
for(i=1;i<=9;i++)
{
if(i%2!=0)
{ v='x'; n=1;}
else
{ v='o'; n=2;}
printf("\n-------------------------------------------------------------------------");
printf("\nPLAYER [%d] TURN : ",n);scanf("%d",&s);
select(a,s,v);
prt(a,3);
z=check(a,v);
if(z==30) break;
}
if(z!=30)
printf("GAME DRAW");
system("PAUSE");
return 0;
}
void intro()
{
printf("\t\t\t@@@@@@@@@@@@@@@@@@@@@@");
printf("\n\t\t\t@@@ TIC- TAC - TOE @@@ ");
printf("\n\t\t\t@@@@@@@@@@@@@@@@@@@@@@");
printf("\n\n 1 | 2 | 3 \n");
printf("-------------------\t\tPLAYER 1 --> [X] \n");
printf(" 4 | 5 | 6 \n");
printf("-------------------\t\tPLAYER 2 --> [O] \n");
printf(" 7 | 8 | 9 \n");
printf("\n\nENTER THE BLOCK NUMBER:-");
}
void select(char a[][3], int s,char i)
{
switch(s)
{
case 1 :
a[0][0]=i;
break;
case 2:
a[0][1]=i;
break;
case 3 :
a[0][2]=i;
break;
case 4 :
a[1][0]=i;
break;
case 5:
a[1][1]=i;
break;
case 6 :
a[1][2]=i;
break;
case 7 :
a[2][0]=i;
break;
case 8:
a[2][1]=i;
break;
case 9 :
a[2][2]=i;
break;
}
}
void prt(char a[][3], int s)
{
int i,j;
for(i=1;i<=s;i++)
{
printf("\t\t\t");
for(j=1;j<=3;j++)
{
printf(" %c ",a[i-1][j-1]);
if(j/3!=1)
printf("|");
}
if(i/3!=1)
printf("\n\t\t\t ---------------\n");
}
}
int check(char a[][3],char v)
{
int g,s,n,m,w;
for(g=0;g<=2;g++)
{
if(v=='x') w=1;
if(v=='o') w=2;
if(a[g][0]==v && a[g][1]==v && a[g][2]==v)
{
printf("\n\t *********************************");
printf("\n\t\t CONGRATES PLAYER (%d) WIN ",w);
printf("\n\t *********************************\n");
return 30;
}
else if(a[0][g]==v && a[1][g]==v && a[2][g]==v)
{
printf("\n\t *********************************");
printf("\n\t\t CONGRATES PLAYER (%d) WIN ",w);
printf("\n\t *********************************\n");
return 30;
}
else if(a[0][0]==v && a[1][1]==v && a[2][2]==v || a[0][2]==v && a[1][1]==v && a[2][0]==v)
{
printf("\n\t *********************************");
printf("\n\t\t CONGRATES PLAYER (%d) WIN ",w);
printf("\n\t *********************************\n");
return 30;
}
}
}
use pointer while you post next program!
ReplyDeleteI WILL POST THE NOTES OF POINTER AND THAN SOME PROGRAM RELATED TO POINTER TOMORROW
ReplyDelete