- 论坛徽章:
- 0
|
第一次用C写了游戏,心里高兴
/* This game from Cplusultra !!!*/
#include <graphics.h>;
#include <stdlib.h>;
void car();
void load();
void rock();
void endloss();
void endhappy();
void start();
char t;
int rx1,rx2;
int ry1,ry2;
int r;
int hard;
void main()
{
int gdriver=DETECT,gmode;
start();
randomize();
registerbgidriver(EGAVGA_driver);
initgraph(&gdriver,&gmode,"" ;
rx1=175; ry1=-100;
rx2=265; ry2=-10;
r=rand()%3;
hard=0;
setbkcolor(7);
load();
car();
closegraph();
getch();
}
void car()
{
int temp=1;
int x1,x2,x3,x4;
x1=280; x2=360;
x3=305; x4=335;
setwritemode(XOR_PUT);
setcolor(BLUE);
setlinestyle(SOLID_LINE,0,3);
rectangle(x1,370,x2,400);
rectangle(x1,430,x2,460);
rectangle(x3,340,x4,460);
line(x3,460,x4,460);
do
{
if(x1==180) temp=0;
else if(x1==280) temp=1;
else if(x1==380) temp=2;
do
{
if(
( (ry1>;=340 && ry1<=460) && (temp==r) )
||
( (ry2>;=340 && ry2<=460) && (temp==r) )
)
endloss();
rock();
}while(bioskey(1)==0);
t=bioskey(0);
if( (t=='a' || t=='A') && x1>;180)
{
rectangle(x1,370,x2,400);
rectangle(x1,430,x2,460);
rectangle(x3,340,x4,460);
line(x3,460,x4,460);
x1-=100; x2-=100;
x3-=100; x4-=100;
rectangle(x1,370,x2,400);
rectangle(x1,430,x2,460);
rectangle(x3,340,x4,460);
line(x3,460,x4,460);
}
else if( (t=='d' || t=='D') && x1<380)
{
rectangle(x1,370,x2,400);
rectangle(x1,430,x2,460);
rectangle(x3,340,x4,460);
line(x3,460,x4,460);
x1+=100; x2+=100;
x3+=100; x4+=100;
rectangle(x1,370,x2,400);
rectangle(x1,430,x2,460);
rectangle(x3,340,x4,460);
line(x3,460,x4,460);
}
else if(t=='q' || t=='Q')
{
closegraph();
exit(0);
}
else;
}while(1);
}
void load()
{
int i;
setwritemode(XOR_PUT);
setcolor(WHITE);
for(i=0;i<4;i++)
line(170+i*100,0,170+i*100,479);
for(i=0;i<3;i++)
{
setlinestyle(3,0,1);
line(220+i*100,-100,220+i*100,479);
}
}
void rock()
{
setlinestyle(SOLID_LINE,0,3);
setcolor(BLUE);
if(hard>;=0 && hard<5) {ry1+=2; ry2+=2;}
else if(hard>;=5 && hard<10) {ry1+=3; ry2+=3;}
else if(hard>;=10 && hard<20) {ry1+=4; ry2+=4;}
else if(hard>;=20 && hard<30) {ry1+=5; ry2+=5;}
else if(hard>;=30 && hard<35) {ry1+=6; ry2+=6;}
else if(hard==35) endhappy();
if(ry1>;=650)
{
ry1=-100;
ry2=-10;
r=rand()%3;
hard++;
}
rectangle(r*100+rx1,ry1,r*100+rx2,ry2);
line(r*100+rx1,ry1,r*100+rx2,ry2);
line(r*100+rx2,ry1,r*100+rx1,ry2);
delay(100);
rectangle(r*100+rx1,ry1,r*100+rx2,ry2);
line(r*100+rx1,ry1,r*100+rx2,ry2);
line(r*100+rx2,ry1,r*100+rx1,ry2);
}
void endhappy()
{
closegraph();
printf("You Win !!!\n" ;
printf(" lease press any key to out game\n" ;
getch();
exit(0);
}
void endloss()
{
closegraph();
printf("You loss !!!\n" ;
printf(" lease press any key to out game\n" ;
getch();
exit(0);
}
void start()
{
printf("This game from Cplusultra.\n" ;
printf("QQ:170373161\n" ;
printf("Email:Cplusultra@126.com\n" ;
printf("\n\nPlease press any key to play game.\n" ;
getch();
} |
|