Source Code
// TICTACTO GAME
// Desing by: Hitesh
#include<fstream.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<iomanip.h>
#include<ctype.h>
void print_cover();
const float PI=3.141;
class needle
{
int size,color,x,y,end_x,end_y;
double theta;
public:
void draw(float,float);
void init(int a,int b,int c,int d)
{x=a;y=b;size=c;color=d;}
};
void needle::draw(float a,float b)
{
theta=(a*b-90)*(PI/180);
setcolor(0);
line(x,y,end_x,end_y);
setcolor(color);
end_x=x+cos(theta)*size;
end_y=y+sin(theta)*size;
line(x,y,end_x,end_y);
}
void boundary();
void getpassword();
void initialise();
int print_ttt_menu();
int get_yesno_option();
int check(char [],char[]);
void input(char,char [],char []);
void putat(char);
void border();
void trick1();
void trick2();
int checkwin();
int nop,flag;
int i=1,arr[3][3];
void main()
{
clrscr();
initialise();
//getpassword();
print_cover();
cleardevice();
int ch;
char name1[10],name2[10],name[10];
int i,j,st,getinput,x,n,p,c,k;
getinput:
nop=0;
cleardevice();
ch=print_ttt_menu();
switch(ch)
{
case 1:
nop=1;
p=0;
cleardevice();
for(i=0;i<3;i++)
for(j=0;j<3;j++)
::arr[i][j]='-';
boundary();
settextstyle(1,0,6);
setcolor(10);
outtextxy(130,20,"TIC-TAC-TOE");
setcolor(LIGHTGREEN);
line(120,90,480,90);
setcolor(CYAN);
line(120,91,480,91);
setcolor(MAGENTA);
line(120,92,480,92);
setcolor(YELLOW);
line(120,93,480,93);
for(int i=0;i<8;i++)
{
settextstyle(1,0,3);
setcolor(GREEN);
outtextxy(50,200," Enter your Name : ");
n=getch();
if(n==13)
break;
if(n==8)
{
if(p==0)
i--;
else
{
setcolor(0);
outtextxy(400,200,name);
p--;
name[p]='\0';
i-=2;
}
}
else
{
name[i]=n;
name[++p]='\0';
}
setcolor(YELLOW);
outtextxy(400,200,name);
}
cleardevice();
setcolor(5);
for( j=0;j<=18;j++)
rectangle(j,j,640-j,480-j);
setcolor(12);
for(i=0;i<4;i++)
line(i+220,80,i+220,450);
for(i=0;i<4;i++)
line(i+370,80,i+370,450);
for(i=0;i<4;i++)
line(70,i+200,510,i+200);
for(i=0;i<4;i++)
line(70,i+330,510,i+330);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
::arr[i][j]='-';
randomize();
c=random(2)+1;
//c=0;
if(c==1)
{
for(k=1;k<=9;k++)
{
if(k%2==0)
input('O',name1,name);
else
{
trick1();
}
int ret=check(name1,name);
if(ret==1)
goto getinput;
}
}
else
{
for(k=1;k<=9;k++)
{
if(k%2==0)
{
trick2();
}
else
input('O',name1,name);
int ret=check(name1,name);
if(ret==1)
goto getinput;
}
}
setcolor(10);
settextstyle(1,0,4);
outtextxy(160,20,"The Match Is Draw ");
getch();
cleardevice();
goto getinput;
case 2:
cleardevice();
boundary();
settextstyle(1,0,6);
setcolor(LIGHTRED);
outtextxy(120,20,"TIC-TAC-TOE");
setcolor(LIGHTGREEN);
line(110,90,480,90);
setcolor(CYAN);
line(110,91,480,91);
setcolor(MAGENTA);
line(110,92,480,92);
setcolor(YELLOW);
line(110,92,480,92);
int p2name,name;
p=0;
for(i=0;i<8;i++)
{
settextstyle(1,0,3);
setcolor(GREEN);
outtextxy(50,150,"Player 1 Enter your Name : ");
n=getch();
if(n==13)
break;
if(n==8)
{
if(p==0)
i--;
else
{
setcolor(0);
outtextxy(400,150,name1);
p--;
name1[p]='\0';
i-=2;
}
}
else
{
name1[i]=n;
name1[++p]='\0';
}
setcolor(YELLOW);
outtextxy(400,150,name1);
}
p=0;
for( i=0;i<8;i++)
{
settextstyle(1,0,3);
setcolor(GREEN);
outtextxy(50,260,"Player 2 Enter your Name : ");
n=getch();
if(n==13)
break;
if(n==8)
{
if(p==0)
i--;
else
{
setcolor(0);
outtextxy(400,260,name2);
p--;
name2[p]='\0';
i-=2;
}
}
else
{
name2[i]=n;
name2[++p]='\0';
}
setcolor(YELLOW);
outtextxy(400,260,name2);
}
cleardevice();
setcolor(YELLOW);
for( j=0;j<=18;j++)
rectangle(j,j,j+618,j+460);
setcolor(12);
for(i=0;i<4;i++)
line(i+220,80,i+220,450);
for(i=0;i<4;i++)
line(i+370,80,i+370,450);
for(i=0;i<4;i++)
line(70,i+200,510,i+200);
for(i=0;i<4;i++)
line(70,i+330,510,i+330);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
::arr[i][j]='-';
randomize();
c=random(2)+1;
if(c==1)
{
for(c=1;c<=9;c++)
{
if(c%2==0)
input('X',name1,name2);
else
input('O',name1,name2);
int ret=check(name1,name2);
if(ret==1)
goto getinput;
}
}
else
{
for(int c=0;c<9;c++)
{
if(c%2==0)
input('X',name1,name2);
else
input('O',name1,name2);
int ret=check(name1,name2);
if(ret==1)
goto getinput;
}
}
setcolor(10);
settextstyle(1,0,4);
outtextxy(160,20,"The Match Is Draw ");
getch();
cleardevice();
goto getinput;
case 3:
cleardevice();
boundary();
setcolor(11);
settextstyle(4,0,7);
outtextxy(160,10,"Instructions");
setcolor(5);
settextstyle(7,0,3);
outtextxy(15,90,"Player 1(X)");
outtextxy(450,90,"Player 2(0)");
setcolor(YELLOW);
settextstyle(7,0,2);
outtextxy(15,130,"Up Left . . . . . . . . . 7");
outtextxy(15,150,"Up Right . . . . . . . . . 9");
outtextxy(15,170,"Up . . . . . . . . . . . . 8");
outtextxy(15,190,"Down . . . . . . . . . . . . 2");
outtextxy(15,210,"Down Left . . . . . . . . 1");
outtextxy(15,230,"Down Right . . . . . . . 3");
outtextxy(15,250,"Left . . . . . . . . . . . . . 4");
outtextxy(15,270,"Right . . . . . . . . . . . . 6");
outtextxy(15,290,"Center . . . . . . . . . . . 5");
//outtextxy(12,310,"Exit . . . . . . . . . . . ' - '");
outtextxy(380,130,"Up Left . . . . . . . . . q");
outtextxy(380,150,"Up Right . . . . . . . . . e");
outtextxy(380,170,"Up . . . . . . . . . . . . w");
outtextxy(380,190,"Down . . . . . . . . . . . . x");
outtextxy(380,210,"Down Left . . . . . . . . z");
outtextxy(380,230,"Down Right . . . . . . . c");
outtextxy(380,250,"Left . . . . . . . . . . . . . a");
outtextxy(380,270,"Right . . . . . . . . . . . . d");
outtextxy(380,290,"Center . . . . . . . . . . . s");
//outtextxy(380,310,"Exit . . . . . . . . . . . ' ` '");
delay(1000);
setcolor(10);
settextstyle(7,0,6);
outtextxy(100,340,"Happy Playing!!");
setcolor(RED);
settextstyle(4,0,5);
outtextxy(100,389,"*************************");
getch();
cleardevice();
goto getinput;
case 4:
x=get_yesno_option();
if(x==1)
exit(0);
else if(x==2)
goto getinput;
}
getch();
}
void initialise()
{
int GD,GM;
detectgraph(&GD,&GM);
initgraph(&GD,&GM,"C:\\tc\\bgi");
}
void getpassword()
{
int i,j;
char password[7],ch;
ifstream ob1;
ob1.open("password");
ob1>>password;
ob1.close();
char pw[7];
for(i=0;i<3;i++)
{
gotoxy(21,13+i);
cout<<" Enter CURRENT Password:";
for(j=0;;j++)
{
pw[j]=getch();
if(pw[j]==13)
break;
else
cout<<'*';
}
pw[j]='\0';
if(strcmp(password,pw)!=0)
{
cout<<'X';
sound(500);
delay(80);
nosound();
if(i==2)
{
cout<<"\n\n\n\n\t\tFATAL ERROR : Access Denied !!\a";
delay(400);
exit(0);
}
}
else
break;
}
}
int print_ttt_menu()
{
int i;
char menu[5][20]={"$ Single Player","$ Double Player","$ Instructions","$ Exit"};
int yaxiss[]={180,220,260,300,340};
const int xaxiss=170;
static int selected=1;
border();
settextstyle(7,0,6);
setcolor(11);
outtextxy(120,50,"TIC-TAC-TOE");
setcolor(LIGHTGREEN);
line(110,130,480,130);
setcolor(CYAN);
line(110,131,480,131);
setcolor(MAGENTA);
line(110,132,480,132);
setcolor(YELLOW);
line(110,133,480,133);
setcolor(4);
settextstyle(7,0,4);
for(i=0;i<4;i++)
outtextxy(xaxiss,yaxiss[i],menu[i]);
setcolor(YELLOW);
outtextxy(xaxiss,yaxiss[selected-1],menu[selected-1]);
int getinput;
getinput:
int ch=getch();
switch(ch)
{
case 72:
setcolor(4);
outtextxy(xaxiss,yaxiss[selected-1],menu[selected-1]);
selected--;
if(selected<=0)
selected=4;
setcolor(YELLOW);
outtextxy(xaxiss,yaxiss[selected-1],menu[selected-1]);
goto getinput;
case 80:
setcolor(4);
outtextxy(xaxiss,yaxiss[selected-1],menu[selected-1]);
selected++;
if(selected>4) selected=1;
setcolor(YELLOW);
outtextxy(xaxiss,yaxiss[selected-1],menu[selected-1]);
goto getinput;
case 13:
break;
default:
goto getinput;
}
return selected;
}
void print_cover()
{
clearviewport();
char menu[][30]={"Continue ..."," Exit !"};
int x[2]={30,500},y=400,i,selected=1,ch,getinput,end,k=100,j;
for(i=1;!kbhit();i++,k+=10)
{
boundary();
if(i%2==0)
{
setcolor(YELLOW);
k+=10;
}
else
setcolor(4);
sound(k);
delay(100);
nosound();
settextstyle(8,0,8);
outtextxy(25,10,"TIC-TAC-TOE");
if(i%2==0)
setcolor(LIGHTRED);
else
setcolor(11);
outtextxy(27,8,"TIC-TAC-TOE");
settextstyle(7,0,3);
setcolor(13);
outtextxy(100,140,"Made By : ");
settextstyle(4,0,4);
setcolor(12);
outtextxy(240,140,"Hitesh Kumar");
setcolor(15);
outtextxy(242,138,"Hitesh Kumar");
settextstyle(7,0,3);
setcolor(13);
outtextxy(110,200,"Class : ");
settextstyle(4,0,4);
setcolor(15);
outtextxy(240,200,"BCA");
setcolor(GREEN);
outtextxy(242,198,"BCA");
settextstyle(7,0,3);
setcolor(13);
outtextxy(110,260,"Hitesh : ");
settextstyle(4,0,4);
setcolor(15);
outtextxy(240,260,". . . . .");
setcolor(4);
outtextxy(242,258,". . . . .");
settextstyle(7,0,3);
setcolor(13);
outtextxy(110,320,"Hitesh");
settextstyle(7,0,4);
setcolor(YELLOW);
outtextxy(240,320,"Hitesh");
setcolor(4);
outtextxy(242,318,"Hitesh");
setcolor(7);
settextstyle(4,0,5);
for(j=0;j<2;j++)
outtextxy(x[j],y,menu[j]);
setcolor(10);
outtextxy(x[selected-1],y,menu[selected-1]);
}
getinput:
ch=getch();
switch(ch)
{
case 77:
setcolor(7);
outtextxy(x[selected-1],y,menu[selected-1]);
selected++;
if(selected>2)
selected--;
setcolor(10);
outtextxy(x[selected-1],y,menu[selected-1]);
goto getinput;
case 75:
setcolor(7);
outtextxy(x[selected-1],y,menu[selected-1]);
selected--;
if(selected<1)
selected++;
setcolor(10);
outtextxy(x[selected-1],y,menu[selected-1]);
goto getinput;
case 13:
goto end;
default:
goto getinput;
}
end:
clearviewport();
if(selected==2)
exit(0);
}
void border()
{
settextstyle(0,0,0);
for(int i=0,j=0,k=632,l=5500;i<=632;i=i+8,j++,k=k-8,l-=30)
{
if(j%2==0)
setcolor(GREEN);
else
setcolor(YELLOW);
outtextxy(i,10," ");
outtextxy(k,460," ");
delay(5*::i);
}
for(i=0,j=10,k=460;j<=460;j=j+8,i++,k=k-8,l+=30)
{
if(i%2==0)
setcolor(GREEN);
else
setcolor(YELLOW);
outtextxy(632,j," ");
outtextxy(0,k," ");
delay(5*::i);
}
for( i=8,j=0,k=618,l=5500;i<=630;i=i+8,j++,k=k-8,l-=30)
{
/*sound(j);
delay(10*::i);
nosound();*/
if(j%2==0)
setcolor(LIGHTRED);
else
setcolor(MAGENTA);
outtextxy(i,18,"°");
if(i<=622)
outtextxy(k,452,"°");
delay(5*::i);
}
for(i=0,j=18,k=450;j<=450;j=j+8,i++,k=k-8,l+=30)
{
/*sound(j);
delay(10*::i);
nosound();*/
if(i%2==0)
setcolor(LIGHTRED);
else
setcolor(MAGENTA);
outtextxy(622,j,"°");
outtextxy(8,k,"°");
delay(5*::i);
}
for( i=16,j=0,k=614,l=5500;i<=620;i=i+8,j++,k=k-8,l-=30)
{
/* sound(j);
delay(10*::i);
nosound();*/
if(j%2==0)
setcolor(CYAN);
else
setcolor(BLUE);
outtextxy(i,24," ");
if(i<=622)
outtextxy(k,445," ");
delay(5*::i);
}
for(i=0,j=24,k=442;j<=440;j=j+8,i++,k=k-8,l+=30)
{
/*sound(j);
delay(10*::i);
nosound();*/
if(i%2==0)
setcolor(CYAN);
else
setcolor(BLUE);
outtextxy(614,j," ");
outtextxy(16,k," ");
delay(5*::i);
}
settextstyle(0,0,1);
for( i=24,j=0,k=610,l=5500;i<=615;i=i+8,j++,k=k-8,l-=30)
{
/* sound(j);
delay(10*::i);
nosound();*/
if(j%2==0)
setcolor(RED);
else
setcolor(YELLOW);
outtextxy(i,30,"");
if(i<=610)
outtextxy(k,435,"");
delay(5*::i);
}
for(i=0,j=32,k=434;j<=430;j=j+8,i++,k=k-8,l+=30)
{
/* sound(j);
delay(10*::i);
nosound();*/
if(i%2==0)
setcolor(RED);
else
setcolor(YELLOW);
outtextxy(608,j,"");
outtextxy(24,k,"");
delay(5*::i);
}
::i=0;
}
int get_yesno_option()
{
cleardevice();
boundary();
char yesno[][4]={"YES\0","NO\0"};
int xaxess[]={160,380};
const int yaxess=180;
settextstyle(1,0,4);
setcolor(11);
outtextxy(120,100,"DO YOU WANT TO QUIT ?!!");
settextstyle(4,0,4);
setcolor(BLUE);
for(int i=0;i<=1;i++)
outtextxy(xaxess[i],yaxess,yesno[i]);
setcolor(10);
int selected=2;
outtextxy(xaxess[selected-1],yaxess,yesno[selected-1]);
int getinput;
getinput:
int ch=getch();
switch(ch)
{
case 75:
setcolor(BLUE);
outtextxy(xaxess[selected-1],yaxess,yesno[selected-1]);
selected--;
if(selected<1)
{
selected++;
setcolor(10);
outtextxy(xaxess[selected-1],yaxess,yesno[selected-1]);
goto getinput;
}
setcolor(10);
outtextxy(xaxess[selected-1],yaxess,yesno[selected-1]);
goto getinput;
case 77:
setcolor(BLUE);
outtextxy(xaxess[selected-1],yaxess,yesno[selected-1]);
selected++;
if(selected>2)
{
selected--;
setcolor(10);
outtextxy(xaxess[selected-1],yaxess,yesno[selected-1]);
goto getinput;
}
setcolor(10);
outtextxy(xaxess[selected-1],yaxess,yesno[selected-1]);
goto getinput;
case 13:
break;
default:
goto getinput;
}
cleardevice();
return selected;
}
void boundary()
{
setcolor(LIGHTRED);
rectangle(5,10,630,460);
setcolor(MAGENTA);
rectangle(0,5,635,465);
}
void trick1()
{
int i,j,turn=1,f=0;
flag=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(::arr[i][j]=='X')
turn++;
if(turn==1)
{
randomize();
int ch=random(4)+1;
if(ch==1)
putat('7');
else if(ch==2)
putat('9');
else if(ch==3)
putat('1');
else
putat('3');
}
else if(turn==2)
{
flag=0;
//void check_winning();
if(::arr[0][0]=='X'&&::arr[1][2]=='O'&&flag==0)
{putat('5');flag=1;}
else if(::arr[0][2]=='X'&&::arr[1][0]=='O'&&flag==0)
{putat('5');flag=1;}
else if(::arr[2][0]=='X'&&::arr[1][2]=='O'&&flag==0)
{putat('5');flag=1;}
else if(::arr[2][2]=='X'&&::arr[1][0]=='O'&&flag==0)
{putat('5');flag=1;}
else if(::arr[0][0]=='X'&&::arr[1][1]=='O'&&::arr[2][2]=='-'&&flag==0)
{putat('3');flag=1;}
else if(::arr[0][2]=='X'&&::arr[1][1]=='O'&&::arr[2][0]=='-'&&flag==0)
{putat('1');flag=1;}
else if(::arr[2][2]=='X'&&::arr[1][1]=='O'&&::arr[0][0]=='-'&&flag==0)
{putat('7');flag=1;}
else if(::arr[2][0]=='X'&&::arr[1][1]=='O'&&::arr[0][2]=='-'&&flag==0)
{putat('9');flag=1;}
else if(::arr[0][0]=='X'&&::arr[1][0]=='-'&&::arr[1][1]=='-'&&::arr[1][2]=='-'&&::arr[2][0]=='-'&&::arr[2][2]=='-'&&flag==0)
{putat('4');flag=1;}
else if(::arr[0][0]=='X'&&::arr[0][1]=='-'&&::arr[0][2]=='-'&&::arr[1][1]=='-'&&::arr[2][1]=='-'&&::arr[2][2]=='-'&&flag==0)
{putat('8');flag=1;}
else if(::arr[0][2]=='X'&&::arr[0][0]=='-'&&::arr[0][1]=='-'&&::arr[1][1]=='-'&&::arr[2][1]=='-'&&::arr[2][0]=='-'&&flag==0)
{putat('8');flag=1;}
else if(::arr[0][2]=='X'&&::arr[1][0]=='-'&&::arr[1][1]=='-'&&::arr[1][2]=='-'&&::arr[2][0]=='-'&&::arr[2][2]=='-'&&flag==0)
{putat('6');flag=1;}
else if(::arr[2][2]=='X'&&::arr[1][0]=='-'&&::arr[1][1]=='-'&&::arr[1][2]=='-'&&::arr[0][0]=='-'&&::arr[0][2]=='-'&&flag==0)
{putat('6');flag=1;}
else if(::arr[2][2]=='X'&&::arr[0][0]=='-'&&::arr[0][1]=='-'&&::arr[1][1]=='-'&&::arr[2][0]=='-'&&::arr[2][1]=='-'&&flag==0)
{putat('2');flag=1;}
else if(::arr[2][0]=='X'&&::arr[0][2]=='-'&&::arr[0][1]=='-'&&::arr[1][1]=='-'&&::arr[2][1]=='-'&&::arr[2][2]=='-'&&flag==0)
{putat('2');flag=1;}
else if(::arr[2][0]=='X'&&::arr[0][0]=='-'&&::arr[0][2]=='-'&&::arr[1][0]=='-'&&::arr[1][1]=='-'&&::arr[1][2]=='-'&&flag==0)
{putat('4');flag=1;}
else if(::arr[0][0]=='X'&&flag==0)
{
f=0;
randomize();
do
{
int ch=random(3)+1;
switch(ch)
{
case 1:
if(::arr[2][2]=='-')
{
putat('3');
flag=1;
f=1;
break;
}
case 2:
if(::arr[2][0]=='-')
{
putat('1');
flag=1;
f=1;
break;
}
case 3:
if(::arr[0][2]=='-')
{
putat('9');
flag=1;
f=1;
break;
}
}
}while(f==0);
}
else if(::arr[2][0]=='X'&&flag==0)
{
f=0;
randomize();
do
{
int ch=random(3)+1;
switch(ch)
{
case 1:
if(::arr[0][0]=='-')
{
putat('7');
f=1;flag=1;
break;
}
case 2:
if(::arr[0][2]=='-')
{
putat('9');
f=1;flag=1;
break;
}
case 3:
if(::arr[2][2]=='-')
{
putat('3');
f=1;flag=1;
break;
}
}
}while(f==0);
}
else if(::arr[2][2]=='X')
{
f=0;
randomize();
do
{
int ch=random(3)+1;
switch(ch)
{
case 1:
if(::arr[0][0]=='-')
{
putat('7');
f=1;flag=1;
break;
}
case 2:
if(::arr[0][2]=='-')
{
putat('9');
f=1;flag=1;
break;
}
case 3:
if(::arr[2][0]=='-')
{
putat('1');
f=1;flag=1;
break;
}
}
}while(f==0);
}
else if(::arr[0][2]=='X')
{
randomize();
f=0;
do
{
int ch=random(3)+1;
switch(ch)
{
case 1:
if(::arr[0][0]=='-')
{
putat('7');
f=1;flag=1;
break;
}
case 2:
if(::arr[2][0]=='-')
{
putat('9');
f=1;flag=1;
break;
}
case 3:
if(::arr[2][2]=='-')
{
putat('3');
f=1;flag=1;
break;
}
}
}while(f==0);
}
}
else
{
/* CHECK IF ANY ONE IS WINNING */
//void check_winning();
if((::arr[0][0]=='-')&&(((::arr[0][1]==::arr[0][2])&&(::arr[0][1]=='X'))||((::arr[1][0]==::arr[2][0])&&(::arr[1][0]=='X'))||((::arr[1][1]==::arr[2][2])&&(::arr[1][1]=='X')))&&flag==0)
{putat('7');flag=1;}
else if((::arr[0][1]=='-')&&(((::arr[0][0]==::arr[0][2])&&(::arr[0][0]=='X'))||((::arr[1][1]==::arr[2][1])&&(::arr[1][1]=='X')))&&flag==0)
{putat('8');flag=1;}
else if((::arr[0][2]=='-')&&(((::arr[0][1]==::arr[0][0])&&(::arr[0][1]=='X'))||((::arr[1][2]==::arr[2][2])&&(::arr[1][2]=='X'))||((::arr[1][1]==::arr[2][0])&&(::arr[1][1]=='X')))&&flag==0)
{putat('9');flag=1;}
else if((::arr[1][0]=='-')&&(((::arr[0][0]==::arr[2][0])&&(::arr[0][0]=='X'))||((::arr[1][2]==::arr[1][1])&&(::arr[1][2]=='X')))&&flag==0)
{putat('4');flag=1;}
else if((::arr[1][1]=='-')&&(((::arr[0][1]==::arr[2][1])&&(::arr[0][1]=='X'))||((::arr[1][0]==::arr[1][2])&&(::arr[1][0]=='X'))||((::arr[0][2]==::arr[2][0])&&(::arr[0][2]=='X'))||((::arr[0][0]==::arr[2][2])&&(::arr[0][0]=='X')))&&flag==0)
{putat('5');flag=1;}
else if((::arr[1][2]=='-')&&(((::arr[0][2]==::arr[2][2])&&(::arr[0][2]=='X'))||((::arr[1][0]==::arr[1][1])&&(::arr[1][0]=='X')))&&flag==0)
{putat('6');flag=1;}
else if((::arr[2][0]=='-')&&(((::arr[0][0]==::arr[1][0])&&(::arr[0][0]=='X'))||((::arr[2][2]==::arr[2][1])&&(::arr[2][2]=='X'))||((::arr[1][1]==::arr[0][2])&&(::arr[1][1]=='X')))&&flag==0)
{putat('1');flag=1;}
else if((::arr[2][1]=='-')&&(((::arr[0][1]==::arr[1][1])&&(::arr[0][1]=='X'))||((::arr[2][0]==::arr[2][2])&&(::arr[2][0]=='X')))&&flag==0)
{putat('2');flag=1;}
else if((::arr[2][2]=='-')&&(((::arr[0][0]==::arr[1][1])&&(::arr[0][0]=='X'))||((::arr[1][2]==::arr[0][2])&&(::arr[1][2]=='X'))||((::arr[2][1]==::arr[2][0])&&(::arr[2][1]=='X')))&&flag==0)
{putat('3');flag=1;}
else if((::arr[0][0]=='-')&&(((::arr[0][1]==::arr[0][2])&&(::arr[0][1]=='O'))||((::arr[1][0]==::arr[2][0])&&(::arr[1][0]=='O'))||((::arr[1][1]==::arr[2][2])&&(::arr[1][1]=='O')))&&flag==0)
{putat('7');flag=1;}
else if((::arr[0][1]=='-')&&(((::arr[0][0]==::arr[0][2])&&(::arr[0][0]=='O'))||((::arr[1][1]==::arr[2][1])&&(::arr[1][1]=='O')))&&flag==0)
{putat('8');flag=1;}
else if((::arr[0][2]=='-')&&(((::arr[0][1]==::arr[0][0])&&(::arr[0][1]=='O'))||((::arr[1][2]==::arr[2][2])&&(::arr[1][2]=='O'))||((::arr[1][1]==::arr[2][0])&&(::arr[1][1]=='O')))&&flag==0)
{putat('9');flag=1;}
else if((::arr[1][0]=='-')&&(((::arr[0][0]==::arr[2][0])&&(::arr[0][0]=='O'))||((::arr[1][2]==::arr[1][1])&&(::arr[1][2]=='O')))&&flag==0)
{putat('4');flag=1;}
else if((::arr[1][1]=='-')&&(((::arr[0][1]==::arr[2][1])&&(::arr[0][1]=='O'))||((::arr[1][0]==::arr[1][2])&&(::arr[1][0]=='O'))||((::arr[0][2]==::arr[2][0])&&(::arr[0][2]=='O'))||((::arr[0][0]==::arr[2][2])&&(::arr[0][0]=='X')))&&flag==0)
{putat('5');flag=1;}
else if((::arr[1][2]=='-')&&(((::arr[0][2]==::arr[2][2])&&(::arr[0][2]=='O'))||((::arr[1][0]==::arr[1][1])&&(::arr[1][0]=='O')))&&flag==0)
{putat('6');flag=1;}
else if((::arr[2][0]=='-')&&(((::arr[0][0]==::arr[1][0])&&(::arr[0][0]=='O'))||((::arr[2][2]==::arr[2][1])&&(::arr[2][2]=='O'))||((::arr[1][1]==::arr[0][2])&&(::arr[1][1]=='O')))&&flag==0)
{putat('1');flag=1;}
else if((::arr[2][1]=='-')&&(((::arr[0][1]==::arr[1][1])&&(::arr[0][1]=='O'))||((::arr[2][0]==::arr[2][2])&&(::arr[2][0]=='O')))&&flag==0)
{putat('2');flag=1;}
else if((::arr[2][2]=='-')&&(((::arr[0][0]==::arr[1][1])&&(::arr[0][0]=='O'))||((::arr[1][2]==::arr[0][2])&&(::arr[1][2]=='O'))||((::arr[2][1]==::arr[2][0])&&(::arr[2][1]=='O')))&&flag==0)
{putat('3');flag=1;}
/* CHECK FOR APPLICABILITY OF TRIPLE TRIC */
else if(::arr[0][0]=='X'&&::arr[1][0]=='X'&&::arr[1][1]=='-'&&::arr[1][2]=='-'&&::arr[2][2]=='-'&&flag==0)
{putat('5');flag=1;}
else if(::arr[1][0]=='X'&&::arr[2][0]=='X'&&::arr[1][1]=='-'&&::arr[1][2]=='-'&&::arr[0][2]=='-'&&flag==0)
{putat('5');flag=1;}
else if(::arr[0][0]=='X'&&::arr[0][1]=='X'&&::arr[1][1]=='-'&&::arr[2][1]=='-'&&::arr[2][2]=='-'&&flag==0)
{putat('5');flag=1;}
else if(::arr[0][1]=='X'&&::arr[0][2]=='X'&&::arr[1][1]=='-'&&::arr[2][1]=='-'&&::arr[2][0]=='-'&&flag==0)
{putat('5');flag=1;}
else if(::arr[0][2]=='X'&&::arr[1][2]=='X'&&::arr[1][1]=='-'&&::arr[1][0]=='-'&&::arr[2][0]=='-'&&flag==0)
{putat('5');flag=1;}
else if(::arr[1][2]=='X'&&::arr[2][2]=='X'&&::arr[1][1]=='-'&&::arr[0][0]=='-'&&::arr[1][0]=='-'&&flag==0)
{putat('5');flag=1;}
else if(::arr[2][1]=='X'&&::arr[2][2]=='X'&&::arr[1][1]=='-'&&::arr[0][0]=='-'&&::arr[0][1]=='-'&&flag==0)
{putat('5');flag=1;}
else if(::arr[2][0]=='X'&&::arr[2][1]=='X'&&::arr[1][1]=='-'&&::arr[0][1]=='-'&&::arr[0][2]=='-'&&flag==0)
{putat('5');flag=1;}
/*TRIPLE TRICK*/
else if(::arr[0][0]=='X'&&::arr[1][0]=='-'&&::arr[1][1]=='-'&&::arr[1][2]=='-'&&::arr[2][0]=='-'&&::arr[2][2]=='-'&&flag==0)
{putat('4');flag=1;}
else if(::arr[0][0]=='X'&&::arr[0][1]=='-'&&::arr[0][2]=='-'&&::arr[1][1]=='-'&&::arr[2][1]=='-'&&::arr[2][2]=='-'&&flag==0)
{putat('8');flag=1;}
else if(::arr[0][2]=='X'&&::arr[0][0]=='-'&&::arr[0][1]=='-'&&::arr[1][1]=='-'&&::arr[2][1]=='-'&&::arr[2][0]=='-'&&flag==0)
{putat('8');flag=1;}
else if(::arr[0][2]=='X'&&::arr[1][0]=='-'&&::arr[1][1]=='-'&&::arr[1][2]=='-'&&::arr[2][0]=='-'&&::arr[2][2]=='-'&&flag==0)
{putat('6');flag=1;}
else if(::arr[2][2]=='X'&&::arr[1][0]=='-'&&::arr[1][1]=='-'&&::arr[1][2]=='-'&&::arr[0][0]=='-'&&::arr[0][2]=='-'&&flag==0)
{putat('6');flag=1;}
else if(::arr[2][2]=='X'&&::arr[0][0]=='-'&&::arr[0][1]=='-'&&::arr[1][1]=='-'&&::arr[2][0]=='-'&&::arr[2][1]=='-'&&flag==0)
{putat('2');flag=1;}
else if(::arr[2][0]=='X'&&::arr[0][2]=='-'&&::arr[0][1]=='-'&&::arr[1][1]=='-'&&::arr[2][1]=='-'&&::arr[2][2]=='-'&&flag==0)
{putat('2');flag=1;}
else if(::arr[2][0]=='X'&&::arr[0][0]=='-'&&::arr[0][2]=='-'&&::arr[1][0]=='-'&&::arr[1][1]=='-'&&::arr[1][2]=='-'&&flag==0)
{putat('4');flag=1;}
/*DOUBLE TRICK*/
else if(::arr[0][0]=='X'&&::arr[2][0]=='X'&&flag==0)
{
if((::arr[0][2]=='-')&&((::arr[0][1]=='-'&&::arr[1][0]=='-')||
(::arr[1][0]=='-'&&::arr[1][1]=='-')||(::arr[0][1]=='-'&&::arr[1][1]=='-')))
{putat('9');flag=1;}
else if((::arr[2][2]=='-')&&((::arr[1][0]=='-'&&::arr[2][1])||
(::arr[1][1]=='-'&&::arr[2][1]=='-')||(::arr[1][1]=='-'&&::arr[1][0]=='-')))
{putat('3');flag=1;}
}
else if(::arr[0][0]=='X'&&::arr[0][2]=='X'&&flag==0)
{
if((::arr[2][2]=='-')&&((::arr[1][1]=='-'&&::arr[1][2]=='-')||
(::arr[1][1]=='-'&&::arr[2][1]=='-')||(::arr[2][1]=='-'&&::arr[1][2]=='-')))
{putat('3');flag=1;}
if((::arr[2][0]=='-')&&((::arr[1][1]=='-'&&::arr[0][1]=='-')||
(::arr[1][1]=='-'&&::arr[1][0]=='-')||(::arr[1][0]=='-'&&::arr[0][1]=='-')))
{putat('1');flag=1;}
}
else if(::arr[0][2]=='X'&&::arr[2][2]=='X'&&flag==0)
{
if((::arr[0][0]=='-')&&((::arr[1][1]=='-'&&::arr[0][1]=='-')||
(::arr[1][1]=='-'&&::arr[1][2]=='-')||(::arr[0][1]=='-'&&::arr[1][2]=='-')))
{putat('7');flag=1;}
if((::arr[2][0]=='-')&&((::arr[1][1]=='-'&&::arr[1][2]=='-')||
(::arr[1][1]=='-'&&::arr[2][1]=='-')||(::arr[1][2]=='-'&&::arr[2][1]=='-')))
{putat('1');flag=1;}
}
else if(::arr[2][0]=='X'&&::arr[2][2]=='X'&&flag==0)
{
if((::arr[0][0]=='-')&&((::arr[1][1]=='-'&&::arr[1][0]=='-')||
(::arr[1][1]=='-'&&::arr[2][1]=='-')||(::arr[1][0]=='-'&&::arr[2][1]=='-')))
{putat('7');flag=1;}
if((::arr[0][2]=='-')&&((::arr[1][1]=='-'&&::arr[1][2]=='-')||
(::arr[1][1]=='-'&&::arr[2][1]=='-')||(::arr[1][2]=='-'&&::arr[2][1]=='-')))
{putat('9');flag=1;}
}
else if(::arr[0][0]=='X'&&::arr[2][2]=='X'&&flag==0)
{
if((::arr[0][2]=='-')&&((::arr[1][1]=='-'&&::arr[0][1]=='-')||
(::arr[1][1]=='-'&&::arr[1][2]=='-')||(::arr[0][1]=='-'&&::arr[1][2]=='-')))
{putat('9');flag=1;}
if((::arr[2][0]=='-')&&((::arr[1][1]=='-'&&::arr[1][0]=='-')||
(::arr[1][1]=='-'&&::arr[2][1]=='-')||(::arr[1][0]=='-'&&::arr[2][1]=='-')))
{putat('1');flag=1;}
}
else if(::arr[0][2]=='X'&&::arr[2][0]=='X'&&flag==0)
{
if((::arr[0][0]=='-')&&((::arr[1][1]=='-'&&::arr[0][1]=='-')||
(::arr[1][1]=='-'&&::arr[1][0]=='-')||(::arr[0][1]=='-'&&::arr[1][0]=='-')))
{putat('7');flag=1;}
if((::arr[2][2]=='-')&&((::arr[1][1]=='-'&&::arr[1][2]=='-')||
(::arr[1][1]=='-'&&::arr[2][1]=='-')||(::arr[1][2]=='-'&&::arr[2][1]=='-')))
{putat('3');flag=1;}
}
else if(::arr[1][1]=='-'&&flag==0)
{putat('5');flag=1;}
else if(::arr[0][0]=='-'&&flag==0)
{putat('7');flag=1;}
else if(::arr[0][2]=='-'&&flag==0)
{putat('9');flag=1;}
else if(::arr[2][0]=='-'&&flag==0)
{putat('1');flag=1;}
else if(::arr[2][2]=='-'&&flag==0)
{putat('3');flag=1;}
else if(::arr[1][0]=='-'&&flag==0)
{putat('4');flag=1;}
else if(::arr[0][1]=='-'&&flag==0)
{putat('8');flag=1;}
else if(::arr[2][1]=='-'&&flag==0)
{putat('2');flag=1;}
}
}
int check(char name1[8],char name2[8])
{
int i,j;
setcolor(10);
settextstyle(1,0,4);
if(::arr[0][0]==::arr[1][1]&&::arr[1][1]==::arr[2][2]&&::arr[0][0]!='-')
{
if(::arr[0][0]=='X')
{
if(nop==1)
{
outtextxy(100,20,name2);
outtextxy(240,20," You Are The Loser");
getch();
cleardevice();
}
else
{
outtextxy(100,20,name1);
outtextxy(240,20," You Are The Winner");
getch();
cleardevice();
}
return 1;
}
else
if(::arr[0][0]=='O')
{
outtextxy(100,20,name2);
outtextxy(240,20,"You Are The Winner ");
getch();
cleardevice();
return 1;
}
}
else
{
if(::arr[0][2]==::arr[1][1]&&::arr[1][1]==::arr[2][0]&&::arr[1][1]!='-')
{
if(::arr[1][1]=='X')
{
if(nop==1)
{
outtextxy(100,20,name2);
outtextxy(240,20," You Are The Loser");
getch();
cleardevice();
}
else
{
outtextxy(100,20,name1);
outtextxy(240,20," You Are The Winner");
getch();
cleardevice();
}
return 1;
}
else
if(::arr[1][1]=='O')
{
outtextxy(100,20,name2);
outtextxy(240,20," You Are The Winner");
getch();
cleardevice();
return 1;
}
}
else
for(i=0;i<3;i++)
{
if(::arr[i][0]==::arr[i][1]&&::arr[i][1]==::arr[i][2]&&::arr[i][0]!='-')
{
if(::arr[i][1]=='X')
{
if(nop==1)
{
outtextxy(100,20,name2);
outtextxy(240,20," You Are The Loser");
getch();
cleardevice();
}
else
{
outtextxy(100,20,name1);
outtextxy(240,20," You Are The Winner");
getch();
cleardevice();
}
return 1;
}
else
if(::arr[i][1]=='O')
{
outtextxy(100,20,name2);
outtextxy(240,20," You Are The Winner");
getch();
cleardevice();
return 1;
}
}
}
for(i=0;i<3;i++)
{
if(::arr[0][i]==::arr[1][i]&&::arr[1][i]==::arr[2][i]&&::arr[0][i]!='-')
{
if(::arr[0][i]=='X')
{
if(nop==1)
{
outtextxy(100,20,name2);
outtextxy(240,20," You Are The Loser");
getch();
cleardevice();
}
else
{
outtextxy(100,20,name1);
outtextxy(240,20," You Are The Winner");
getch();
cleardevice();
}
return 1;
}
else
if(::arr[0][i]=='O')
{
outtextxy(100,20,name2);
outtextxy(240,20," You Are The Winner");
getch();
cleardevice();
return 1;
}
}
}
}
return 0;
}
void input(char ch,char name1[8],char name2[8])
{
int c,i,j,x;
setcolor(10);
settextstyle(1,0,4);
if(ch=='X')
{
outtextxy(120,20,name1);
outtextxy(300,20,"(X) Your Turn");
}
else
{
outtextxy(120,20,name2);
outtextxy(300,20,"(O) Your Turn ");
}
x:
c=getch();
if(ch=='X')
{
switch(c)
{
case '7':
i=0; j=0;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+100,90,i+200,190);
line(i+200,90,i+100,190);
}
break;
case '8':
i=0; j=1;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+240,90,i+340,190);
line(i+340,90,i+240,190);
}
break;
case '9':
i=0; j=2;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+380,90,i+480,190);
line(i+480,90,i+380,190);
}
break;
case '4':
i=1; j=0;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+100,220,i+200,320);
line(i+200,220,i+100,320);
}
break;
case '5':
i=1; j=1;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+240,220,i+340,320);
line(i+340,220,i+240,320);
}
break;
case '6':
i=1; j=2;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+380,220,i+480,320);
line(i+480,220,i+380,320);
}
break;
case '1':
i=2; j=0;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+100,340,i+200,440);
line(i+200,340,i+100,440);
}
break;
case '2':
i=2; j=1;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+240,340,i+340,440);
line(i+340,340,i+240,440);
}
break;
case '3':
i=2; j=2;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+380,340,i+480,440);
line(i+480,340,i+380,440);
}
break;
default:
sound(500);
delay(200);
nosound();
goto x;
}
}
else if(ch=='O')
{
switch(c)
{
case 'Q':
case 'q':
i=0; j=0;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='O';
for( i=0;i<12;i++)
{
if(i<=2||(i>10&&i<12))
setcolor(GREEN);
else
setcolor(MAGENTA);
circle(150,138,i+50);
}
break;
case 'W':
case 'w':
i=0; j=1;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='O';
for( i=0;i<12;i++)
{
if(i<=2||(i>10&&i<12))
setcolor(GREEN);
else
setcolor(MAGENTA);
circle(298,138,i+50);
}
break;
case 'E':
case 'e':
i=0; j=2;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='O';
for( i=0;i<12;i++)
{
if(i<=2||(i>10&&i<12))
setcolor(GREEN);
else
setcolor(MAGENTA);
circle(440,138,i+50);
}
break;
case 'A':
case 'a':
i=1; j=0;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='O';
for( i=0;i<12;i++)
{
if(i<=2||(i>10&&i<12))
setcolor(GREEN);
else
setcolor(MAGENTA);
circle(150,266,i+50);
}
break;
case 'S':
case 's':
i=1; j=1;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='O';
for( i=0;i<12;i++)
{
if(i<=2||(i>10&&i<12))
setcolor(GREEN);
else
setcolor(MAGENTA);
circle(300,266,i+50);
}
break;
case 'D':
case 'd':
i=1; j=2;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='O';
for( i=0;i<12;i++)
{
if(i<=2||(i>10&&i<12))
setcolor(GREEN);
else
setcolor(MAGENTA);
circle(440,266,i+50);
}
break;
case 'Z':
case 'z':
i=2; j=0;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='O';
for( i=0;i<12;i++)
{
if(i<=2||(i>10&&i<12))
setcolor(GREEN);
else
setcolor(MAGENTA);
circle(150,398,i+50);
}
break;
case 'X':
case 'x':
i=2; j=1;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='O';
for( i=0;i<12;i++)
{
if(i<=2||(i>10&&i<12))
setcolor(GREEN);
else
setcolor(MAGENTA);
circle(300,398,i+50);
}
break;
case 'C':
case 'c':
i=2; j=2;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
goto x;
}
::arr[i][j]='O';
for( i=0;i<12;i++)
{
if(i<=2||(i>10&&i<12))
setcolor(GREEN);
else
setcolor(MAGENTA);
circle(440,398,i+50);
}
break;
default:
sound(500);
delay(200);
nosound();
goto x;
}
}
setcolor(0);
settextstyle(1,0,4);
if(ch=='X')
{
outtextxy(120,20,name1);
outtextxy(300,20,"(X) Your Turn");
}
else
{
outtextxy(120,20,name2);
outtextxy(300,20,"(O) Your Turn ");
}
}
void putat(char ch)
{
int i,j;
switch(ch)
{
case '7':
i=0; j=0;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+100,90,i+200,190);
line(i+200,90,i+100,190);
}
break;
case '8':
i=0; j=1;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+240,90,i+340,190);
line(i+340,90,i+240,190);
}
break;
case '9':
i=0; j=2;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+380,90,i+480,190);
line(i+480,90,i+380,190);
}
break;
case '4':
i=1; j=0;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+100,220,i+200,320);
line(i+200,220,i+100,320);
}
break;
case '5':
i=1; j=1;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+240,220,i+340,320);
line(i+340,220,i+240,320);
}
break;
case '6':
i=1; j=2;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+380,220,i+480,320);
line(i+480,220,i+380,320);
}
break;
case '1':
i=2; j=0;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+100,340,i+200,440);
line(i+200,340,i+100,440);
}
break;
case '2':
i=2; j=1;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+240,340,i+340,440);
line(i+340,340,i+240,440);
}
break;
case '3':
i=2; j=2;
if(arr[i][j]!='-')
{
sound(500);
delay(200);
nosound();
}
::arr[i][j]='X';
for(i=0;i<15;i++)
{
if(i<=2||(i>12&&i<15))
setcolor(GREEN);
else
setcolor(RED);
line(i+380,340,i+480,440);
line(i+480,340,i+380,440);
}
break;
case '-':
closegraph();
exit(0);
}
}
void trick2()
{
int i,j,turn=1,f;
flag=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(::arr[i][j]=='X')
turn++;
if(turn==1)
{
randomize();
int ch=random(4)+1;
if(::arr[0][0]=='O'||::arr[0][2]=='O'||::arr[2][0]=='O'||::arr[2][2]=='O')
{putat('5');flag=1;}
else if(ch==1)
{putat('7');flag=1;}
else if(ch==2)
{putat('9');flag=1;}
else if(ch==3)
{putat('1');flag=1;}
else
{putat('3');flag=1;}
}
else
{
if((::arr[0][0]=='-')&&(((::arr[0][1]==::arr[0][2])&&(::arr[0][1]=='X'))||((::arr[1][0]==::arr[2][0])&&(::arr[1][0]=='X'))||((::arr[1][1]==::arr[2][2])&&(::arr[1][1]=='X')))&&flag==0)
{putat('7');flag=1;}
else if((::arr[0][1]=='-')&&(((::arr[0][0]==::arr[0][2])&&(::arr[0][0]=='X'))||((::arr[1][1]==::arr[2][1])&&(::arr[1][1]=='X')))&&flag==0)
{putat('8');flag=1;}
else if((::arr[0][2]=='-')&&(((::arr[0][1]==::arr[0][0])&&(::arr[0][1]=='X'))||((::arr[1][2]==::arr[2][2])&&(::arr[1][2]=='X'))||((::arr[1][1]==::arr[2][0])&&(::arr[1][1]=='X')))&&flag==0)
{putat('9');flag=1;}
else if((::arr[1][0]=='-')&&(((::arr[0][0]==::arr[2][0])&&(::arr[0][0]=='X'))||((::arr[1][2]==::arr[1][1])&&(::arr[1][2]=='X')))&&flag==0)
{putat('4');flag=1;}
else if((::arr[1][1]=='-')&&(((::arr[0][1]==::arr[2][1])&&(::arr[0][1]=='X'))||((::arr[1][0]==::arr[1][2])&&(::arr[1][0]=='X'))||((::arr[0][2]==::arr[2][0])&&(::arr[0][2]=='X'))||((::arr[0][0]==::arr[2][2])&&(::arr[0][0]=='X')))&&flag==0)
{putat('5');flag=1;}
else if((::arr[1][2]=='-')&&(((::arr[0][2]==::arr[2][2])&&(::arr[0][2]=='X'))||((::arr[1][0]==::arr[1][1])&&(::arr[1][0]=='X')))&&flag==0)
{putat('6');flag=1;}
else if((::arr[2][0]=='-')&&(((::arr[0][0]==::arr[1][0])&&(::arr[0][0]=='X'))||((::arr[2][2]==::arr[2][1])&&(::arr[2][2]=='X'))||((::arr[1][1]==::arr[0][2])&&(::arr[1][1]=='X')))&&flag==0)
{putat('1');flag=1;}
else if((::arr[2][1]=='-')&&(((::arr[0][1]==::arr[1][1])&&(::arr[0][1]=='X'))||((::arr[2][0]==::arr[2][2])&&(::arr[2][0]=='X')))&&flag==0)
{putat('2');flag=1;}
else if((::arr[2][2]=='-')&&(((::arr[0][0]==::arr[1][1])&&(::arr[0][0]=='X'))||((::arr[1][2]==::arr[0][2])&&(::arr[1][2]=='X'))||((::arr[2][1]==::arr[2][0])&&(::arr[2][1]=='X')))&&flag==0)
{putat('3');flag=1;}
else if((::arr[0][0]=='-')&&(((::arr[0][1]==::arr[0][2])&&(::arr[0][1]=='O'))||((::arr[1][0]==::arr[2][0])&&(::arr[1][0]=='O'))||((::arr[1][1]==::arr[2][2])&&(::arr[1][1]=='O')))&&flag==0)
{putat('7');flag=1;}
else if((::arr[0][1]=='-')&&(((::arr[0][0]==::arr[0][2])&&(::arr[0][0]=='O'))||((::arr[1][1]==::arr[2][1])&&(::arr[1][1]=='O')))&&flag==0)
{putat('8');flag=1;}
else if((::arr[0][2]=='-')&&(((::arr[0][1]==::arr[0][0])&&(::arr[0][1]=='O'))||((::arr[1][2]==::arr[2][2])&&(::arr[1][2]=='O'))||((::arr[1][1]==::arr[2][0])&&(::arr[1][1]=='O')))&&flag==0)
{putat('9');flag=1;}
else if((::arr[1][0]=='-')&&(((::arr[0][0]==::arr[2][0])&&(::arr[0][0]=='O'))||((::arr[1][2]==::arr[1][1])&&(::arr[1][2]=='O')))&&flag==0)
{putat('4');flag=1;}
else if((::arr[1][1]=='-')&&(((::arr[0][1]==::arr[2][1])&&(::arr[0][1]=='O'))||((::arr[1][0]==::arr[1][2])&&(::arr[1][0]=='O'))||((::arr[0][2]==::arr[2][0])&&(::arr[0][2]=='O'))||((::arr[0][0]==::arr[2][2])&&(::arr[0][0]=='X')))&&flag==0)
{putat('5');flag=1;}
else if((::arr[1][2]=='-')&&(((::arr[0][2]==::arr[2][2])&&(::arr[0][2]=='O'))||((::arr[1][0]==::arr[1][1])&&(::arr[1][0]=='O')))&&flag==0)
{putat('6');flag=1;}
else if((::arr[2][0]=='-')&&(((::arr[0][0]==::arr[1][0])&&(::arr[0][0]=='O'))||((::arr[2][2]==::arr[2][1])&&(::arr[2][2]=='O'))||((::arr[1][1]==::arr[0][2])&&(::arr[1][1]=='O')))&&flag==0)
{putat('1');flag=1;}
else if((::arr[2][1]=='-')&&(((::arr[0][1]==::arr[1][1])&&(::arr[0][1]=='O'))||((::arr[2][0]==::arr[2][2])&&(::arr[2][0]=='O')))&&flag==0)
{putat('2');flag=1;}
else if((::arr[2][2]=='-')&&(((::arr[0][0]==::arr[1][1])&&(::arr[0][0]=='O'))||((::arr[1][2]==::arr[0][2])&&(::arr[1][2]=='O'))||((::arr[2][1]==::arr[2][0])&&(::arr[2][1]=='O')))&&flag==0)
{putat('3');flag=1;}
else if(::arr[0][0]=='X'&&::arr[1][2]=='O'&&flag==0)
{putat('5');flag=1;}
else if(::arr[0][2]=='X'&&::arr[1][0]=='O'&&flag==0)
{putat('5');flag=1;}
else if(::arr[2][0]=='X'&&::arr[1][2]=='O'&&flag==0)
{putat('5');flag=1;}
else if(::arr[2][2]=='X'&&::arr[1][0]=='O'&&flag==0)
{putat('5');flag=1;}
else if(::arr[0][0]=='O'&&::arr[1][0]=='O'&&::arr[1][1]=='-'&&::arr[1][2]=='-'&&::arr[2][2]=='-'&&flag==0)
{putat('5');flag=1;}
else if(::arr[1][0]=='O'&&::arr[2][0]=='O'&&::arr[1][1]=='-'&&::arr[1][2]=='-'&&::arr[0][2]=='-'&&flag==0)
{putat('5');flag=1;}
else if(::arr[0][0]=='O'&&::arr[0][1]=='O'&&::arr[1][1]=='-'&&::arr[2][1]=='-'&&::arr[2][2]=='-'&&flag==0)
{putat('5');flag=1;}
else if(::arr[0][1]=='O'&&::arr[0][2]=='O'&&::arr[1][1]=='-'&&::arr[2][1]=='-'&&::arr[2][0]=='-'&&flag==0)
{putat('5');flag=1;}
else if(::arr[0][2]=='O'&&::arr[1][2]=='O'&&::arr[1][1]=='-'&&::arr[1][0]=='-'&&::arr[2][0]=='-'&&flag==0)
{putat('5');flag=1;}
else if(::arr[1][2]=='O'&&::arr[2][2]=='O'&&::arr[1][1]=='-'&&::arr[0][0]=='-'&&::arr[1][0]=='-'&&flag==0)
{putat('5');flag=1;}
else if(::arr[2][1]=='O'&&::arr[2][2]=='O'&&::arr[1][1]=='-'&&::arr[0][0]=='-'&&::arr[0][1]=='-'&&flag==0)
{putat('5');flag=1;}
else if(::arr[2][0]=='O'&&::arr[2][1]=='O'&&::arr[1][1]=='-'&&::arr[0][1]=='-'&&::arr[0][2]=='-'&&flag==0)
{putat('5');flag=1;}
else if(::arr[0][0]=='X'&&::arr[1][0]=='-'&&::arr[1][1]=='-'&&::arr[1][2]=='-'&&::arr[2][0]=='-'&&::arr[2][2]=='-'&&flag==0)
{putat('4');flag=1;}
else if(::arr[0][0]=='X'&&::arr[0][1]=='-'&&::arr[0][2]=='-'&&::arr[1][1]=='-'&&::arr[2][1]=='-'&&::arr[2][2]=='-'&&flag==0)
{putat('8');flag=1;}
else if(::arr[0][2]=='X'&&::arr[0][0]=='-'&&::arr[0][1]=='-'&&::arr[1][1]=='-'&&::arr[2][1]=='-'&&::arr[2][0]=='-'&&flag==0)
{putat('8');flag=1;}
else if(::arr[0][2]=='X'&&::arr[1][0]=='-'&&::arr[1][1]=='-'&&::arr[1][2]=='-'&&::arr[2][0]=='-'&&::arr[2][2]=='-'&&flag==0)
{putat('6');flag=1;}
else if(::arr[2][2]=='X'&&::arr[1][0]=='-'&&::arr[1][1]=='-'&&::arr[1][2]=='-'&&::arr[0][0]=='-'&&::arr[0][2]=='-'&&flag==0)
{putat('6');flag=1;}
else if(::arr[2][2]=='X'&&::arr[0][0]=='-'&&::arr[0][1]=='-'&&::arr[1][1]=='-'&&::arr[2][0]=='-'&&::arr[2][1]=='-'&&flag==0)
{putat('2');flag=1;}
else if(::arr[2][0]=='X'&&::arr[0][2]=='-'&&::arr[0][1]=='-'&&::arr[1][1]=='-'&&::arr[2][1]=='-'&&::arr[2][2]=='-'&&flag==0)
{putat('2');flag=1;}
else if(::arr[2][0]=='X'&&::arr[0][0]=='-'&&::arr[0][2]=='-'&&::arr[1][0]=='-'&&::arr[1][1]=='-'&&::arr[1][2]=='-'&&flag==0)
{putat('4');flag=1;}
else if(::arr[0][0]=='O'&&::arr[2][0]=='O'&&flag==0)
{
if((::arr[0][2]=='-')&&((::arr[0][1]=='-'&&::arr[1][0]=='-')||
(::arr[1][0]=='-'&&::arr[1][1]=='-')||(::arr[0][1]=='-'&&::arr[1][1]=='-'))&&flag==0)
{putat('8');flag=1;}
else if((::arr[2][2]=='-')&&((::arr[1][0]=='-'&&::arr[2][1])||
(::arr[1][1]=='-'&&::arr[2][1]=='-')||(::arr[1][1]=='-'&&::arr[1][0]=='-'))&&flag==0)
{putat('2');flag=1;}
}
else if(::arr[0][0]=='O'&&::arr[0][2]=='O'&&flag==0)
{
if((::arr[2][2]=='-')&&((::arr[1][1]=='-'&&::arr[1][2]=='-')||
(::arr[1][1]=='-'&&::arr[2][1]=='-')||(::arr[2][1]=='-'&&::arr[1][2]=='-'))&&flag==0)
{putat('2');flag=1;}
if((::arr[2][0]=='-')&&((::arr[1][1]=='-'&&::arr[0][1]=='-')||
(::arr[1][1]=='-'&&::arr[1][0]=='-')||(::arr[1][0]=='-'&&::arr[0][1]=='-'))&&flag==0)
{putat('4');flag=1;}
}
else if(::arr[0][2]=='O'&&::arr[2][2]=='O'&&flag==0)
{
if((::arr[0][0]=='-')&&((::arr[1][1]=='-'&&::arr[0][1]=='-')||
(::arr[1][1]=='-'&&::arr[1][2]=='-')||(::arr[0][1]=='-'&&::arr[1][2]=='-'))&&flag==0)
{putat('6');flag=1;}
if((::arr[2][0]=='-')&&((::arr[1][1]=='-'&&::arr[1][2]=='-')||
(::arr[1][1]=='-'&&::arr[2][1]=='-')||(::arr[1][2]=='-'&&::arr[2][1]=='-'))&&flag==0)
{putat('4');flag=1;}
}
else if(::arr[2][0]=='O'&&::arr[2][2]=='O'&&flag==0)
{
if((::arr[0][0]=='-')&&((::arr[1][1]=='-'&&::arr[1][0]=='-')||
(::arr[1][1]=='-'&&::arr[2][1]=='-')||(::arr[1][0]=='-'&&::arr[2][1]=='-'))&&flag==0)
{putat('6');flag=1;}
if((::arr[0][2]=='-')&&((::arr[1][1]=='-'&&::arr[1][2]=='-')||
(::arr[1][1]=='-'&&::arr[2][1]=='-')||(::arr[1][2]=='-'&&::arr[2][1]=='-'))&&flag==0)
{putat('8');flag=1;}
}
else if(::arr[0][0]=='O'&&::arr[2][2]=='O'&&flag==0)
{
if((::arr[0][2]=='-')&&((::arr[1][1]=='-'&&::arr[0][1]=='-')||
(::arr[1][1]=='-'&&::arr[1][2]=='-')||(::arr[0][1]=='-'&&::arr[1][2]=='-'))&&flag==0)
{putat('8');flag=1;}
if((::arr[2][0]=='-')&&((::arr[1][1]=='-'&&::arr[1][0]=='-')||
(::arr[1][1]=='-'&&::arr[2][1]=='-')||(::arr[1][0]=='-'&&::arr[2][1]=='-'))&&flag==0)
{putat('4');flag=1;}
}
else if(::arr[0][2]=='O'&&::arr[2][0]=='O'&&flag==0)
{
if((::arr[0][0]=='-')&&((::arr[1][1]=='-'&&::arr[0][1]=='-')||
(::arr[1][1]=='-'&&::arr[1][0]=='-')||(::arr[0][1]=='-'&&::arr[1][0]=='-'))&&flag==0)
{putat('8');flag=1;}
if((::arr[2][2]=='-')&&((::arr[1][1]=='-'&&::arr[1][2]=='-')||
(::arr[1][1]=='-'&&::arr[2][1]=='-')||(::arr[1][2]=='-'&&::arr[2][1]=='-'))&&flag==0)
{putat('6');flag=1;}
}
if(::arr[1][1]=='-'&&flag==0)
{putat('5');flag=1;}
if(::arr[0][0]=='-'&&flag==0)
{putat('7');flag=1;}
if(::arr[0][2]=='-'&&flag==0)
{putat('9');flag=1;}
if(::arr[2][0]=='-'&&flag==0)
{putat('1');flag=1;}
if(::arr[2][2]=='-'&&flag==0)
{putat('3');flag=1;}
if(::arr[1][0]=='-'&&flag==0)
{putat('4');flag=1;}
if(::arr[0][1]=='-'&&flag==0)
{putat('8');flag=1;}
if(::arr[2][1]=='-'&&flag==0)
{putat('2');flag=1;}
}
}
No comments :
Post a Comment