I have just made a significant rewrite and improvement to a small C game from a book. The original racing car could only move left or right, couldn't move forward or backward, there was only one truck as the passing vehicle with only one color, which was very monotonous. I added forward and backward movement for the racing car, added another small truck, added mileage display and a menu to choose the game difficulty, made the colors of the passing vehicles colorful, and also made it reflect failure if the racing car crashes into the passing vehicles from the left or right sides. In contrast, the original crash was very single...
I hope everyone has time to play it... If you are good at art, you can also change it into a realistic car model by yourself...
Also, I have prepared an executable program that can run independently, which can be played by double - clicking...
But unfortunately, there is only PC SPEAKER, and there is no music yet.. Can anyone who knows how to add it?
Open the attachment
#include <math.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <dos.h>
#include <bios.h>
#include <string.h>
#include <ctype.h>
#define BORDER 1
#define ESC 27
#define REV_VID 0x1e
#define NORM_VID 0x40
void light(void);
void chineseputs(int x, int y, char *p, int attrib);
void display_menu(char *menu, int x, int y, int count);
void disp_box(int x1, int y1, int x2, int y2, int attrib);
int get_resp(int x, int y, int count, char *menu, char *keys);
int popup(char *menu, char *keys, int count, int x, int y, int border);
void goto_xy(int x, int y);
int coustomize();
main()
{
int gdriver,gmode,c,d,e,b,i,l,j,k,u,w,course,s,h,bcolor,scolor,pcolor,ccolor,time;
int *p={400,40,310,200,610,140};
int poly;
char speed;
char *main_menu={".h...(high)",".a...(average)",".l...(low)",".c...(coustomize)"};
c=1;d=0;u=0;
gdriver=DETECT;
registerbgidriver(EGAVGA_driver);
initgraph(&gdriver,&gmode,""
;
setwritemode(XOR_PUT);
setfillstyle(HATCH_FILL,4);
drawpoly(4,p);
line(380,50,600,160);
setcolor(14);
setbkcolor(0);
settextstyle(GOTHIC_FONT,HORIZ_DIR,6);
outtextxy(350,70,"JUST START MY COURSE !!"
;
setcolor(5);
settextstyle(TRIPLEX_FONT,VERT_DIR,8);
outtextxy(550,120,"Our goal is just waiting for your hands !"
;
setcolor(8);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
outtextxy(80,400,"Written by Dai ..."
;
getch();
closegraph();
speed=popup(main_menu, "halc", 4, 5, 16, BORDER);
if(speed==0) time=400;
if(speed==1) time=1000;
if(speed==2) time=1500;
if(speed==3) time=coustomize();
if(speed==5) exit (0);
initgraph(&gdriver,&gmode,""
;
setwritemode(XOR_PUT);
setcolor(YELLOW);
outtextxy(250,350,"Are you ready?"
;
while(kbhit()==0); /* getch() will eat the previous ENTER so it is not used */
cleardevice();
light();
setcolor(15);
for(h=0;h<4;h++)
line(150+h*100,0,150+h*100,472);
for(h=0;h<3;h++)
{
setlinestyle(3,0,1);
line(200+h*100,0,200+h*100,472);
settextstyle(1,HORIZ_DIR,3);
}
settextstyle(1,HORIZ_DIR,4);
setcolor(RED);
outtextxy(40,40,"Just do it !"
;
outtextxy(40,80,"Yeah !!"
;
setcolor(10);
setlinestyle(SOLID_LINE,0,3);
rectangle(150,400,450,460);
outtextxy(160,410,"Ready,Begin!"
;
setcolor(BLUE);
rectangle(180+c*100,400,220+c*100,440);
rectangle(170+c*100,390,230+c*100,400);
rectangle(190+c*100,370,210+c*100,390);
rectangle(170+c*100,440,230+c*100,450);
setcolor(5);
line(190+c*100,400,190+c*100,440);
line(200+c*100,400,200+c*100,440);
line(210+c*100,400,210+c*100,440);
line(200+c*100,350,200+c*100,370);
line(185+c*100,350,215+c*100,350);
course=0;
w=-50;
loop:
bcolor=rand()%15,scolor=rand()%15,pcolor=rand()%15,ccolor=rand()%15,i=rand()%3,l=rand()%3;
if(w>=800) w=-50;
for(j=-20;j<=90;j++,w++)
{
setcolor(bcolor+1);
rectangle(170+i*100,j*10,230+i*100,60+j*10);
rectangle(160+i*100,70+j*10,240+i*100,260+j*10);
line(180+i*100,70+j*10,180+i*100,260+j*10);
line(200+i*100,70+j*10,200+i*100,260+j*10);
line(220+i*100,70+j*10,220+i*100,260+j*10);
if(j>=20)
{
k=j-35;
setcolor(scolor+1);
rectangle(170+l*100,k*10,230+l*100,60+k*10);
}
setcolor(10);
line(85,-5+u*15+w,85,55+u*15+w);
line(95,-5+u*15+w,95,55+u*15+w);
line(105,-5+u*15+w,105,55+u*15+w);
line(115,-5+u*15+w,115,55+u*15+w);
line(75,11+u*15+w,75,39+u*15+w);
line(125,11+u*15+w,125,39+u*15+w);
setcolor(pcolor+1);
poly = 530;
poly = u*15+j*30;
poly =515;
poly = 25+u*15+j*30;
poly =485;
poly =25+u*15+j*30 ;
poly =470;
poly =u*15+j*30 ;
poly =485;
poly =-25+u*15+j*30;
poly =515;
poly =-25+u*15+j*30 ;
poly = poly;
poly = poly;
drawpoly(7,poly);
delay(time);
setcolor(bcolor+1);
rectangle(170+i*100,j*10,230+i*100,60+j*10);
rectangle(160+i*100,70+j*10,240+i*100,260+j*10);
line(180+i*100,70+j*10,180+i*100,260+j*10);
line(200+i*100,70+j*10,200+i*100,260+j*10);
line(220+i*100,70+j*10,220+i*100,260+j*10);
if(j>=20)
{
setcolor(scolor+1);
rectangle(170+l*100,k*10,230+l*100,60+k*10);
}
setcolor(10);
line(85,-5+u*15+w,85,55+u*15+w);
line(95,-5+u*15+w,95,55+u*15+w);
line(105,-5+u*15+w,105,55+u*15+w);
line(115,-5+u*15+w,115,55+u*15+w);
line(75,11+u*15+w,75,39+u*15+w);
line(125,11+u*15+w,125,39+u*15+w);
setcolor(pcolor+1);
poly = 530;
poly = u*15+j*30;
poly =515;
poly = 25+u*15+j*30;
poly =485;
poly =25+u*15+j*30 ;
poly =470;
poly =u*15+j*30 ;
poly =485;
poly =-25+u*15+j*30;
poly =515;
poly =-25+u*15+j*30 ;
poly = poly;
poly = poly;
drawpoly(7,poly);
sound(j*10);
delay(50);
nosound();
course++;
setcolor(ccolor+1);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
outtextxy(580,390,"10000"
;
if(course>=1000) outtextxy(580,50,"1000"
;
if(course>=1500) outtextxy(580,70,"1500"
;
if(course>=2000) outtextxy(580,90,"2000"
;
if(course>=2500) outtextxy(580,110,"2500"
;
if(course>=3000) outtextxy(580,130,"3000"
;
if(course>=3500) outtextxy(580,150,"3500"
;
if(course>=4000) outtextxy(580,170,"4000"
;
if(course>=4500) outtextxy(580,190,"4500"
;
if(course>=5000) outtextxy(580,210,"5000"
;
if(course>=5500) outtextxy(580,230,"5500"
;
if(course>=6000) outtextxy(580,250,"6000"
;
if(course>=6500) outtextxy(580,270,"6500"
;
if(course>=7000) outtextxy(580,290,"7000"
;
if(course>=7500) outtextxy(580,310,"7500"
;
if(course>=8000) outtextxy(580,330,"8000"
;
if(course>=8500) outtextxy(580,350,"8500"
;
if(course>=9000) outtextxy(580,370,"9000"
;
if(course>=10000) outtextxy(580,390,"10000"
;
if(course>=10000)
{
sound(800);
delay(1000);
nosound();
closegraph();
window(10,5,60,10);
textbackground(RED);
textcolor(YELLOW);
cprintf("\n\rYou are EXCELLENT !\n\r"
;
cprintf(" You have WON !\n\r"
;
cprintf(" The mileage you have covered\n\ris:"
;
textcolor(BLUE);
cprintf("%d",course);
getch();
getch();
exit (0);
}
if(bioskey(1)!=0)
{ b=bioskey(0);
setcolor(BLUE);
rectangle(180+c*100,400-d*10,220+c*100,440-d*10);
rectangle(170+c*100,390-d*10,230+c*100,400-d*10);
rectangle(190+c*100,370-d*10,210+c*100,390-d*10);
rectangle(170+c*100,440-d*10,230+c*100,450-d*10);
setcolor(5);
line(190+c*100,400-d*10,190+c*100,440-d*10);
line(200+c*100,400-d*10,200+c*100,440-d*10);
line(210+c*100,400-d*10,210+c*100,440-d*10);
line(200+c*100,350-d*10,200+c*100,370-d*10);
line(185+c*100,350-d*10,215+c*100,350-d*10);
if((b==0x4b00)&&(c>0))
c--;
else if((b==0x4d00)&&(c<2))
c++;
else if(b==0x4800)
d++;
else if(b==0x5000)
d--;
setcolor(BLUE);
setcolor(BLUE);
rectangle(180+c*100,400-d*10,220+c*100,440-d*10);
rectangle(170+c*100,390-d*10,230+c*100,400-d*10);
rectangle(190+c*100,370-d*10,210+c*100,390-d*10);
rectangle(170+c*100,440-d*10,230+c*100,450-d*10);
setcolor(5);
line(190+c*100,400-d*10,190+c*100,440-d*10);
line(200+c*100,400-d*10,200+c*100,440-d*10);
line(210+c*100,400-d*10,210+c*100,440-d*10);
line(200+c*100,350-d*10,200+c*100,370-d*10);
line(185+c*100,350-d*10,215+c*100,350-d*10);
}
/*if(course>=1)
{ */
if(((c==i)&&(j>=9-d&&j<=45-d))||((c==l)&&(k>=29-d&&k<=45-d)))
{
for(i=0;i<2000;i++)
{
sound(1500);
delay(10);
nosound();
}
closegraph();
window(35,18,75,23);
textbackground(WHITE);
textcolor(DARKGRAY);
cprintf("\n\r You made a car ACCIDENT !\n\r"
;
cprintf(" You have LOST !\n\r"
;
cprintf("The mileage you have covered\n\ris:"
;
textcolor(MAGENTA);
cprintf("%d",course);
goon:
while(bioskey(1)==0);
if(bioskey(0)==0x1c0d) /* or if((char)bioskey(0)==13) */
/*getch();
getch();*/
exit (0);
goto goon;
}
/* if
{
cleardevice();
outtextxy(200,100,"You made a car ACCIDENT !"
;
outtextxy(280,120," You have LOST !"
;
getch();
closegraph();
exit;
}*/
/* }*/
}
goto loop;
}
void goto_xy(int x, int y)
{
union REGS regs;
regs.h.ah=2;
regs.h.dl=y;
regs.h.dh=x;
regs.h.bh=0;
int86(0x10, ®s, ®s);
}
void display_menu(char *menu, int x, int y, int count)
{
register int i;
for(i=0;i<count;i++,x++)
{
goto_xy(x, y);
cprintf(menu);
}
}
void disp_box(int x1, int y1, int x2, int y2, int attrib)
{
unsigned char *boxchar={"H","H","H","H","H","H"};
register int i;
for(i=x1;i<=x2;i++)
{
chineseputs(i, y1, boxchar,attrib);
chineseputs(i, y2, boxchar,attrib);
}
for(i=y1;i<=y2;i++)
{
chineseputs(x1, i, boxchar,attrib);
chineseputs(x2, i, boxchar,attrib);
}
chineseputs(x1, y1, boxchar,attrib);
chineseputs(x2, y1, boxchar,attrib);
chineseputs(x2, y2, boxchar,attrib);
chineseputs(x1, y2, boxchar,attrib);
}
void chineseputs(int x, int y, char *p, int attrib)
{
union REGS r;
while(*p)
{
r.h.ah=2;
r.h.dl=x++;
r.h.dh=y;
int86(0x10, &r, &r);
r.h.ah=9;
r.h.bh=0;
r.x.cx=1;
r.h.al=*p++;
r.h.bl=attrib;
int86(0x10, &r, &r);
}
}
int get_resp(int x, int y, int count, char *menu, char *keys)
{
union inkey
{
char ch;
int i;
}c;
int arrow_choice=0, key_choice;
y++;
goto_xy(x, y);
chineseputs(y, x, menu, REV_VID);
for(;
{
while(!bioskey(1));
c.i=bioskey(0);
goto_xy(x+arrow_choice, y);
chineseputs(y, x+arrow_choice, menu, NORM_VID);
if(c.ch)
{
key_choice=is_in(keys, tolower(c.ch));
if(key_choice) return key_choice-1;
switch(c.ch)
{
case '\r': return arrow_choice;
case ' ': arrow_choice++;
break;
case ESC: return 5;
}
}
else
{
switch(c.ch)
{
case 72: arrow_choice--;
break;
case 80: arrow_choice++;
break;
}
}
if(arrow_choice==count) arrow_choice=0;
if(arrow_choice<0) arrow_choice=count-1;
goto_xy(x+arrow_choice, y);
chineseputs(y, x+arrow_choice, menu, REV_VID);
}
}
int is_in(char *s, char c)
{
register int i;
for(i=0;*s;i++)
if(*s++==c) return i+1;
return 0;
}
int popup(char *menu, char *keys, int count, int x, int y, int border)
{
register int i, len;
int endx, endy, choice;
unsigned *p;
if((x>24)||(x<0)||(y>79)||(y<0))
{
printf("range error"
;
return -2;
}
len=10;
for(i=0;i<count;i++)
if(strlen(menu)>len) len=strlen(menu);
endy=len+1+y;
endx=count+1+x;
if((endx+1>24)||(endy+1>79))
{
printf("menu dont'fit"
;
return -2;
}
/*p=(unsigned int*)malloc((endx-x+1) *(endy-y+1));
if(!p) exit(1);
save_video(x, endx+1, y, endy+1, p);*/
if(border) disp_box(y, x, endy, endx, YELLOW);
display_menu(menu, x+1, y+1, count);
choice=get_resp(x+1, y, count, menu, keys);
/*restore_video(x, endx+1, y, endy+2, (unsigned char *)p);
free (p);*/
return choice;
}
int coustomize()
{
int delaytime;
delaytime=0;
window(36,10,76,20);
textcolor(GREEN);
textbackground(BLUE);
clrscr();
cprintf("\n Please input the delaytime (in milli-\n\r second):\n\r The greater the delaytime is,the slower the game is. It depends on your PC CPU frequency as well as your own preferenc es.The suggested num is:\n\n\r"
;
textcolor(RED);
cprintf(" *** from 100 to 10000 ***\n\r"
;
textcolor(GREEN);
cprintf(" input here:"
;
cscanf("%d",&delaytime);
return delaytime;
}
void light(void)
{
rectangle(535,65,565,155);
/*floodfill(545,100,BLUE);*/
setfillstyle(1,RED);
fillellipse(550,80,10,10);
sound(650);
delay(300);
nosound();
delay(100);
setfillstyle(1,YELLOW);
fillellipse(550,110,10,10);
sound(650);
delay(300);
nosound();
delay(100);
setfillstyle(1,GREEN);
fillellipse(550,140,10,10);
sound(650);
delay(300);
nosound();
delay(100);
setcolor(10);
setlinestyle(SOLID_LINE,0,3);
rectangle(150,400,450,460);
outtextxy(160,410,"Ready,Begin!"
;
}
[ Last edited by GOTOmsdos on 2005-10-22 at 00:35 ]
I hope everyone has time to play it... If you are good at art, you can also change it into a realistic car model by yourself...
Also, I have prepared an executable program that can run independently, which can be played by double - clicking...
But unfortunately, there is only PC SPEAKER, and there is no music yet.. Can anyone who knows how to add it?
Open the attachment
#include <math.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <dos.h>
#include <bios.h>
#include <string.h>
#include <ctype.h>
#define BORDER 1
#define ESC 27
#define REV_VID 0x1e
#define NORM_VID 0x40
void light(void);
void chineseputs(int x, int y, char *p, int attrib);
void display_menu(char *menu, int x, int y, int count);
void disp_box(int x1, int y1, int x2, int y2, int attrib);
int get_resp(int x, int y, int count, char *menu, char *keys);
int popup(char *menu, char *keys, int count, int x, int y, int border);
void goto_xy(int x, int y);
int coustomize();
main()
{
int gdriver,gmode,c,d,e,b,i,l,j,k,u,w,course,s,h,bcolor,scolor,pcolor,ccolor,time;
int *p={400,40,310,200,610,140};
int poly;
char speed;
char *main_menu={".h...(high)",".a...(average)",".l...(low)",".c...(coustomize)"};
c=1;d=0;u=0;
gdriver=DETECT;
registerbgidriver(EGAVGA_driver);
initgraph(&gdriver,&gmode,""
;setwritemode(XOR_PUT);
setfillstyle(HATCH_FILL,4);
drawpoly(4,p);
line(380,50,600,160);
setcolor(14);
setbkcolor(0);
settextstyle(GOTHIC_FONT,HORIZ_DIR,6);
outtextxy(350,70,"JUST START MY COURSE !!"
;setcolor(5);
settextstyle(TRIPLEX_FONT,VERT_DIR,8);
outtextxy(550,120,"Our goal is just waiting for your hands !"
;setcolor(8);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
outtextxy(80,400,"Written by Dai ..."
;getch();
closegraph();
speed=popup(main_menu, "halc", 4, 5, 16, BORDER);
if(speed==0) time=400;
if(speed==1) time=1000;
if(speed==2) time=1500;
if(speed==3) time=coustomize();
if(speed==5) exit (0);
initgraph(&gdriver,&gmode,""
;setwritemode(XOR_PUT);
setcolor(YELLOW);
outtextxy(250,350,"Are you ready?"
;while(kbhit()==0); /* getch() will eat the previous ENTER so it is not used */
cleardevice();
light();
setcolor(15);
for(h=0;h<4;h++)
line(150+h*100,0,150+h*100,472);
for(h=0;h<3;h++)
{
setlinestyle(3,0,1);
line(200+h*100,0,200+h*100,472);
settextstyle(1,HORIZ_DIR,3);
}
settextstyle(1,HORIZ_DIR,4);
setcolor(RED);
outtextxy(40,40,"Just do it !"
;outtextxy(40,80,"Yeah !!"
;setcolor(10);
setlinestyle(SOLID_LINE,0,3);
rectangle(150,400,450,460);
outtextxy(160,410,"Ready,Begin!"
;setcolor(BLUE);
rectangle(180+c*100,400,220+c*100,440);
rectangle(170+c*100,390,230+c*100,400);
rectangle(190+c*100,370,210+c*100,390);
rectangle(170+c*100,440,230+c*100,450);
setcolor(5);
line(190+c*100,400,190+c*100,440);
line(200+c*100,400,200+c*100,440);
line(210+c*100,400,210+c*100,440);
line(200+c*100,350,200+c*100,370);
line(185+c*100,350,215+c*100,350);
course=0;
w=-50;
loop:
bcolor=rand()%15,scolor=rand()%15,pcolor=rand()%15,ccolor=rand()%15,i=rand()%3,l=rand()%3;
if(w>=800) w=-50;
for(j=-20;j<=90;j++,w++)
{
setcolor(bcolor+1);
rectangle(170+i*100,j*10,230+i*100,60+j*10);
rectangle(160+i*100,70+j*10,240+i*100,260+j*10);
line(180+i*100,70+j*10,180+i*100,260+j*10);
line(200+i*100,70+j*10,200+i*100,260+j*10);
line(220+i*100,70+j*10,220+i*100,260+j*10);
if(j>=20)
{
k=j-35;
setcolor(scolor+1);
rectangle(170+l*100,k*10,230+l*100,60+k*10);
}
setcolor(10);
line(85,-5+u*15+w,85,55+u*15+w);
line(95,-5+u*15+w,95,55+u*15+w);
line(105,-5+u*15+w,105,55+u*15+w);
line(115,-5+u*15+w,115,55+u*15+w);
line(75,11+u*15+w,75,39+u*15+w);
line(125,11+u*15+w,125,39+u*15+w);
setcolor(pcolor+1);
poly = 530;
poly = u*15+j*30;
poly =515;
poly = 25+u*15+j*30;
poly =485;
poly =25+u*15+j*30 ;
poly =470;
poly =u*15+j*30 ;
poly =485;
poly =-25+u*15+j*30;
poly =515;
poly =-25+u*15+j*30 ;
poly = poly;
poly = poly;
drawpoly(7,poly);
delay(time);
setcolor(bcolor+1);
rectangle(170+i*100,j*10,230+i*100,60+j*10);
rectangle(160+i*100,70+j*10,240+i*100,260+j*10);
line(180+i*100,70+j*10,180+i*100,260+j*10);
line(200+i*100,70+j*10,200+i*100,260+j*10);
line(220+i*100,70+j*10,220+i*100,260+j*10);
if(j>=20)
{
setcolor(scolor+1);
rectangle(170+l*100,k*10,230+l*100,60+k*10);
}
setcolor(10);
line(85,-5+u*15+w,85,55+u*15+w);
line(95,-5+u*15+w,95,55+u*15+w);
line(105,-5+u*15+w,105,55+u*15+w);
line(115,-5+u*15+w,115,55+u*15+w);
line(75,11+u*15+w,75,39+u*15+w);
line(125,11+u*15+w,125,39+u*15+w);
setcolor(pcolor+1);
poly = 530;
poly = u*15+j*30;
poly =515;
poly = 25+u*15+j*30;
poly =485;
poly =25+u*15+j*30 ;
poly =470;
poly =u*15+j*30 ;
poly =485;
poly =-25+u*15+j*30;
poly =515;
poly =-25+u*15+j*30 ;
poly = poly;
poly = poly;
drawpoly(7,poly);
sound(j*10);
delay(50);
nosound();
course++;
setcolor(ccolor+1);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
outtextxy(580,390,"10000"
;if(course>=1000) outtextxy(580,50,"1000"
;if(course>=1500) outtextxy(580,70,"1500"
;if(course>=2000) outtextxy(580,90,"2000"
;if(course>=2500) outtextxy(580,110,"2500"
;if(course>=3000) outtextxy(580,130,"3000"
;if(course>=3500) outtextxy(580,150,"3500"
;if(course>=4000) outtextxy(580,170,"4000"
;if(course>=4500) outtextxy(580,190,"4500"
;if(course>=5000) outtextxy(580,210,"5000"
;if(course>=5500) outtextxy(580,230,"5500"
;if(course>=6000) outtextxy(580,250,"6000"
;if(course>=6500) outtextxy(580,270,"6500"
;if(course>=7000) outtextxy(580,290,"7000"
;if(course>=7500) outtextxy(580,310,"7500"
;if(course>=8000) outtextxy(580,330,"8000"
;if(course>=8500) outtextxy(580,350,"8500"
;if(course>=9000) outtextxy(580,370,"9000"
;if(course>=10000) outtextxy(580,390,"10000"
;if(course>=10000)
{
sound(800);
delay(1000);
nosound();
closegraph();
window(10,5,60,10);
textbackground(RED);
textcolor(YELLOW);
cprintf("\n\rYou are EXCELLENT !\n\r"
;cprintf(" You have WON !\n\r"
;cprintf(" The mileage you have covered\n\ris:"
;textcolor(BLUE);
cprintf("%d",course);
getch();
getch();
exit (0);
}
if(bioskey(1)!=0)
{ b=bioskey(0);
setcolor(BLUE);
rectangle(180+c*100,400-d*10,220+c*100,440-d*10);
rectangle(170+c*100,390-d*10,230+c*100,400-d*10);
rectangle(190+c*100,370-d*10,210+c*100,390-d*10);
rectangle(170+c*100,440-d*10,230+c*100,450-d*10);
setcolor(5);
line(190+c*100,400-d*10,190+c*100,440-d*10);
line(200+c*100,400-d*10,200+c*100,440-d*10);
line(210+c*100,400-d*10,210+c*100,440-d*10);
line(200+c*100,350-d*10,200+c*100,370-d*10);
line(185+c*100,350-d*10,215+c*100,350-d*10);
if((b==0x4b00)&&(c>0))
c--;
else if((b==0x4d00)&&(c<2))
c++;
else if(b==0x4800)
d++;
else if(b==0x5000)
d--;
setcolor(BLUE);
setcolor(BLUE);
rectangle(180+c*100,400-d*10,220+c*100,440-d*10);
rectangle(170+c*100,390-d*10,230+c*100,400-d*10);
rectangle(190+c*100,370-d*10,210+c*100,390-d*10);
rectangle(170+c*100,440-d*10,230+c*100,450-d*10);
setcolor(5);
line(190+c*100,400-d*10,190+c*100,440-d*10);
line(200+c*100,400-d*10,200+c*100,440-d*10);
line(210+c*100,400-d*10,210+c*100,440-d*10);
line(200+c*100,350-d*10,200+c*100,370-d*10);
line(185+c*100,350-d*10,215+c*100,350-d*10);
}
/*if(course>=1)
{ */
if(((c==i)&&(j>=9-d&&j<=45-d))||((c==l)&&(k>=29-d&&k<=45-d)))
{
for(i=0;i<2000;i++)
{
sound(1500);
delay(10);
nosound();
}
closegraph();
window(35,18,75,23);
textbackground(WHITE);
textcolor(DARKGRAY);
cprintf("\n\r You made a car ACCIDENT !\n\r"
;cprintf(" You have LOST !\n\r"
;cprintf("The mileage you have covered\n\ris:"
;textcolor(MAGENTA);
cprintf("%d",course);
goon:
while(bioskey(1)==0);
if(bioskey(0)==0x1c0d) /* or if((char)bioskey(0)==13) */
/*getch();
getch();*/
exit (0);
goto goon;
}
/* if
{
cleardevice();
outtextxy(200,100,"You made a car ACCIDENT !"
;outtextxy(280,120," You have LOST !"
;getch();
closegraph();
exit;
}*/
/* }*/
}
goto loop;
}
void goto_xy(int x, int y)
{
union REGS regs;
regs.h.ah=2;
regs.h.dl=y;
regs.h.dh=x;
regs.h.bh=0;
int86(0x10, ®s, ®s);
}
void display_menu(char *menu, int x, int y, int count)
{
register int i;
for(i=0;i<count;i++,x++)
{
goto_xy(x, y);
cprintf(menu);
}
}
void disp_box(int x1, int y1, int x2, int y2, int attrib)
{
unsigned char *boxchar={"H","H","H","H","H","H"};
register int i;
for(i=x1;i<=x2;i++)
{
chineseputs(i, y1, boxchar,attrib);
chineseputs(i, y2, boxchar,attrib);
}
for(i=y1;i<=y2;i++)
{
chineseputs(x1, i, boxchar,attrib);
chineseputs(x2, i, boxchar,attrib);
}
chineseputs(x1, y1, boxchar,attrib);
chineseputs(x2, y1, boxchar,attrib);
chineseputs(x2, y2, boxchar,attrib);
chineseputs(x1, y2, boxchar,attrib);
}
void chineseputs(int x, int y, char *p, int attrib)
{
union REGS r;
while(*p)
{
r.h.ah=2;
r.h.dl=x++;
r.h.dh=y;
int86(0x10, &r, &r);
r.h.ah=9;
r.h.bh=0;
r.x.cx=1;
r.h.al=*p++;
r.h.bl=attrib;
int86(0x10, &r, &r);
}
}
int get_resp(int x, int y, int count, char *menu, char *keys)
{
union inkey
{
char ch;
int i;
}c;
int arrow_choice=0, key_choice;
y++;
goto_xy(x, y);
chineseputs(y, x, menu, REV_VID);
for(;

{
while(!bioskey(1));
c.i=bioskey(0);
goto_xy(x+arrow_choice, y);
chineseputs(y, x+arrow_choice, menu, NORM_VID);
if(c.ch)
{
key_choice=is_in(keys, tolower(c.ch));
if(key_choice) return key_choice-1;
switch(c.ch)
{
case '\r': return arrow_choice;
case ' ': arrow_choice++;
break;
case ESC: return 5;
}
}
else
{
switch(c.ch)
{
case 72: arrow_choice--;
break;
case 80: arrow_choice++;
break;
}
}
if(arrow_choice==count) arrow_choice=0;
if(arrow_choice<0) arrow_choice=count-1;
goto_xy(x+arrow_choice, y);
chineseputs(y, x+arrow_choice, menu, REV_VID);
}
}
int is_in(char *s, char c)
{
register int i;
for(i=0;*s;i++)
if(*s++==c) return i+1;
return 0;
}
int popup(char *menu, char *keys, int count, int x, int y, int border)
{
register int i, len;
int endx, endy, choice;
unsigned *p;
if((x>24)||(x<0)||(y>79)||(y<0))
{
printf("range error"
;return -2;
}
len=10;
for(i=0;i<count;i++)
if(strlen(menu)>len) len=strlen(menu);
endy=len+1+y;
endx=count+1+x;
if((endx+1>24)||(endy+1>79))
{
printf("menu dont'fit"
;return -2;
}
/*p=(unsigned int*)malloc((endx-x+1) *(endy-y+1));
if(!p) exit(1);
save_video(x, endx+1, y, endy+1, p);*/
if(border) disp_box(y, x, endy, endx, YELLOW);
display_menu(menu, x+1, y+1, count);
choice=get_resp(x+1, y, count, menu, keys);
/*restore_video(x, endx+1, y, endy+2, (unsigned char *)p);
free (p);*/
return choice;
}
int coustomize()
{
int delaytime;
delaytime=0;
window(36,10,76,20);
textcolor(GREEN);
textbackground(BLUE);
clrscr();
cprintf("\n Please input the delaytime (in milli-\n\r second):\n\r The greater the delaytime is,the slower the game is. It depends on your PC CPU frequency as well as your own preferenc es.The suggested num is:\n\n\r"
;textcolor(RED);
cprintf(" *** from 100 to 10000 ***\n\r"
;textcolor(GREEN);
cprintf(" input here:"
;cscanf("%d",&delaytime);
return delaytime;
}
void light(void)
{
rectangle(535,65,565,155);
/*floodfill(545,100,BLUE);*/
setfillstyle(1,RED);
fillellipse(550,80,10,10);
sound(650);
delay(300);
nosound();
delay(100);
setfillstyle(1,YELLOW);
fillellipse(550,110,10,10);
sound(650);
delay(300);
nosound();
delay(100);
setfillstyle(1,GREEN);
fillellipse(550,140,10,10);
sound(650);
delay(300);
nosound();
delay(100);
setcolor(10);
setlinestyle(SOLID_LINE,0,3);
rectangle(150,400,450,460);
outtextxy(160,410,"Ready,Begin!"
;}
[ Last edited by GOTOmsdos on 2005-10-22 at 00:35 ]
Attachments



