My C programs - The Bricks Game !
/************************************************************************/
/* Designed & developed by J.V.RAVICHANDRAN. */
/* Started on 19/04/1998. */
/* 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 -- 27th April, 1998. */
/* Name of software -- GREYcells Bricks */
/* Nature of software -- Game */
/************************************************************************/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
_fmode=O_BINARY;
handle=_creat("termtic.$$$", FA_HIDDEN);
lseek(handle, 0L, SEEK_SET);
_write(handle,"1",1);
_close(handle);
_fmode=O_BINARY;
handle=_creat("delaytic.$$$", FA_HIDDEN);
lseek(handle, 0L, SEEK_SET);
_write(handle,"1",1);
_close(handle);
goon=1;}
if (ct==0){goon=1;}
if (goon==1){
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);
ix=0;
exit(0);}
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);
if (ballrow>=435 && down==1){
if (soundon==1){
sound(100);
delay(10);
nosound();}
wallctr=0;
bx=x;
bxx=xx;
counter=bx;
downangle=0;
down=6;}
if (ballrow>=435 && down==7){
if (soundon==1){
sound(100);
delay(10);
nosound();}
wallctr=0;
bx=x;
bxx=xx;
counter=bx;
downangle=0;
down=6;}
if (down==6){
for (counter==bx;counter=bx-6 && ballcol<=bx+10){
angle=1;
counter=bxx+3;
down=3;}
if (ballcol>bx+10 && ballcol<=bx+20){
angle=2;
counter=bxx+3;
down=3;}
if (ballcol>bx+20 && ballcol<=bx+30){
angle=3;
counter=bxx+3;
down=3;}
if (ballcol>bx+30 && ballcol<=bx+40 && ballcol!=bx+36 && ballcol!=bx+37){
angle=4;
counter=bxx+3;
down=3;}
if (ballcol>bx+40 && ballcol<=bx+50){
angle=5;
counter=bxx+3;
down=3;}
if (ballcol>bx+50 && ballcol<=bx+60){
angle=6;
counter=bxx+3;
down=3;}
if (ballcol>bx+60 && ballcol<=bx+70){
angle=7;
counter=bxx+3;
down=3;}
if (ballcol>bx+70 && ballcol<=bx+83){
angle=8;
counter=bxx+3;
down=3;}
if (ballcol==bx+36 || ballcol==bx+37){
ballrow=ballrow-5;
angle=-1;
down=4;
counter=bxx+3;}
if (down==6){
counter=bxx+3;
down=5;}
}
}
if (down==3){
upangles();}
if (down==5){
if (delayover==3){
cleardevice();
start();
ballrow=125;
ballcol=300;
downangle=1;
gamestart=1;
delayover=5;}
if (delayover!=3 || delayover!=5){
if (soundon==1){
sound(100);
delay(50);
nosound();}
ballrow=ballrow+10;
incolor=9;
ball();
if (ballcx<=135){
setcolor(0);
circle(ballcx,470,7);
ballcx=ballcx+25;
ballnum++;
if (ballnum>4){ballnum=0;}
settextstyle(DEFAULT_FONT,HORIZ_DIR,3);
settextjustify(0,1);
setcolor(10);
outtextxy(125,250,"Have another ball !");
delay(1500);
settextstyle(DEFAULT_FONT,HORIZ_DIR,3);
settextjustify(0,1);
setcolor(0);
outtextxy(125,250,"Have another ball !");}
if (ballcx>=150){
settextstyle(DEFAULT_FONT,HORIZ_DIR,3);
settextjustify(0,1);
setcolor(12);
outtextxy(225,250,"Game over !");
tune();
getch();
setfillstyle(SOLID_FILL,0);
bar(x,y,xx,yy);
incolor=0;
ball();
delay(50);
settextstyle(DEFAULT_FONT,HORIZ_DIR,3);
settextjustify(0,1);
setcolor(0);
outtextxy(225,250,"Game over !");
score=0;
start();
scorex=510;
score=0;
scorex+=textwidth("Score -");
scorex=scorex+5;
ballcx=10;}
}
if (delayover==5){down=1;}
writescore();
wallctr=0;
incolor=0;
ball();
ballrow=125;
down=1;}
incolor=12;
ball();
}
}
key=getch();
switch(key){
case 32:
if (gamestart==2){
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 (gamestart==2){
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(18,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 34:
if (gamestart==2){
if (menuon==0){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
cx=10;
setcolor(12);
outtextxy(cx,60,"G");
cx+=textwidth("G");
cx=cx+1;
setcolor(15);
outtextxy(cx,60,"ame");
menuon=1;
menuflag=0;
menuitem=1;}
if (menuon==1 && menuitem==1 && menuflag==0){
menucol=10;
menurow=63;
menucoll=130;
menuroww=106;
messageboxc=menucol;
messageboxr=menurow;
messageboxcc=menucoll;
messageboxrr=menuroww;
savebox();
dropdownmenu();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(1,1);
setcolor(8);
outtextxy(menucol+60,menurow+13,"Start");
outtextxy(menucol+60,menurow+33,"Quit");
item=0;
menuflag=1;}
}
break;
case 35:
if (gamestart==2){
if (menuon==0){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
cx=100;
setcolor(12);
outtextxy(cx,60,"H");
cx+=textwidth("H");
cx=cx+1;
setcolor(15);
outtextxy(cx,60,"elp");
menuon=1;
menuflag=0;
menuitem=2;}
if (menuon==1 && menuitem==2 && menuflag==0){
menucol=100;
menurow=63;
menucoll=239;
menuroww=106;
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;}
}
break;
case 80:
if (gamestart==2){
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+60,menurow+13,"Start");}
if (item==1){
twod_menu();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(1,1);
setcolor(8);
outtextxy(menucol+60,menurow+13,"Start");
setlinestyle(SOLID_LINE,1,1);
threed_menuitem2();
setcolor(15);
outtextxy(menucol+60,menurow+33,"Quit");}
if (item==2){
twod_menuitem2();
setcolor(8);
outtextxy(menucol+60,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;}
}
}
break;
case 13:
if (gamestart==2){
if (menuon==1 && menuitem==1){
restorebox();
if (item==0){
sound(200);
delay(25);
nosound();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
cx=10;
setcolor(15);
outtextxy(cx,60,"G");
cx+=textwidth("G");
cx=cx+1;
setcolor(12);
outtextxy(cx,60,"ame");}
if (item==1){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
cx=10;
setcolor(15);
outtextxy(cx,60,"G");
cx+=textwidth("G");
cx=cx+1;
setcolor(12);
outtextxy(cx,60,"ame");
item=0;
menuon=0;
menuflag=0;
cleardevice();
textcounter=5;
start();
writescore();
gamestart=1;
count=1;
down=1;
ix=1;}
if (item==2){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
cx=10;
setcolor(15);
outtextxy(cx,60,"G");
cx+=textwidth("G");
cx=cx+1;
setcolor(12);
outtextxy(cx,60,"ame");
quit();
count=1;
ix=0;}
menuon=0;
}
if (menuon==1 && menuitem==2){
restorebox();
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
cx=100;
setcolor(15);
outtextxy(cx,60,"H");
setcolor(12);
cx+=textwidth("H");
cx=cx+1;
outtextxy(cx,60,"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(18,11,"0");
if (item==2){
shareware();}
settextstyle(DEFAULT_FONT,VERT_DIR,1);
settextjustify(0,1);
setcolor(7);
outtextxy(18,11,"0");
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
setcolor(15);
outtextxy(295,12,"GREYcells");
cx=10;
setcolor(15);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
outtextxy(cx,60,"G");
cx+=textwidth("G");
cx=cx+1;
setcolor(12);
outtextxy(cx,60,"ame");
cx=100;
setcolor(15);
outtextxy(cx,60,"H");
cx+=textwidth("H");
cx=cx+1;
setcolor(12);
outtextxy(cx,60,"elp");
setlinestyle(SOLID_LINE,1,1);
setcolor(15);
line(0,65,640,65);
barx=0;
barxx=barx+60;
bary=75;
baryy=bary+20;
bricknum=0;
ctr=0;
if (barxx>640){
if (ctr==0 || ctr==2 || ctr==4 || ctr==6 || ctr==8 || ctr==10 || ctr==12 || ctr==14){
bricknum=1;}
if (ctr==1 || ctr==3 || ctr==5 || ctr==7 || ctr==9 || ctr==11 || ctr==13 || ctr==15){
bricknum=0;}
if (bricknum==1){
bary=bary+25;
baryy=bary+20;
barx=0;
barxx=barx+30;}
if (bricknum==0){
bary=bary+25;
baryy=bary+20;
barx=0;
barxx=barx+60;}
ctr++;}
}
if (textcounter==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,"Speed");
setcolor(0);
outtextxy(messageboxc+5,messageboxr+35,"Enter ballspeed (less than 100) -");
messageboxc+=textwidth("Enter ballspeed (less than 100) -");
cursorctr=messageboxc+5;
messageboxc=cursorctr;
setfillstyle(SOLID_FILL,15);
bar(messageboxc,messageboxr+45,messageboxc+5,messageboxr+50);}
/* BRICKS */
/* B */
srand( seed ); /* Restart random # function */
count=0;
color=15;
while (!kbhit()){
if (count==0 || count==2){
i=0;
z=50;
q=20;
w=200;
h=125;
ctr=0;
greateri=1000;
bee();}
if (count==0 || count==1){
i=0;
z=150;
q=20;
w=200;
h=125;
ctr=0;
greateri=1000;
arr();}
if (count==0 || count==2){
i=0;
z=250;
q=20;
w=200;
h=125;
greateri=1000;
eye();}
if (count==0 || count==1){
i=0;
z=325;
q=15;
w=200;
h=25;
greateri=100;
ctr=0;
see();}
if (count==0 || count==2){
i=0;
z=425;
q=20;
w=200;
h=125;
greateri=1000;
ctr=0;
kay();}
if (count==0 || count==1){
i=0;
z=595;
q=20;
w=200;
h=15;
greateri=100;
ctr=0;
ess();}
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
setcolor(10);
outtextxy(115,340,"A ballgame designed & developed by J.V.Ravichandran");
sound(275);
delay(50);
sound(250);
delay(100);
sound(300);
delay(75);
sound(125);
delay(50);
sound(225);
delay(50);
sound(300);
delay(100);
sound(125);
delay(50);
sound(225);
delay(100);
nosound();
/* End */
delay(200);
count++;
color++;
if (color>=15){
color=0;}
}
while (textcounter!=5){
ctrlbrk(c_break);
key=getch();
switch(key){
case 8:
if (textcounter>0 && messageboxc>cursorctr){
setfillstyle(SOLID_FILL,9);
bar(messageboxc-3,messageboxr+30,messageboxc+10,messageboxr+50);
messageboxc-=textwidth(&key);
textcounter--;}
if (textcounter<=0){textcounter=0;}
if (messageboxc<=cursorctr){messageboxc=cursorctr;}
setfillstyle(SOLID_FILL,15);
bar(messageboxc,messageboxr+45,messageboxc+5,messageboxr+50);
break;
case 27:
sound(200);
delay(50);
nosound();
break;
case 13:
if (textcounter==0){
sound(200);
delay(50);
nosound();}
if (delayover==1 && textcounter>0){
lastcounter=textcounter;
gamestart=2;
count=0;
while (count
/* Frame */
setfillstyle(SOLID_FILL,2);
bar(0,100,5,460);
bar(0,455,640,460);
bar(635,100,640,460);
ballrow=125;
ballcol=300;
once=0;
down=1;
brickctr=1;
while (brickctr<=40){
strcpy(&brick[brickctr],"0");
brickctr++;}
incolor=12;
ball();
if (delayover==3 || delayover==5){
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(0,1);
setcolor(12);
outtextxy(275,470,"Level - 1");
if (ballnum==0){
ballcx=10;}
if (ballnum==1){
ballcx=35;}
if (ballnum==2){
ballcx=60;}
if (ballnum==3){
ballcx=85;}
if (ballnum==4){
ballcx=110;}
if (ballnum>4){
srand( seed ); /* Restart Random # at same # */
vx=z+random(q-1); /* Column */
vy=w+random(h-1); /* Row */
putpixel( vx, vy, color );}
ctr++;
if (ctr==1){
i=0;
z=170;
q=15;
w=200;
greateri=50;
h=15;}
if (ctr==2){
i=0;
greateri=50;
z=180;
q=15;
w=200;
h=25;}
if (ctr==3){
i=0;
greateri=50;
z=190;
q=15;
w=210;
h=25;}
if (ctr==4){
i=0;
greateri=50;
z=200;
q=15;
w=220;
h=25;}
if (ctr==5){
i=0;
greateri=50;
z=190;
q=15;
w=210;
h=25;}
if (ctr==6){
i=0;
greateri=50;
z=170;
q=15;
w=250;
h=25;}
if (ctr==7){
i=0;
greateri=50;
z=180;
q=15;
w=240;
h=25;}
if (ctr==8){
i=0;
z=190;
q=15;
w=230;
greateri=50;
h=25;}
if (ctr==9){
i=0;
z=170;
q=15;
w=250;
greateri=50;
h=15;}
if (ctr==10){
i=0;
greateri=50;
z=180;
q=15;
w=250;
h=25;}
if (ctr==11){
i=0;
greateri=50;
z=180;
q=15;
w=260;
h=25;}
if (ctr==12){
i=0;
greateri=50;
z=195;
q=15;
w=270;
h=25;}
if (ctr==13){
i=0;
greateri=50;
z=200;
q=15;
w=280;
h=25;}
if (ctr==14){
i=0;
greateri=50;
z=205;
q=15;
w=290;
h=25;}
if (ctr==15){
i=0;
greateri=50;
z=205;
q=15;
w=300;
h=25;}
}
srand(seed);
return 1;}
int eye(){
for( i=0 ; i
delay(100);
for( i=0 ; i
w=195;
greateri=100;
h=25;}
if (ctr==3){
i=0;
z=565;
q=15;
w=205;
greateri=100;
h=25;}
if (ctr==4){
i=0;
z=555;
q=15;
w=210;
greateri=100;
h=25;}
if (ctr==5){
i=0;
z=545;
q=15;
w=215;
greateri=100;
h=25;}
if (ctr==6){
i=0;
z=545;
q=15;
w=225;
greateri=100;
h=25;}
if (ctr==7){
i=0;
z=555;
q=15;
w=235;
greateri=100;
h=25;}
if (ctr==8){
i=0;
z=565;
q=15;
w=245;
greateri=100;
h=25;}
if (ctr==9){
i=0;
z=575;
q=15;
w=255;
greateri=100;
h=25;}
if (ctr==10){
i=0;
z=585;
q=15;
w=265;
greateri=100;
h=25;}
if (ctr==11){
i=0;
z=585;
q=15;
w=275;
greateri=100;
h=25;}
if (ctr==12){
i=0;
z=575;
q=15;
w=285;
greateri=100;
h=25;}
if (ctr==13){
i=0;
z=565;
q=15;
w=290;
greateri=100;
h=25;}
if (ctr==14){
i=0;
z=555;
q=15;
w=290;
greateri=100;
h=25;}
if (ctr==15){
i=0;
z=545;
q=15;
w=295;
greateri=100;
h=25;}
if (ctr==16){
i=0;
z=535;
q=15;
w=300;
greateri=100;
h=25;}
if (ctr==17){
i=0;
z=525;
q=15;
w=300;
greateri=100;
h=25;}
srand(seed);
}
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);
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 threed_menu(){
setlinestyle(SOLID_LINE,1,1);
setcolor(15);
line(menucoll-6,menurow+8,menucoll-6,menurow+17);
line(menucol+7,menurow+17,menucoll-6,menurow+17);
setcolor(0);
line(menucol+7,menurow+7,menucoll-7,menurow+7);
line(menucol+7,menurow+7,menucol+7,menurow+17);
return 1;}
No comments:
Post a Comment