/*
Making a game of zero-cross (Tic-Tac)
Created by chirag goti
*/
#include<stdio.h>
#include<conio.h>
// define a constaints
#define size 6
#define zero 1
#define chokdi 2
/* declaring a global variabes, char array or string and user-define fuctions */
//variables
int i,j,k;
int rows,cols,flag;
int f,s;
char o[size][size]={' '}, x[size][size]={' '};
//char array & string
char player1[12],player2[12];
int ox[3][3]={0}; //numerical array
// uers define Fuctions
void print_location(int,int);
/*
Using for fixing the loction of 'x' or 'o' design.
*/
void display(int,int,int);
/*
Usig for print the design of 'x' or 'o'
*/
void setnull(int *);
/*
set the null values in 3X3 array.
*/
char check();
/*
check the who is winner???
*/
void main()
{
int l,p,q;
char cho,y;
go2:
l=1;
/*
following statements to genrated the login screen.
*/
clrscr();
printf("\n\t\tEnter your name: ");
printf("\n\tPlayer 1 : ");
scanf("%s",player1);
printf("\n\tPlayer 2 : ");
scanf("%s",player2);
printf("[OK]...\n");
getch();
/*
following statements and loops to design 'x' and 'o' in the x[size][size] and o[size][size].
*/
for (i=1,j=size;i<size;i++)
{
x[i][i]='#';
x[j-i][i]='#';
}
for (i=1,j=1,k=size-1;i<size;i++)
{
o[i][j]='#';
o[j][i]='#';
o[i][k]='#';
o[k][i]='#';
}
setnull(ox[0]);
do
{
flag=chokdi;
if(l%2!=0)
flag=zero;
go:
clrscr();
/*
following loops and statements to genrate platefrom of ox.
*/
for (i=5;i<=26;i+=7)
{
for(j=16;j<=58;j++)
{
gotoxy (j,i);
printf("_");
}
}
for(i=6;i<=26;i++)
{
for (j=16;j<=64;j+=14)
{
gotoxy (j,i);
printf("_");
}
}
for(i=1;i<=75;i++)
{
gotoxy (i,30);
printf("-");
}
for(i=1;i<=75;i++)
{
gotoxy (i,40);
printf("-");
}
/*
following statements ,checking the conditons and loops to
input from players
*/
display(3,33,flag);// display zero-chokdi at bottom-right on the screen.
gotoxy(2,32);
printf(" Player %d",flag);
gotoxy(10,35);
printf("Name: ");
if(flag==zero)
{
printf("%s",player1);
}
else
{
printf("%s",player2);
}
/*
display the ox 3X3 array.
*/
for (p=1;p<=3;p++)
{
for (q=1;q<=3;q++)
{
if(ox[p][q]==zero || ox[p][q]==chokdi)
{
print_location(p,q);
display(f,s,ox[p][q]);
}
}
}
gotoxy(10,38);
printf("Row: ");
scanf("%d",&rows); //inputing rows
gotoxy(20,38);
printf("Column: ");
scanf("%d",&cols); //inputing cols
gotoxy(25,42);
printf("Ok..[enter any key OR No]: ");
cho=getch();
if(cho=='N' || cho=='n')
goto go;
/*
your entered row or column are perfect or not then try agin.
*/
if((rows<1 || rows>3) || (cols<1 || cols&>3))
{
gotoxy(25,42);
printf("Try agean [OK]...\t\t");
getch();
goto go;
}
/*
duplicate entry not permitted to checking this conditions
*/
if(ox[rows][cols]==zero || ox[rows][cols]==chokdi )
{
gotoxy(25,42);
printf(" Your location all ready exist [OK]...");
getch();
goto go;
}
/*
Insert the zero('o') and chokdi('x') in the ox[3][3].
*/
if(flag==chokdi)
{
ox[rows][cols]=chokdi;
}
else
{
ox[rows][cols]=zero;
}
cho=check();
if(cho=='y')
{
// display the winner is player1 or player2.
for(i=6;i<=27;i++)
{
for (j=12;j<=73;j+=53)
{
gotoxy (j,i);
printf("-");
}
}
for (j=12;j<=65;j++)
{
for(i=6;i<=27;i+=21)
{
gotoxy (j,i);
printf("-");
}
}
gotoxy(15,35);
if(flag==zero)
printf("Congratulation %s, YOU ARE WINNER!!!!!!!!",player1);
else
printf("Congratulation %s, YOU ARE WINNER!!!!!!!!",player2);
getch();
break;
}
l++;
}while (l<=9);
//ending of loop
clrscr();
//asking from uesrs, play again?
gotoxy(30,35);
printf("PLAY AGAIN[YES/NO]:");
cho=getch();
if(cho=='y')
goto go2;
//ending of program
}
void setnull(int *t)
{
for (i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
*t=NULL;
t++;
}
}
};
// display x or o at screen
void display(int a,int b,int cho)
{
char *tamp;
if(cho==zero)
tamp=&o[0][0];
else if(cho==chokdi)
tamp=&x[0][0];
for (i=0;i<size;i++)
{
gotoxy(a,b);
for (j=0;j<size;j++)
{
printf("%c",*tamp);
tamp++;
}
b++;
}
};
void print_location(int a,int b)
{
int x;
for (i=1,x=6;i<=3;i++,x+=7)
{
if(a==i)
s=x;
}
for (i=1,x=21;i<=3;i++,x+=13)
{
if(b==i)
f=x;
}
};
char check()
{
char ask='n';
int one,two;
clrscr();
for (one=1;one<=3;one++)
{
if(ox[one][1]==zero && ox[one][2]==zero && ox[one][3]==zero)
{
for (two=1;two<=3;two++)
{
print_location(one,two);
display(f,s,zero);
}
ask='y';
}
else if(ox[one][1]==chokdi && ox[one][2]==chokdi && ox[one][3]==chokdi)
{
for (two=1;two<=3;two++)
{
print_location(one,two);
display(f,s,chokdi);
}
ask='y';
}
else if(ox[1][one]==zero && ox[2][one]==zero && ox[3][one]==zero)
{
for (two=1;two<=3;two++)
{
print_location(two,one);
display(f,s,zero);
}
ask='y';
}
else if(ox[1][one]==chokdi && ox[2][one]==chokdi && ox[3][one]==chokdi)
{
for (two=1;two<=3;two++)
{
print_location(two,one);
display(f,s,chokdi);
}
ask='y'; //player2 win
}
}
if(ox[1][1]==zero && ox[2][2]==zero && ox[3][3]==zero)
{
for (one=1;one<=3;one++)
{
print_location(one,one);
display(f,s,zero);
}
ask='y'; //player1 win
}
else if(ox[1][1]==chokdi && ox[2][2]==chokdi && ox[3][3]==chokdi)
{
for (one=1;one<=3;one++)
{
print_location(one,one);
display(f,s,chokdi);
}
ask='y'; //player2 win
}
else if(ox[3][1]==zero && ox[2][2]==zero && ox[1][3]==zero)
{
for (one=3,two=1;one>=0 && two<=3;one--,two++)
{
print_location(one,two);
display(f,s,zero);
}
ask='y'; //player1 win
}
else if(ox[3][1]==chokdi && ox[2][2]==chokdi && ox[1][3]==chokdi)
{
for (one=3,two=1;one>=0 && two<=3;one--,two++)
{
print_location(one,two);
display(f,s,chokdi);
}
ask='y'; //player2 win
}
return ask;
};
Making a game of zero-cross (Tic-Tac)
Created by chirag goti
*/
#include<stdio.h>
#include<conio.h>
// define a constaints
#define size 6
#define zero 1
#define chokdi 2
/* declaring a global variabes, char array or string and user-define fuctions */
//variables
int i,j,k;
int rows,cols,flag;
int f,s;
char o[size][size]={' '}, x[size][size]={' '};
//char array & string
char player1[12],player2[12];
int ox[3][3]={0}; //numerical array
// uers define Fuctions
void print_location(int,int);
/*
Using for fixing the loction of 'x' or 'o' design.
*/
void display(int,int,int);
/*
Usig for print the design of 'x' or 'o'
*/
void setnull(int *);
/*
set the null values in 3X3 array.
*/
char check();
/*
check the who is winner???
*/
void main()
{
int l,p,q;
char cho,y;
go2:
l=1;
/*
following statements to genrated the login screen.
*/
clrscr();
printf("\n\t\tEnter your name: ");
printf("\n\tPlayer 1 : ");
scanf("%s",player1);
printf("\n\tPlayer 2 : ");
scanf("%s",player2);
printf("[OK]...\n");
getch();
/*
following statements and loops to design 'x' and 'o' in the x[size][size] and o[size][size].
*/
for (i=1,j=size;i<size;i++)
{
x[i][i]='#';
x[j-i][i]='#';
}
for (i=1,j=1,k=size-1;i<size;i++)
{
o[i][j]='#';
o[j][i]='#';
o[i][k]='#';
o[k][i]='#';
}
setnull(ox[0]);
do
{
flag=chokdi;
if(l%2!=0)
flag=zero;
go:
clrscr();
/*
following loops and statements to genrate platefrom of ox.
*/
for (i=5;i<=26;i+=7)
{
for(j=16;j<=58;j++)
{
gotoxy (j,i);
printf("_");
}
}
for(i=6;i<=26;i++)
{
for (j=16;j<=64;j+=14)
{
gotoxy (j,i);
printf("_");
}
}
for(i=1;i<=75;i++)
{
gotoxy (i,30);
printf("-");
}
for(i=1;i<=75;i++)
{
gotoxy (i,40);
printf("-");
}
/*
following statements ,checking the conditons and loops to
input from players
*/
display(3,33,flag);// display zero-chokdi at bottom-right on the screen.
gotoxy(2,32);
printf(" Player %d",flag);
gotoxy(10,35);
printf("Name: ");
if(flag==zero)
{
printf("%s",player1);
}
else
{
printf("%s",player2);
}
/*
display the ox 3X3 array.
*/
for (p=1;p<=3;p++)
{
for (q=1;q<=3;q++)
{
if(ox[p][q]==zero || ox[p][q]==chokdi)
{
print_location(p,q);
display(f,s,ox[p][q]);
}
}
}
gotoxy(10,38);
printf("Row: ");
scanf("%d",&rows); //inputing rows
gotoxy(20,38);
printf("Column: ");
scanf("%d",&cols); //inputing cols
gotoxy(25,42);
printf("Ok..[enter any key OR No]: ");
cho=getch();
if(cho=='N' || cho=='n')
goto go;
/*
your entered row or column are perfect or not then try agin.
*/
if((rows<1 || rows>3) || (cols<1 || cols&>3))
{
gotoxy(25,42);
printf("Try agean [OK]...\t\t");
getch();
goto go;
}
/*
duplicate entry not permitted to checking this conditions
*/
if(ox[rows][cols]==zero || ox[rows][cols]==chokdi )
{
gotoxy(25,42);
printf(" Your location all ready exist [OK]...");
getch();
goto go;
}
/*
Insert the zero('o') and chokdi('x') in the ox[3][3].
*/
if(flag==chokdi)
{
ox[rows][cols]=chokdi;
}
else
{
ox[rows][cols]=zero;
}
cho=check();
if(cho=='y')
{
// display the winner is player1 or player2.
for(i=6;i<=27;i++)
{
for (j=12;j<=73;j+=53)
{
gotoxy (j,i);
printf("-");
}
}
for (j=12;j<=65;j++)
{
for(i=6;i<=27;i+=21)
{
gotoxy (j,i);
printf("-");
}
}
gotoxy(15,35);
if(flag==zero)
printf("Congratulation %s, YOU ARE WINNER!!!!!!!!",player1);
else
printf("Congratulation %s, YOU ARE WINNER!!!!!!!!",player2);
getch();
break;
}
l++;
}while (l<=9);
//ending of loop
clrscr();
//asking from uesrs, play again?
gotoxy(30,35);
printf("PLAY AGAIN[YES/NO]:");
cho=getch();
if(cho=='y')
goto go2;
//ending of program
}
void setnull(int *t)
{
for (i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
*t=NULL;
t++;
}
}
};
// display x or o at screen
void display(int a,int b,int cho)
{
char *tamp;
if(cho==zero)
tamp=&o[0][0];
else if(cho==chokdi)
tamp=&x[0][0];
for (i=0;i<size;i++)
{
gotoxy(a,b);
for (j=0;j<size;j++)
{
printf("%c",*tamp);
tamp++;
}
b++;
}
};
void print_location(int a,int b)
{
int x;
for (i=1,x=6;i<=3;i++,x+=7)
{
if(a==i)
s=x;
}
for (i=1,x=21;i<=3;i++,x+=13)
{
if(b==i)
f=x;
}
};
char check()
{
char ask='n';
int one,two;
clrscr();
for (one=1;one<=3;one++)
{
if(ox[one][1]==zero && ox[one][2]==zero && ox[one][3]==zero)
{
for (two=1;two<=3;two++)
{
print_location(one,two);
display(f,s,zero);
}
ask='y';
}
else if(ox[one][1]==chokdi && ox[one][2]==chokdi && ox[one][3]==chokdi)
{
for (two=1;two<=3;two++)
{
print_location(one,two);
display(f,s,chokdi);
}
ask='y';
}
else if(ox[1][one]==zero && ox[2][one]==zero && ox[3][one]==zero)
{
for (two=1;two<=3;two++)
{
print_location(two,one);
display(f,s,zero);
}
ask='y';
}
else if(ox[1][one]==chokdi && ox[2][one]==chokdi && ox[3][one]==chokdi)
{
for (two=1;two<=3;two++)
{
print_location(two,one);
display(f,s,chokdi);
}
ask='y'; //player2 win
}
}
if(ox[1][1]==zero && ox[2][2]==zero && ox[3][3]==zero)
{
for (one=1;one<=3;one++)
{
print_location(one,one);
display(f,s,zero);
}
ask='y'; //player1 win
}
else if(ox[1][1]==chokdi && ox[2][2]==chokdi && ox[3][3]==chokdi)
{
for (one=1;one<=3;one++)
{
print_location(one,one);
display(f,s,chokdi);
}
ask='y'; //player2 win
}
else if(ox[3][1]==zero && ox[2][2]==zero && ox[1][3]==zero)
{
for (one=3,two=1;one>=0 && two<=3;one--,two++)
{
print_location(one,two);
display(f,s,zero);
}
ask='y'; //player1 win
}
else if(ox[3][1]==chokdi && ox[2][2]==chokdi && ox[1][3]==chokdi)
{
for (one=3,two=1;one>=0 && two<=3;one--,two++)
{
print_location(one,two);
display(f,s,chokdi);
}
ask='y'; //player2 win
}
return ask;
};
![[del.icio.us]](http://www.itshala.com/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.itshala.com/wp-content/plugins/bookmarkify/digg.png)
![[dzone]](http://www.itshala.com/wp-content/plugins/bookmarkify/dzone.png)
![[Facebook]](http://www.itshala.com/wp-content/plugins/bookmarkify/facebook.png)
![[Google]](http://www.itshala.com/wp-content/plugins/bookmarkify/google.png)
![[LinkedIn]](http://www.itshala.com/wp-content/plugins/bookmarkify/linkedin.png)
![[Twitter]](http://www.itshala.com/wp-content/plugins/bookmarkify/twitter.png)
![[Windows Live]](http://www.itshala.com/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://www.itshala.com/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://www.itshala.com/wp-content/plugins/bookmarkify/email.png)
