GREYcells Tic-Tac-Toe
/************************************************************************/
/* Designed & developed by J.V.RAVICHANDRAN. */
/* Started on 02/10/1997. */
/* Author's name -- J.V.RAVICHANDRAN */
/* Company's name -- Semantix Computers. */
/* Company's address -- B-10, Triveni Apartments, */
/* Vikas puri, New Delhi - 110018. */
/* Completed on -- 10th October, 1997. */
/* Name of software -- GREYcells Tic-tac-toe */
/* Nature of software -- Game */
/************************************************************************/
#include <\tc\library\graphics.h>
#include <\tc\library\process.h>
#include <\tc\library\io.h>
#include <\tc\library\dos.h>
#include <\tc\library\conio.h>
#include <\tc\library\string.h>
#include <\tc\library\stdlib.h>
#include <\tc\library\stdio.h>
#include <\tc\library\alloc.h>
#include <\tc\library\fcntl.h>
#include <\tc\library\stat.h>
#define ALT 1
#define ASCII 1
int gdriver = VGA, gmode=VGAHI, err_code,time_spent=0,boardvisible=0,counter=0;
int nkey,ikey,key,ik=1,boxrr=150,boxcc=175,boxr=125,boxc=150,ctr=0,cx=125,rx=25,start=0;
int player=0,color=15,ir,once=0,entered=1,rctr,menuflag;
int playertype1=0, playertype2=0,checkxflag=0,checkoflag=0,length,handle,handl;
int checkxflag,checkoflag,checkx1flag,checko1flag,menuitem=0,firsttime=0;
char str,firstletter,secondletter;
int playerno1=0, playerno2=0, err_flag=0,gameover=0,checkflag=0,once;
int menucol,menurow,menucoll,menuroww,item,player1lastcounter=10,player2lastcounter=0;
int messageboxc,messageboxr,messageboxcc,messageboxrr,rctr=0;
void *sbox;
int sctr=0,bctr=0,count,counter,lastcount,lastcounter;
int menuon=0,lastrctr,menuerror=0,sharecounter=0;
unsigned size;
int oxx1,oxx2,oxx3,oxx4,oxx5,oxx6,oxx7,oxx8,oxx9;
int letter3=0,letter4=1,winflag=0;
char *box[9],*playername[20];
int letter1, letter2,letter;
char score1,score2;
int soundon=1,incolor=12,soundctr,lettercolor=15,ct,midx,mee=0;
char terminator,leng,newstr;
main(){
initgraph(&gdriver, &gmode, "");
err_code = graphresult();
if (err_code !=grOk)
{
printf("Graphic initialization error...\n");
time_spent=0;
while (time_spent<50){
time_spent++;
delay(25);}
exit(0);
}
ct=access("delaytic.$$$",0);
if (ct==-1){
_fmode=O_BINARY;
handle=_creat("delaytic.$$$", FA_HIDDEN);
lseek(handle, 0L, SEEK_SET);
counter=1;
sprintf(&terminator,"%d",counter);
_write(handle,&terminator,4);}
ct=access("termtic.$$$",0);
if (ct==-1){
setfillstyle(SOLID_FILL,15);
bar(100,100,400,200);
setfillstyle(SOLID_FILL,0);
bar(101,101,399,120);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
setcolor(15);
outtextxy(220,111,"GREYcells");
setcolor(0);
outtextxy(110,135,"Intruder alert ! Please contact");
outtextxy(110,150,"the developer immediately.");
sound(100);
delay(75);
nosound();
getch();
cleardevice();
closegraph();
_close(handle);
exit(0);
ik=1;}
if (ct==0){
handle=open("termtic.$$$", O_RDONLY | O_BINARY);
lseek(handle, 0L, SEEK_SET);
counter=0;
leng=filelength(handle);
sscanf(&terminator,"%d",&leng);
while (!eof(handle)){
read(handle,&terminator,4);}
}
chmod("termtic.$$$",S_IWRITE);
unlink("termtic.$$$");
_fmode=O_BINARY;
handle=_creat("termtic.$$$", FA_HIDDEN);
lseek(handle, 0L, SEEK_SET);
sscanf(&terminator,"%d",&counter);
counter++;
sprintf(&terminator,"%d",counter);
_write(handle,&terminator,4);
if (counter<28){
ik=0;}
if (counter>28){
sound(100);
delay(25);
sound(150);
delay(25);
sound(125);
delay(25);
nosound();
alertformoney();
getch();
cleardevice();
chmod("termtic.$$$",S_IREAD);
_close(handle);
ik=0;
sharecounter=1;}
if (ik<1){
firstscreen();
menu();
cx=400;
rx=250;
color=15;}
while (ik<1){
key=getch();
switch(key){
case 32:
if (menuon==2 && item==1){
sound(100);
delay(50);
nosound();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(1,1);
setcolor(15);
soundon++;
if (soundon>1){
soundon=0;}
if (soundon==1){
setcolor(7);
outtextxy(menucol+75,menurow+13,"Sound ( OFF )");
setcolor(15);
outtextxy(menucol+75,menurow+13,"Sound ( ON )");}
if (soundon==0){
setcolor(7);
outtextxy(menucol+75,menurow+13,"Sound ( ON )");
setcolor(15);
outtextxy(menucol+75,menurow+13,"Sound ( OFF )");}
}
break;
case ALT==1:
case 129:
if (menuon==0){
menucol=15;
menurow=14;
menucoll=164;
menuroww=57;
messageboxc=menucol;
messageboxr=menurow;
messageboxcc=menucoll;
messageboxrr=menuroww;
savebox();
dropdownmenu();
setcolor(12);
settextstyle(DEFAULT_FONT,VERT_DIR,1);
settextjustify(0,1);
outtextxy(20,11,"0");
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(1,1);
setcolor(8);
if (soundon==1){
outtextxy(menucol+75,menurow+13,"Sound ( ON )");}
if (soundon==0){
outtextxy(menucol+75,menurow+13,"Sound ( OFF )");}
outtextxy(menucol+75,menurow+33,"Levels (1-3)");
item=0;
menuon=2;}
break;
case 35:
if (menuon==0){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
cx=120;
setcolor(12);
outtextxy(cx,43,"H");
setcolor(15);
cx+=textwidth("H");
cx=cx+1;
outtextxy(cx,43,"elp");
menuitem=2;
menuflag=0;
menuon=1;}
break;
case 34:
if (menuon==0){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
cx=20;
setcolor(12);
outtextxy(cx,43,"G");
cx+=textwidth("G");
cx=cx+1;
setcolor(15);
outtextxy(cx,43,"ame");
menuitem=1;
menuflag=0;
menuon=1;}
break;
case 27:
if (menuon==2){
restorebox();
setcolor(7);
settextstyle(DEFAULT_FONT,VERT_DIR,1);
settextjustify(0,1);
outtextxy(20,11,"0");
menuon=0;}
if (menuon==0){
sound(50);
delay(50);
nosound();}
if (menuon==1 && menuflag==1 && menuitem==1){
restorebox();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
cx=20;
setcolor(15);
outtextxy(cx,43,"G");
cx+=textwidth("G");
cx=cx+1;
setcolor(7);
outtextxy(cx,43,"ame");
menuon=0;
menuflag=0;
item=0;
menuitem=1;
}
if (menuon==1 && menuflag==1 && menuitem==2){
restorebox();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
cx=120;
setcolor(15);
outtextxy(cx,43,"H");
setcolor(7);
cx+=textwidth("H");
cx=cx+1;
outtextxy(cx,43,"elp");
menuon=0;
menuflag=0;
menuitem=1;
item=0;
}
break;
case 75:
if (start==4 && menuon==0){
/* left arrow */
boxoff();
if (boxc>150){
boxc=boxc-100;
boxcc=boxcc-100;}
if (boxc<150){
boxc=150;
boxcc=175;}
boxon();}
break;
case 77:
/* right arrow */
if (start==4 && menuon==0){
boxoff();
if (boxc==150){
ctr=0;
boxc=210;
boxcc=235;}
if (boxcc<420 && ctr>0){
boxc=boxc+100;
boxcc=boxcc+100;}
boxon();
}
ctr++;
break;
case 80:
if (menuon==2){
if (item==0){
threed_menu();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(1,1);
if (soundon==1){
setcolor(7);
outtextxy(menucol+75,menurow+13,"Sound ( OFF )");
setcolor(15);
outtextxy(menucol+75,menurow+13,"Sound ( ON )");}
if (soundon==0){
setcolor(7);
outtextxy(menucol+75,menurow+13,"Sound ( ON )");
setcolor(15);
outtextxy(menucol+75,menurow+13,"Sound ( OFF )");}
}
if (item==1){
twod_menu();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(1,1);
setcolor(8);
if (soundon==1){
outtextxy(menucol+75,menurow+13,"Sound ( ON )");}
if (soundon==0){
outtextxy(menucol+75,menurow+13,"Sound ( OFF )");}
setlinestyle(SOLID_LINE,1,1);
threed_menuitem2();
setcolor(15);
outtextxy(menucol+75,menurow+33,"Levels (1-3)");}
if (item==2){
twod_menuitem2();
setcolor(8);
outtextxy(menucol+75,menurow+33,"Levels (1-3)");}
sound(20);
delay(75);
nosound();
item++;
if (item==3){
item=0;}
}
if (menuon==1 && menuflag==1 && menuitem==1){
if (item==0){
threed_menu();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(1,1);
setcolor(15);
outtextxy(menucol+50,menurow+13,"Start");}
if (item==1){
twod_menu();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(1,1);
setcolor(8);
outtextxy(menucol+50,menurow+13,"Start");
setlinestyle(SOLID_LINE,1,1);
threed_menuitem2();
setcolor(15);
outtextxy(menucol+50,menurow+33,"Quit");}
if (item==2){
twod_menuitem2();
setcolor(8);
outtextxy(menucol+50,menurow+33,"Quit");}
sound(20);
delay(75);
nosound();
item++;
if (item==3){
item=0;}
}
if (menuon==1 && menuflag==1 && menuitem==2){
if (item==0){
threed_menu();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(1,1);
setcolor(15);
outtextxy(menucol+75,menurow+13,"How to use...");}
if (item==1){
twod_menu();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(1,1);
setcolor(8);
outtextxy(menucol+75,menurow+13,"How to use...");
setlinestyle(SOLID_LINE,1,1);
threed_menuitem2();
setcolor(15);
outtextxy(menucol+70,menurow+33,"About");}
if (item==2){
twod_menuitem2();
setcolor(8);
outtextxy(menucol+70,menurow+33,"About");}
sound(20);
delay(75);
nosound();
item++;
if (item==3){
item=0;}
}
if (menuon==1 && menuitem==1 && menuflag==0){
menucol=20;
menurow=48;
menucoll=120;
menuroww=91;
messageboxc=menucol;
messageboxr=menurow;
messageboxcc=menucoll;
messageboxrr=menuroww;
savebox();
dropdownmenu();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(1,1);
setcolor(8);
outtextxy(menucol+50,menurow+13,"Start");
outtextxy(menucol+50,menurow+33,"Quit");
item=0;
menuflag=1;}
if (menuon==1 && menuitem==2 && menuflag==0){
menucol=120;
menurow=48;
menucoll=259;
menuroww=91;
messageboxc=menucol;
messageboxr=menurow;
messageboxcc=menucoll;
messageboxrr=menuroww;
savebox();
dropdownmenu();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(1,1);
setcolor(8);
outtextxy(menucol+75,menurow+13,"How to use...");
outtextxy(menucol+70,menurow+33,"About");
item=0;
menuflag=1;}
if (start==4 && menuon==0){
if (boxc>150){
boxoff();
if (boxrr<320){
boxr=boxr+85;
boxrr=boxrr+85;}
}
boxon();
}
break;
case 72:
if (start==4 && menuon==0){
boxoff();
if (boxr>150){
boxr=boxr-85;
boxrr=boxrr-85;
}
boxon();}
break;
case 88:
/* caps x */
if (start==4 && checkxflag==0 && menuon==0){
checkflag=1;
boxoff();
mee=2;
error();
if (gameover==-1){gameover=0;checkxflag=0;}
checkflag=0;}
if (start==4 && checkxflag==1 && menuon==0){
boxoff();
if (playertype1==1 || playertype2==1){
if (winflag==0){
scanboxes();
setstatus();
boxrr=150;
boxcc=175;
boxr=125;
boxc=150;
boxon();}}
if (winflag==0 && err_flag==0){
setplayer();}
if (winflag==1 && err_flag==0){
start=5;}
}
if (playertype2==2 && winflag==0 && err_flag==0){
once=0;
computer_o();
writectext();
if (once==2){display_win();}
boxrr=150;
boxcc=175;
boxr=125;
boxc=150;
boxon();
if (winflag==0 && err_flag==0){
setplayer();}
if (winflag==1 && err_flag==0){
start=5;}}
if (entered>=9 && winflag==0 && gameover==0){
gameover=1;
error();
start=5;}
break;
case 79:
/* caps O*/
if (start==4 && checkoflag==0 && menuon==0){
checkflag=1;
boxoff();
mee=2;
error();
checkflag=0;}
if (start==4 && checkoflag==1 && menuon==0){
boxoff();
if (playertype1==1 || playertype2==1){
if (winflag==0){
scanboxes();
setstatus();
boxrr=150;
boxcc=175;
boxr=125;
boxc=150;
boxon();}}
if (winflag==0 && err_flag==0){
setplayer();}
if (winflag==1 && err_flag==0){
start=5;}
}
if (playertype2==2 && winflag==0){
once=0;
computer_o();
writeotext();
if (once==2){display_win();}
boxrr=150;
boxcc=175;
boxr=125;
boxc=150;
boxon();
if (winflag==0 && err_flag==0){
setplayer();}
if (winflag==1 && err_flag==0){
start=5;}}
if (entered>=9 && winflag==0 && gameover==0){
gameover=1;
error();
start=5;}
break;
case 13:
if (menuon==1 && menuitem==1){
restorebox();
if (item==0){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
cx=20;
setcolor(15);
outtextxy(cx,43,"G");
cx+=textwidth("G");
cx=cx+1;
setcolor(7);
outtextxy(cx,43,"ame");}
if (item==1){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
cx=20;
setcolor(15);
outtextxy(cx,43,"G");
cx+=textwidth("G");
cx=cx+1;
setcolor(7);
outtextxy(cx,43,"ame");
gameover=0;
clearboard();
boxrr=150;
boxcc=175;
boxr=125;
boxc=150;
ctr=1;
while (ctr<10){strcpy(&box[ctr],"2");ctr++;}
ctr=1;
entered=2;
setplayer();
entered=1;
player=1;
if (letter1==1){
checkxflag=1;
lettercolor=15;
checkoflag=0;}
if (letter1==2){
checkxflag=0;
lettercolor=12;
checkoflag=1;}
start=4;
item=0;
menuflag=0;
winflag=0;}
if (item==2){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
cx=20;
setcolor(15);
outtextxy(cx,43,"G");
cx+=textwidth("G");
cx=cx+1;
setcolor(7);
outtextxy(cx,43,"ame");
quit();
ik=1;
}
menuon=0;}
if (menuon==1 && menuitem==2){
restorebox();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
cx=120;
setcolor(15);
outtextxy(cx,43,"H");
setcolor(7);
cx+=textwidth("H");
cx=cx+1;
outtextxy(cx,43,"elp");
if (item==0){
sound(200);
delay(25);
nosound();}
if (item==1){
howtouse();}
if (item==2){
about();}
menuon=0;}
if (menuon==2){
restorebox();
setcolor(7);
settextstyle(DEFAULT_FONT,VERT_DIR,1);
settextjustify(0,1);
outtextxy(20,11,"0");
if (item==2){
shareware();}
menuon=0;}
break;
}
}
cleardevice();
closegraph();
return 0;}
int scanboxes(){
sscanf(&box[1],"%d",&oxx1);
sscanf(&box[2],"%d",&oxx2);
sscanf(&box[3],"%d",&oxx3);
sscanf(&box[4],"%d",&oxx4);
sscanf(&box[7],"%d",&oxx7);
sscanf(&box[5],"%d",&oxx5);
sscanf(&box[6],"%d",&oxx6);
sscanf(&box[8],"%d",&oxx8);
sscanf(&box[9],"%d",&oxx9);
return 1;}
int computer_o(){
scanboxes();
if (entered==2){
if (oxx5==2 && once==0){
/* capture box5 */
boxfive();
once=1;}
if (oxx5==0 && once==0){
if (oxx1==2){
/* capture box1 */
boxone();}
once=1;}
}
if (entered==4 || entered==5){
defensivemoves();
if (once==0){
firstoffence();}
}
if (entered>5){
if (once==0){
offensivemoves();}
if (once==0){
defensivemoves();}
if (once==0){
firstoffence();}
}
if (once!=0){writeforcomputer();scanboxes();checkcomputerwin();}
return (once);}
int firstoffence(){
/* offensive moves for computer*/
if (oxx1==1 && oxx2==2 && once==0){
boxtwo();once=1;}
if (oxx1==1 && oxx3==2 && once==0){
boxthree();once=1;}
if (oxx5==1 && oxx2==2 && once==0){
boxtwo();once=1;}
if (oxx5==1 && oxx3==2 && once==0){
boxthree();once=1;}
if (oxx5==1 && oxx4==2 && once==0){
boxfour();once=1;}
if (oxx5==1 && oxx6==2 && once==0){
boxsix();once=1;}
if (oxx5==1 && oxx9==2 && once==0){
boxnine();once=1;}
if (oxx5==1 && oxx7==2 && once==0){
boxseven();once=1;}
if (oxx1==1 && oxx4==2 && once==0){
boxfour();once=1;}
if (oxx1==1 && oxx7==2 && once==0){
boxseven();once=1;}
if (oxx1==1 && oxx9==2 && once==0){
boxnine();once=1;}
if (oxx1==1 && oxx5==2 && once==0){
boxfive();once=1;}
return (once);}
int offensivemoves(){
/* offensive moves for computer*/
if (oxx1==1 && oxx2==1 && oxx3==2 && once==0){
boxthree();once=2;}
if (oxx1==1 && oxx4==1 && oxx7==2 && once==0){
boxseven();once=2;}
if (oxx1==1 && oxx7==1 && oxx4==2 && once==0){
boxfour();once=2;}
if (oxx1==1 && oxx9==1 && oxx5==2 && once==0){
boxfive();once=2;}
if (oxx2==1 && oxx3==1 && oxx1==2 && once==0){
boxone();once=2;}
if (oxx1==1 && oxx3==1 && oxx2==2 && once==0){
boxtwo();once=2;}
if (oxx4==1 && oxx7==1 && oxx1==2 && once==0){
boxone();once=2;}
if (oxx2==1 && oxx5==1 && oxx8==2 && once==0){
boxeight();once=2;}
if (oxx2==1 && oxx8==1 && oxx5==2 && once==0){
boxfive();once=2;}
if (oxx5==1 && oxx8==1 && oxx2==2 && once==0){
boxtwo();once=2;}
if (oxx3==1 && oxx6==1 && oxx9==2 && once==0){
boxnine();once=2;}
if (oxx6==1 && oxx9==1 && oxx3==2 && once==0){
boxthree();once=2;}
if (oxx3==1 && oxx9==1 && oxx6==2 && once==0){
boxsix();once=2;}
if (oxx4==1 && oxx5==1 && oxx6==2 && once==0){
boxsix();once=2;}
if (oxx5==1 && oxx6==1 && oxx4==2 && once==0){
boxfour();once=2;}
if (oxx4==1 && oxx6==1 && oxx5==2 && once==0){
boxfive();once=2;}
if (oxx7==1 && oxx8==1 && oxx9==2 && once==0){
boxnine();once=2;}
if (oxx7==1 && oxx9==1 && oxx8==2 && once==0){
boxeight();once=2;}
if (oxx8==1 && oxx9==1 && oxx7==2 && once==0){
boxseven();once=2;}
if (oxx1==1 && oxx5==1 && oxx9==2 && once==0){
boxnine();once=2;}
if (oxx5==1 && oxx9==1 && oxx1==2 && once==0){
boxone();once=2;}
if (oxx1==1 && oxx9==1 && oxx5==2 && once==0){
boxfive();once=2;}
if (oxx3==1 && oxx5==1 && oxx7==2 && once==0){
boxseven();once=2;}
if (oxx3==1 && oxx7==1 && oxx5==2 && once==0){
boxfive();once=2;}
if (oxx7==1 && oxx5==1 && oxx3==2 && once==0){
boxthree();once=2;}
return (once);}
int defensivemoves(){
/* Defensive moves for computer*/
if (oxx7==0 && oxx4==0 && oxx1==2 && once==0){
boxone();once=1;}
if (oxx1==0 && oxx2==0 && oxx3==2 && once==0){
boxthree();once=1;}
if (oxx5==0 && oxx3==0 && oxx7==2 && once==0){
boxseven();once=1;}
if (oxx5==0 && oxx7==0 && oxx3==2 && once==0){
boxthree();once=1;}
if (oxx1==0 && oxx4==0 && oxx7==2 && once==0){
boxseven();once=1;}
if (oxx1==0 && oxx7==0 && oxx4==2 && once==0){
boxfour();once=1;}
if (oxx3==0 && oxx7==0 && oxx5==2 && once==0){
boxfive();once=1;}
if (oxx2==0 && oxx5==0 && oxx8==2 && once==0){
boxeight();once=1;}
if (oxx2==0 && oxx3==0 && oxx1==2 && once==0){
boxone();once=1;}
if (oxx2==0 && oxx8==0 && oxx5==2 && once==0){
boxfive();once=1;}
if (oxx5==0 && oxx8==0 && oxx2==2 && once==0){
boxtwo();once=1;}
if (oxx3==0 && oxx6==0 && oxx9==2 && once==0){
boxnine();once=1;}
if (oxx3==0 && oxx9==0 && oxx6==2 && once==0){
boxsix();once=1;}
if (oxx6==0 && oxx9==0 && oxx3==2 && once==0){
boxthree();once=1;}
if (oxx4==0 && oxx5==0 && oxx6==2 && once==0){
boxsix();once=1;}
if (oxx4==0 && oxx6==0 && oxx5==2 && once==0){
boxfive();once=1;}
if (oxx6==0 && oxx5==0 && oxx4==2 && once==0){
boxfour();once=1;}
if (oxx7==0 && oxx8==0 && oxx9==2 && once==0){
boxnine();once=1;}
if (oxx7==0 && oxx9==0 && oxx8==2 && once==0){
boxeight();once=1;}
if (oxx9==0 && oxx8==0 && oxx7==2 && once==0){
boxseven();once=1;}
return (once);}
int drawboard(){
setfillstyle(SOLID_FILL,8);
bar(0,0,640,480);
setlinestyle(SOLID_LINE,1,1);
setcolor(15);
line(5,50,634,50);
setcolor(0);
line(4,21,4,480);
line(0,475,640,475);
line(636,21,636,480);
setfillstyle(SOLID_FILL,0);
bar(1,1,639,20);
setcolor(15);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
outtextxy(290,12,"Tic-tac-toe");
setcolor(7);
settextstyle(DEFAULT_FONT,VERT_DIR,1);
settextjustify(0,1);
outtextxy(20,11,"0");
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
cx=20;
setcolor(15);
outtextxy(cx,43,"G");
cx+=textwidth("G");
cx=cx+1;
setcolor(7);
outtextxy(cx,43,"ame");
cx=120;
setcolor(15);
outtextxy(cx,43,"H");
setcolor(7);
cx+=textwidth("H");
cx=cx+1;
outtextxy(cx,43,"elp");
outtextxy(420,27,"Player -");
outtextxy(420,43,"Score -");
outtextxy(45,450,"Player 1 -");
outtextxy(45,465,"Score -");
outtextxy(445,450,"Player 2 -");
outtextxy(445,465,"Score -");
setcolor(15);
/* board */
setlinestyle(SOLID_LINE,1,3);
setcolor(15);
line(200,175,450,175);
line(200,275,450,275);
line(275,100,275,350);
line(375,100,375,350);
setfillstyle(SOLID_FILL,8);
bar(520,23,625,47);
setcolor(15);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
counter=0;
cx=495;
while (counter<player1lastcounter){
outtextxy(cx,27,&playername[counter]);
cx+=textwidth(&playername[counter]);
counter++;}
setcolor(12);
outtextxy(285,460,"LEVEL -");
setcolor(15);
if (playertype1==1){
outtextxy(140,450,"HUMAN");}
if (playertype1==2){
outtextxy(140,450,"COMPUTER");}
if (playertype2==1){
outtextxy(535,450,"HUMAN");
outtextxy(355,460," ");}
if (playertype2==2){
outtextxy(535,450,"COMPUTER");
outtextxy(355,460,"3");}
if (letter1==1){
lettercolor=15;}
if (letter1==2){
lettercolor=12;}
boardvisible=1;
entered=1;
player=1;
if (letter1==1){
checkxflag=1;
lettercolor=15;
checkoflag=0;}
if (letter1==2){
checkxflag=0;
lettercolor=12;
checkoflag=1;}
gameover=0;
checkflag=0;
boxrr=150;
boxcc=175;
boxr=125;
boxc=150;
boxon();
setcolor(15);
outtextxy(510,45,&score1);
ctr=1;
while (ctr<10){strcpy(&box[ctr],"2");ctr++;}
ctr=1;
return 1;}
int boxoff(){
if (boxc==150){
setfillstyle(SOLID_FILL,8);
bar(boxc,boxr,boxcc,boxrr);}
if (boxc>150){
setlinestyle(SOLID_LINE,1,1);
setcolor(8);
line(boxc,boxr,boxcc+5,boxr);
line(boxc,boxr,boxc,boxrr);
line(boxc,boxrr,boxcc+5,boxrr);
line(boxcc+5,boxr,boxcc+5,boxrr);}
return 1;}
int boxon(){
if (boxc==150){
setfillstyle(SOLID_FILL,15);
bar(boxc,boxr,boxcc,boxrr);
setfillstyle(SOLID_FILL,0);
bar(boxc+1,boxr+1,boxcc-1,boxrr-1);}
if (boxc>150){
setlinestyle(SOLID_LINE,1,1);
setcolor(15);
line(boxc,boxr,boxcc+5,boxr);
line(boxc,boxr,boxc,boxrr);
line(boxc,boxrr,boxcc+5,boxrr);
line(boxcc+5,boxr,boxcc+5,boxrr);
}
return 1;}
int clearboard(){
setfillstyle(SOLID_FILL,8);
bar(25,100,575,400);
boardvisible=0;
/* board */
setlinestyle(SOLID_LINE,1,3);
setcolor(15);
line(200,175,450,175);
line(200,275,450,275);
line(275,100,275,350);
line(375,100,375,350);
boardvisible=1;
entered=1;
player=1;
gameover=0;
checkflag=0;
boxrr=150;
boxcc=175;
boxr=125;
boxc=150;
boxon();
setfillstyle(SOLID_FILL,8);
bar(520,23,625,47);
setcolor(15);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
counter=0;
cx=525;
while (counter<player1lastcounter){
outtextxy(cx,27,&playername[counter]);
cx+=textwidth(&playername[counter]);
counter++;}
outtextxy(525,45,&score1);
return 1;}
int name(){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
while (entered!=2){
nkey=getch();
switch(nkey){
case 59:
if (rx==322 || rx==346 || rx==325 || rx==350){
messageboxc=125;
messageboxr=125;
messageboxcc=525;
messageboxrr=225;
midx=295;
savebox();
errorscreen();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
setusercharsize(1,3,1,1);
settextjustify(0,1);
setcolor(12);
outtextxy(messageboxc+5,messageboxr+5,"Help");
playernamehelp();
rctr=0;
getch();
restorebox();
}
break;
case 8:
if (rx==325 || rx==322){
if (rctr>0){
rctr--;}
if (rctr==0){
rctr=0;}}
if (rx==350){
if (rctr>player1lastcounter){
rctr--;}}
curs_off();
cx-=textwidth(&nkey);
setfillstyle(SOLID_FILL,8);
bar(cx,rx-10,cx+10,rx+10);
if (cx<=250){
cx=250;}
curs_on();
break;
case 13:
if (playertype1==1 && playertype2==1 && rctr==0){
messageboxc=125;
messageboxr=125;
messageboxcc=450;
messageboxrr=200;
midx=265;
sound(100);
delay(75);
nosound();
savebox();
errorscreen();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
setusercharsize(1,3,1,1);
settextjustify(0,1);
setcolor(12);
outtextxy(messageboxc+5,messageboxr+5,"Error");
setcolor(0);
outtextxy(messageboxc+5,messageboxr+35,"Mandatory to enter a name.");
getch();
restorebox();
rctr=0;
curs_off();
if (rx==325 || rx==322){
cx=250;
rx=322;
curs_on();}
if (rx==350 || rx==346){
cx=250;
rx=346;
curs_on();}
err_flag=1;}
if (playertype1==2 && playertype2==1 && rctr>0){
curs_off();
rctr=0;
cx=250;
rx=350;}
if (playertype1==1 && rctr>0 && entered==1 && err_flag==0){
if (rx==325 || rx==322){
curs_off();
player1lastcounter=rctr;
if (playertype2==1){
cx=250;
rx=350;}
curs_on();
entered=0;}}
if (playertype2==2 && err_flag==0){
curs_off();
entered=2;}
if (playertype2==1 && err_flag==0 && rctr>0 && entered==1){
if (rx==346 || rx==350){
player2lastcounter=player1lastcounter+rctr;
rctr=0;
curs_off();
entered=2;}}
err_flag=0;
break;
default:
if (start==0){
if (rctr<10 && rx<350){
writename();}
if (rctr>=player1lastcounter && rctr<20 && rx==350){
writename();}
}
break;
}
}
return 1;}
int writename(){
entered=1;
err_flag=0;
curs_off();
setcolor(15);
outtextxy(cx,rx,&nkey);
cx+=textwidth(&nkey);
curs_on();
strcpy(&playername[rctr],&nkey);
rctr++;
return (rctr);}
int menu(){
drawmenuscreen();
while (once<4){
incolor++;
if (incolor>15){
incolor=1;}
setcolor(incolor);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
outtextxy(10,35,"Press <F1> for help");
outtextxy(300,13,"GREYcells");
ikey=getch();
switch(ikey){
case 59:
if (rx==50 || rx==75){
messageboxc=125;
messageboxr=125;
messageboxcc=515;
messageboxrr=250;
midx=295;
savebox();
errorscreen();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
setusercharsize(1,3,1,1);
settextjustify(0,1);
setcolor(12);
outtextxy(messageboxc+5,messageboxr+5,"Help");
scrollplayerhelp();
getch();
restorebox();
}
if (rx==250 || rx==275){
messageboxc=125;
messageboxr=125;
messageboxcc=475;
messageboxrr=275;
midx=275;
savebox();
errorscreen();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
setusercharsize(1,3,1,1);
settextjustify(0,1);
setcolor(12);
outtextxy(messageboxc+5,messageboxr+5,"Help");
playerletterhelp();
getch();
restorebox();
}
break;
case 80:
if (sharecounter==1 && rx<250){
if (ctr==0){
setfillstyle(SOLID_FILL,15);
bar(145,135,300,165);
setcolor(0);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(150,150,"Human");}
if (ctr==1){
setfillstyle(SOLID_FILL,8);
bar(145,135,300,165);
setcolor(15);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(150,150,"Human");}
ctr++;
if (ctr>1){
alertformoney();
getch();
cleardevice();
drawmenuscreen();
ctr=0;}
}
if (once<2 && sharecounter==0){
if (ctr==0){
setfillstyle(SOLID_FILL,15);
bar(145,135,300,165);
setcolor(0);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(150,150,"Human");}
if (ctr==1){
setfillstyle(SOLID_FILL,8);
bar(145,135,300,165);
setcolor(15);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(150,150,"Human");
setfillstyle(SOLID_FILL,15);
bar(145,185,300,215);
setcolor(0);
outtextxy(150,200,"Computer");}
if (ctr==2){
setfillstyle(SOLID_FILL,8);
bar(145,185,300,215);
setcolor(15);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(150,200,"Computer");
}
ctr++;
if (ctr>2){
ctr=0;}
}
break;
case 72:
if (sharecounter==1 && rx<250){
if (ctr==1){
setfillstyle(SOLID_FILL,8);
bar(145,135,300,165);
setcolor(15);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(150,150,"Human");}
ctr--;
if (ctr<=0){
ctr=0;}
}
if (once<2 && sharecounter==0){
if (ctr==1){
setfillstyle(SOLID_FILL,8);
bar(145,135,300,165);
setcolor(15);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(150,150,"Human");}
if (ctr==2){
setfillstyle(SOLID_FILL,8);
bar(145,185,300,215);
setcolor(15);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(150,200,"Computer");
setfillstyle(SOLID_FILL,15);
bar(145,135,300,165);
setcolor(0);
outtextxy(150,150,"Human");}
ctr--;
if (ctr<=0){ctr=0;}
}
break;
case 88:
/* caps x */
if (rx==250){
strcpy(&firstletter,"X");
letter1=1;
checkxflag=1;
checkoflag=0;
curs_off();
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
setcolor(15);
outtextxy(cx+15,rx+1,&ikey);
playerno1=1;
cx=425;
setcolor(12);
outtextxy(cx+15,276,"O");
strcpy(&secondletter,"O");
letter2=2;
playerno2=1;
rx=5;}
break;
case 79:
/* caps O */
if (rx==250){
strcpy(&firstletter,"O");
checkxflag=0;
checkoflag=1;
letter1=2;
curs_off();
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
setcolor(15);
outtextxy(cx+15,rx+1,&ikey);
playerno1=1;
cx=425;
setcolor(12);
outtextxy(cx+15,276,"X");
strcpy(&secondletter,"X");
letter2=1;
playerno2=1;
rx=5;}
break;
case 13:
setcolor(15);
if (ctr==0){
ctr=0;
once--;}
if (once==0 && ctr>0){
if (ctr==1){
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(cx,rx,"Human");
setfillstyle(SOLID_FILL,8);
bar(145,135,300,165);
setcolor(15);
outtextxy(150,150,"Human");
rx=rx+25;
playertype1=1;}
if (ctr==2){
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(cx,rx,"Computer");
setfillstyle(SOLID_FILL,8);
bar(145,185,300,215);
setcolor(15);
outtextxy(150,200,"Computer");
playertype1=2;}
ctr=0;
}
if (once>0 && once<2 && ctr>0){
if (ctr==1){
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(cx,rx,"Human");
playertype2=1;
player=0;}
if (ctr==2){
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(cx,rx,"Computer");
playertype2=2;
player=0;}
}
if (playertype1==2){
menuerror=2;
gameover=2;
checkflag=1;
error();
ctr=0;
once=-1;
player=1;
setfillstyle(SOLID_FILL,8);
bar(10,25,600,125);
setcolor(15);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(100,50,"Player 1:");
outtextxy(100,75,"Player 2:");
playertype1=0;
playertype2=0;
cx=225;
rx=50;}
if (playertype1==2 && playertype2==2){
menuerror=1;
gameover=2;
checkflag=1;
error();
ctr=0;
once=-1;
player=1;
setfillstyle(SOLID_FILL,0);
bar(10,10,600,125);
setcolor(15);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(100,50,"Player 1:");
outtextxy(100,75,"Player 2:");
playertype1=0;
playertype2=0;
cx=225;
rx=50;}
if (player==0){
cx=425;
rx=250;
curs_on();
player=1;
once=3;}
if (rx==5){
ctr=0;
rctr=0;
lastrctr=0;
entered=1;
if (playertype1==1){
cx=250;
rx=325;}
if (playertype1==2){
cx=250;
rx=350;}
curs_on();
start=0;
name();
curs_off();
cleardevice();
drawboard();
boxrr=150;
boxcc=175;
boxr=125;
boxc=150;
boxon();
start=4;
menuon=0;
ik=0;
rx=0;
once=4;
}
if (once<2){
once++;}
break;
}
}
return 1;}
int curs_on()
{
setfillstyle(SOLID_FILL,15);
bar(cx+2,rx-5,cx+10,rx+10);
return 1;
}
int curs_off()
{
setfillstyle(SOLID_FILL,8);
bar(cx+2,rx-5,cx+10,rx+10);
return 1;}
int dropdownmenu(){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(1,1);
setfillstyle(SOLID_FILL,15);
bar(menucol,menurow+2,menucoll,menuroww);
setfillstyle(SOLID_FILL,0);
bar(menucol+1,menurow+3,menucoll-1,menuroww-1);
setfillstyle(SOLID_FILL,7);
bar(menucol+4,menurow+5,menucoll-3,menurow+20);
bar(menucol+4,menurow+25,menucoll-3,menurow+41);
#if 0
bar(menucol+4,menurow+37,menucoll-4,menurow+53);
#endif
setlinestyle(SOLID_LINE,1,2);
setcolor(15);
line(menucol+4,menurow+5,menucoll-3,menurow+5);
line(menucol+4,menurow+5,menucol+4,menurow+20);
line(menucol+4,menurow+25,menucoll-3,menurow+25);
line(menucol+4,menurow+25,menucol+4,menurow+41);
setcolor(0);
line(menucol+4,menurow+20,menucoll-3,menurow+20);
line(menucoll-3,menurow+5,menucoll-3,menurow+20);
line(menucol+4,menurow+41,menucoll-3,menurow+41);
line(menucoll-3,menurow+25,menucoll-3,menurow+41);
/* line in between menu items */
setcolor(15);
line(menucol,menurow+22,menucoll,menurow+22);
return 1;}
int setstatus(){
switch(boxr){
case 125:
if (boxc==150){
mee=2;
error();}
if (boxc==210){
if (oxx1!=2){
mee=2;
error();}
if (oxx1==2){
writetext();}}
if (boxc==310){
if (oxx4!=2){
mee=2;
error();}
if (oxx4==2){
writetext();}
}
if (boxc==410){
if (oxx7!=2){
mee=2;
error();}
if (oxx7==2){
writetext();}
}
break;
case 210:
if (boxc==150){
mee=2;
error();}
if (boxc==210){
if (oxx2!=2){
mee=2;
error();}
if (oxx2==2){
writetext();}
}
if (boxc==310){
if (oxx5!=2){
mee=2;
error();}
if (oxx5==2){
writetext();}
}
if (boxc==410){
if (oxx8!=2){
mee=2;
error();}
if (oxx8==2){
writetext();}
}
break;
case 295:
if (boxc==150){
mee=2;
error();}
if (boxc==210){
if (oxx3!=2){
mee=2;
error();}
if (oxx3==2){
writetext();}
}
if (boxc==310){
if (oxx6!=2){
mee=2;
error();}
if (oxx6==2){
writetext();}
}
if (boxc==410){
if (oxx9!=2){
mee=2;
error();}
if (oxx9==2){
writetext();}
}
break;}
if (player==1 && playertype1==1 && winflag==0){
writeforcomputer();check_xwin();}
if (player==2 && playertype2==1 && winflag==0){
writeforcomputer();check_owin();}
return (winflag);}
int check_xwin(){
scanboxes();
if (winflag==0){
if (oxx1==0 && oxx4==0 && oxx7==0){
display_win();}
if (oxx1==0 && oxx2==0 && oxx3==0){
display_win();}
if (oxx1==0 && oxx5==0 && oxx9==0){
display_win();}
if (oxx4==0 && oxx5==0 && oxx6==0){
display_win();}
if (oxx7==0 && oxx8==0 && oxx9==0){
display_win();}
if (oxx3==0 && oxx5==0 && oxx7==0){
display_win();}
if (oxx3==0 && oxx6==0 && oxx9==0){
display_win();}
if (oxx2==0 && oxx5==0 && oxx8==0){
display_win();}
}
return (winflag);}
int check_owin(){
scanboxes();
if (winflag==0){
if (oxx1==1 && oxx4==1 && oxx7==1){
display_win();}
if (oxx1==1 && oxx2==1 && oxx3==1){
display_win();}
if (oxx1==1 && oxx5==1 && oxx9==1){
display_win();}
if (oxx4==1 && oxx5==1 && oxx6==1){
display_win();}
if (oxx7==1 && oxx8==1 && oxx9==1){
display_win();}
if (oxx3==1 && oxx5==1 && oxx7==1){
display_win();}
if (oxx3==1 && oxx6==1 && oxx9==1){
display_win();}
if (oxx2==1 && oxx5==1 && oxx8==1){
display_win();}
}
return (winflag);}
int writetext(){
boxoff();
setcolor(lettercolor);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(boxcc-15,boxrr-15,&key);
err_flag=0;
return (err_flag);}
int writectext(){
boxoff();
setcolor(lettercolor);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(boxcc-15,boxrr-15,"O");
err_flag=0;
return (err_flag);}
int writeotext(){
boxoff();
setcolor(lettercolor);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(boxcc-15,boxrr-15,"X");
err_flag=0;
return (err_flag);}
int error(){
messageboxc=150;
messageboxr=173;
messageboxcc=500;
messageboxrr=300;
savebox();
midx=295;
errorscreen();
if (mee==1){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
setusercharsize(1,3,1,1);
settextjustify(0,1);
setcolor(4);
outtextxy(messageboxc+5,messageboxr+5,"Game");}
if (mee==2){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
setusercharsize(1,3,1,1);
settextjustify(0,1);
setcolor(4);
outtextxy(messageboxc+5,messageboxr+5,"Error");}
if (soundon==1){
sound(275);
delay(150);
sound(375);
delay(250);
nosound();}
if (menuerror==1){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
setcolor(1);
outtextxy(messageboxc+15,messageboxr+40,"Computer cannot");
outtextxy(messageboxc+15,messageboxr+55,"play from both sides !");
gameover=3;
menuerror=0;}
if (menuerror==2){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
setcolor(1);
outtextxy(messageboxc+10,messageboxr+40,"Computer cannot play the first move in");
outtextxy(messageboxc+10,messageboxr+55,"this version. This feature will be");
outtextxy(messageboxc+10,messageboxr+70,"provided in the next version of the");
outtextxy(messageboxc+10,messageboxr+85,"software !");
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
gameover=3;
menuerror=0;}
if (gameover==0 && checkflag==1){
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
if (player==1){
letter=letter1;
counter=0;
cx=messageboxc+15;
while (counter<player1lastcounter){
setcolor(4);
outtextxy(cx,messageboxr+50,&playername[counter]);
cx+=textwidth(&playername[counter]);
counter++;}
outtextxy(cx+20,messageboxr+50,"!");
cx=messageboxc+15;
outtextxy(cx,messageboxr+85,"Your letter is");
cx=cx+175;
if (letter==1){
outtextxy(cx,messageboxr+85,"X");}
if (letter==2){
outtextxy(cx,messageboxr+85,"O");}
outtextxy(cx+25,messageboxr+85,"!");}
if (player==2){
letter=letter2;
count=player1lastcounter;
cx=messageboxc+15;
while (count<player2lastcounter){
setcolor(4);
outtextxy(cx,messageboxr+50,&playername[count]);
cx+=textwidth(&playername[count]);
count++;}
outtextxy(cx+20,messageboxr+50,"!");
cx=messageboxc+15;
outtextxy(cx,messageboxr+85,"Your letter is");
cx=cx+175;
if (letter==1){
outtextxy(cx,messageboxr+85,"X");}
if (letter==2){
outtextxy(cx,messageboxr+85,"O");}
outtextxy(cx+25,messageboxr+85,"!");}
gameover=-1;}
if (gameover==0 && checkflag==0){
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
setcolor(4);
outtextxy(messageboxc+100,messageboxr+45,"Invalid entry !");
outtextxy(messageboxc+100,messageboxr+75,"Box occupied !");
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);}
if (gameover==1){
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
setcolor(4);
outtextxy(messageboxc+115,messageboxr+60,"Game over !");
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
entered=9;
gameover=2;}
getch();
restorebox();
if (gameover<3){
boxrr=150;
boxcc=175;
boxr=125;
boxc=150;
boxon();}
err_flag=1;
mee=0;
return (err_flag);}
int display_win(){
messageboxc=150;
messageboxr=173;
messageboxcc=500;
messageboxrr=300;
savebox();
midx=295;
if (soundon==1){
soundctr=0;
while (soundctr<10){
sound(250);
delay(50);
nosound();
sound(350);
delay(50);
nosound();
soundctr++;}}
errorscreen();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
setusercharsize(1,3,1,1);
settextjustify(0,1);
setcolor(2);
outtextxy(messageboxc+5,messageboxr+5,"Game");
if (player==1){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
setfillstyle(SOLID_FILL,8);
bar(135,455,250,470);
setcolor(8);
outtextxy(140,465,&score1);
outtextxy(495,43,&score1);
sctr++;
setcolor(2);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(messageboxc+100,messageboxr+50,"Game over !");
counter=0;
cx=messageboxc+15;
setcolor(10);
settextjustify(0,1);
if (playertype1==1){
counter=0;
while (counter<player1lastcounter){
outtextxy(cx,messageboxr+90,&playername[counter]);
cx+=textwidth(&playername[counter]);
counter++;}
cx=cx+10;}
if (playertype1==2){
outtextxy(525,27,"COMPUTER");
cx=cx+135;}
outtextxy(cx,messageboxr+90,"wins !");
setcolor(15);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
sprintf(&score1,"%d",sctr);
setcolor(15);
outtextxy(140,465,&score1);
outtextxy(495,43,&score1);}
if (player==2){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
setcolor(8);
outtextxy(535,465,&score2);
outtextxy(495,43,&score2);
bctr++;
setcolor(2);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
settextjustify(0,1);
outtextxy(messageboxc+100,messageboxr+50,"Game over !");
count=player1lastcounter;
cx=messageboxc+15;
setcolor(10);
settextjustify(0,1);
if (playertype2==1){
count=player1lastcounter;
while (count<player2lastcounter){
outtextxy(cx,messageboxr+90,&playername[count]);
cx+=textwidth(&playername[count]);
count++;}}
cx=cx+10;
if (playertype2==2){
outtextxy(cx,messageboxr+90,"COMPUTER");
cx=cx+135;}
outtextxy(cx,messageboxr+90,"wins !");
setcolor(15);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
sprintf(&score2,"%d",bctr);
setcolor(15);
outtextxy(535,465,&score2);
outtextxy(495,43,&score2);}
if (entered<9){
entered=9;}
getch();
restorebox();
boxrr=150;
boxcc=175;
boxr=125;
boxc=150;
boxon();
winflag=1;
return 1;}
int setplayer(){
if (entered==1 || entered==3 || entered==5 || entered==7 || entered==9){
setfillstyle(SOLID_FILL,8);
bar(490,23,635,48);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
setcolor(15);
if (playertype2==1){
count=player1lastcounter;
cx=495;
while (count<player2lastcounter){
outtextxy(cx,27,&playername[count]);
cx+=textwidth(&playername[count]);
count++;}}
if (playertype2==2){
outtextxy(495,27,"COMPUTER");}
setcolor(15);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
sprintf(&score2,"%d",bctr);
setcolor(15);
outtextxy(495,43,&score2);
player=2;
if (letter2==1){
checkxflag=1;
lettercolor=15;
checkoflag=0;}
if (letter2==2){
lettercolor=12;
checkxflag=0;
checkoflag=1;}
}
if (entered==2 || entered==4 || entered==6 || entered==8 || entered==10){
setfillstyle(SOLID_FILL,8);
bar(490,23,635,48);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
if (playertype1==1){
setcolor(15);
counter=0;
cx=495;
while (counter<player1lastcounter){
outtextxy(cx,27,&playername[counter]);
cx+=textwidth(&playername[counter]);
counter++;}}
if (playertype1==2){
outtextxy(495,27,"Computer");}
if (letter1==1){
checkxflag=1;
lettercolor=15;
checkoflag=0;}
if (letter1==2){
checkxflag=0;
lettercolor=12;
checkoflag=1;}
setcolor(15);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
sprintf(&score1,"%d",sctr);
setcolor(15);
outtextxy(495,43,&score1);
player=1;}
entered++;
return 1;}
int boxone(){
boxc=210;
boxcc=235;
boxr=125;
boxrr=150;
return 1;}
int boxtwo(){
boxc=210;
boxcc=235;
boxr=210;
boxrr=235;
return 1;}
int boxthree(){
boxc=210;
boxcc=235;
boxr=295;
boxrr=320;
return 1;}
int boxfour(){
boxc=310;
boxcc=335;
boxr=125;
boxrr=150;
return 1;}
int boxfive(){
boxc=310;
boxcc=335;
boxr=210;
boxrr=235;
return 1;}
int boxsix(){
boxc=310;
boxcc=335;
boxr=295;
boxrr=320;
return 1;}
int boxseven(){
boxc=410;
boxcc=435;
boxr=125;
boxrr=150;
return 1;}
int boxeight(){
boxc=410;
boxcc=435;
boxr=210;
boxrr=235;
return 1;}
int boxnine(){
boxc=410;
boxcc=435;
boxr=295;
boxrr=320;
return 1;}
int quit(){
messageboxc=150;
messageboxr=173;
messageboxcc=500;
messageboxrr=300;
midx=300;
if (soundon==1){
sound(275);
delay(150);
sound(225);
delay(250);
sound(375);
delay(250);
nosound();}
errorscreen();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
setusercharsize(1,3,1,1);
settextjustify(0,1);
setcolor(12);
outtextxy(messageboxc+5,messageboxr+5,"Exit");
setcolor(12);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
outtextxy(messageboxc+5,messageboxr+35,"GREYcells Tic-tac-toe");
setcolor(10);
outtextxy(messageboxc+5,messageboxr+55,"A game developed by J.V.Ravichandran.");
setcolor(7);
outtextxy(messageboxc+5,messageboxr+75,"(c) Semantix Computers, New Delhi");
setcolor(0);
outtextxy(messageboxc+5,messageboxr+90,"B-10, Triveni apartments, Vikas puri,");
outtextxy(messageboxc+5,messageboxr+105,"New Delhi-110 018.");
getch();
return 1;}
No comments:
Post a Comment