《擋板球(小游戲)》由會員分享,可在線閱讀,更多相關《擋板球(小游戲)(5頁珍藏版)》請在裝配圖網(wǎng)上搜索。
1、#include
#include
#include
#include
#include
#include
#include
#include
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define ESC 0x11b
#define Enter 0x1c0d
unsigned long int flag[11][10]={0},score=0;
enum spd
{ s1=10,
2、 s2=8,s3=6,s4=4,s5=2,s6=0
}gamespeed;
void chose()
{int i; textmode(2);
printf("\n\n\n\n Please Input The Speed You Want(from 1 to 6):");
scanf("%d",&i);
switch(i)
{ case 1: gamespeed=s1;printf("
Thank
You!!
Wish
You
Have
A
Happy
Day");for(;!kbhit();); break;
case 2: gamespeed=s2;pri
3、ntf("
Thank
You!!
Wish
You
Have
A
Happy
Day");for(;!kbhit();); break;
case 3: gamespeed=s3;printf("
Thank
You!!
Wish
You
Have
A
Happy
Day");for(;!kbhit();); break;
case 4: gamespeed=s4;printf("
Thank
You!!
Wish
You
Have
A
Happy
Day");for(;!kbhit();); break;
case 5: gamespe
4、ed=s5;printf("
Thank
You!!
Wish
You
Have
A
Happy
Day");for(;!kbhit();); break;
case 6: gamespeed=s6;printf("
Thank
You!!
Wish
You
Have
A
Happy
Day");for(;!kbhit();); break;
default: printf(" Oh!! My God! Please Check The Number! Is it bewtten 1 and 6 ??");for(;!kbhit(););exit(0);
5、
} } int init()
{ auto int gdriver=DETECT,gmode,i,j;
/* registerbgifont(); */ registerbgidriver(EGAVGA_driver);
initgraph(&gdriver,&gmode,"E:\\tcpp\\bgi"); setbkcolor(9);setcolor(5);setlinestyle(0,0,3);
for(i=0;i<=10;i++)
{ int c=i;if(c==9)c=3;
for(j=0;j<=9;j++)
{ setfillstyle(1,c);c++;if(c=
6、=9)c=6; rectangle(j*60+15,20*i,60*j+75,20*i+20),flag[i][j]=1;
floodfill(j*60+20,20*i+10,5);
}
}setfillstyle(1,15);floodfill(20,10,5);floodfill(380,210,5);
setlinestyle(0,0,1);
setfillstyle(1,BLUE);
rectangle(50,460,110,480);floodfill(60,470,5); return 0;
}
int daba()
{ static int x=50;
if(
7、!kbhit())return 0;
else
{int key;
key=bioskey(0);
switch(key)
{ case LEFT:setfillstyle(1,9);floodfill(x+10,470,5);setcolor(9);rectangle(x,460,x+60,480); setcolor(5);setfillstyle(1,BLUE);
if(x<=9){rectangle(0,460,60,480);floodfill(40,470,5);x=0;}else{rectangle(x-10,460,x+50,480 );floodfill(x+20
8、,470,5);x-=10;}return 1;
case RIGHT:setfillstyle(1,9);floodfill(x+10,470,5);setcolor(9);rectangle(x,460,x+60,480); setcolor(5);setfillstyle(1,BLUE);
if(x>=579){rectangle(579,460,639,480);floodfill(600,470,5);x=579;}else{rectangle(x+10,46 0,x+70,480);floodfill(x+30,470,5);x+=10; }return 1;
case ES
9、C: return 2;
default: return 0;
}
}
return 0;
}
int Juge(int &direction,int x,int y)
{int i,j,k;
if(y>=240) return 0;
switch(direction)
{ case 1: for(k=0;k<=10&&fabs(y-41-20*k)>=3;k++);i=k;if(i==11)return 0;for(k=0;k<=9&&!(x>=60*k-5&&x<=60*k+95);k++);j=k;
if(flag[i][j]==1){setlinestyle(0,
10、0,3);setcolor(9);setfillstyle(1,9);floodfill(60*j+20,20*i+10,5);recta ngle(60*j+15,20*i,60*j+75,20*i+20);score+=1;setcolor(5);
if(j>=1&&flag[i][j-1]!=0)rectangle(60*j+15-60,20*i,60*j+15,20*i+20);if(j==0&&flag[i][j+1]!=0) rectangle(15,20*i,75,20*i+20);if(j==9&&flag[i][j-1]!=0)rectangle(60*9+15,20*i,
11、60*9+75,20*i+2 0);if(j<=8&&flag[i][j+1]!=0)rectangle(60*j+75,20*i,60*j+75+60,20*i+20);if(i>=1&&flag[i-1][j]!
=0)rectangle(60*j+15,20*i-20,60*j+75,20*i);flag[i][j]=0;direction=-2;return 1;} else if(flag[i][j-1]==0)return 0;else if(x>=60*j+15+8)return 0;else{direction=-2;return 1;}
case 2: for(k=0;k
12、<=10&&fabs(y-41-20*k)>=3;k++);i=k;if(i==11)return 0;for(k=0;k<=9&&!(x>=60*k-5&&x<=60*k+95);k++);j=k; if(flag[i][j]==1){setlinestyle(0,0,3);score+=1;setcolor(9);setfillstyle(1,9);floodfill(60*j+20,20*i+1 0,5);rectangle(60*j+15,20*i,60*j+75,20*i+20);flag[i][j]=0;direction=-1;setcolor(5);if(j==0&&fla g
13、[i][j+1]!=0)rectangle(15,20*i,75,20*i+20);if(j==9&&flag[i][j-1]!=0)rectangle(60*9+15,20*i,60* 9+75,20*i+20);if(j>=1&&flag[i][j-1]!=0)rectangle(60*j+15-60,20*i,60*j+15,20*i+20);if(j<=8& &flag[i][j+1]!=0)rectangle(60*j+75,20*i,60*j+75+60,20*i+20);if(i>=1&&flag[i-1][j]!=0)rectangl e(60*j+15,20*i-20,60*
14、j+75,20*i); return 1;} else if(flag[i][j+1]==0)return 0;else if(x<=60*j+15-8)return 0;else{direction=-1;return 1;}
case -1:for(k=2;k<=10&&fabs(y+20-20*k)>=2;k++);i=k;if(i==11)return 0;for(k=0;k<=9&&!(x>=60*k-5&&x<=60*k+95);k++);j=k; if(flag[i][j]==1){setlinestyle(0,0,3);setcolor(9);setfillstyle(1,9
15、);floodfill(60*j+20,20*i+10,5);recta ngle(60*j+15,20*i,60*j+75,20*i+20);score+=1;setcolor(5); if(j>=1&&flag[i][j-1]!=0)rectangle(60*j+15-60,20*i,60*j+15,20*i+20);if(j==0&&flag[i][j+1]!=0) rectangle(15,20*i,75,20*i+20);if(j==9&&flag[i][j-1]!=0)rectangle(60*9+15,20*i,60*9+75,20*i+2 0);if(j<=8&&flag[i]
16、[j+1]!=0)rectangle(60*j+75,20*i,60*j+75+60,20*i+20);if(i<=8&&flag[i+1][j] !=0)rectangle(60*j+15,20*i-20,60*j+75,20*i); flag[i][j]=0;direction=2;return 1; } else if(flag[i][j+1]==0&&flag[i][j-1]==0)return 0;else if(x<=60*i+15-68)return 0;else {direction=2;return 1;}
case -2:for(k=2;k<=10&&fabs(y+20-
17、20*k)>=2;k++);i=k;if(i==11)return 0;for(k=0;k<=9&&!(x>=60*k-5&&x<=60*k+95);k++);j=k; if(flag[i][j]==1){setlinestyle(0,0,3);setcolor(9);setfillstyle(1,9);floodfill(60*j+20,20*i+10,5);recta ngle(60*j+15,20*i,60*j+75,20*i+20);score+=1;setcolor(5); if(j>=1&&flag[i][j-1]!=0)rectangle(60*j+15-60,20*i,60*j
18、+15,20*i+20);if(j==0&&flag[i][j+1]!=0) rectangle(15,20*i,75,20*i+20);if(j==9&&flag[i][j-1]!=0)rectangle(60*9+15,20*i,60*9+75,20*i+2 0);if(j<=8&&flag[i][j+1]!=0)rectangle(60*j+75,20*i,60*j+75+60,20*i+20);if(i<=8&&flag[i+1][j] !=0)rectangle(60*j+15,20*i-20,60*j+75,20*i); flag[i][j]=0;direction=2;retur
19、n 1; } else if(flag[i][j+1]==0&&flag[i][j-1]==0)return 0;else if(x<=60*i+15-68)return 0;else {direction=2;return 1;}
} return 0;
}
int play()
{int key,x=50,x0=80,y0=436,direction;char *s; void*buf1;randomize();direction=rand()%1+1;
setcolor(5);circle(x0,y0,20);setfillstyle(1,8);floodfill(x0,y0,
20、5); buf1=malloc(imagesize(59,415,102,458));getimage(59,415,102,458,buf1);
while(1)
{ while(!kbhit())
{swi:switch(direction)
{ case 1:for(;y0>=21&&x0>=21;x0--,y0--) {if(kbhit())goto loop;delay(gamespeed);
if(Juge(direction,x0,y0)!=0)goto swi; putimage(x0-22,y0-22,buf1,0);
}x0++,y0++;if(x0==21)d
21、irection=2;else direction=-2;break;
case 2:for(;x0<=617&&y0>=21;x0++,y0--) {if(kbhit())goto loop;delay(gamespeed);
if(Juge(direction,x0,y0)!=0)goto swi; putimage(x0-22,y0-22,buf1,0);
}x0--,y0++;if(x0==617)direction=1;else direction=-1; break;
case -1:for(;x0<=617&&y0<=436;x0++,y0++)
{if(kbhit()
22、)goto loop;delay(gamespeed); if(Juge(direction,x0,y0)!=0)goto swi;
putimage(x0-22,y0-22,buf1,0);
}x0--,y0--;if(y0==436){if(x0+20>=x&&x0-20<=x+60)direction=2;else{ for(;y0<=500;y0
++,x0++){delay(gamespeed); putimage(x0-22,y0-22,buf1,0);} return 0;} }else direction=-2; break;
case -2:for(;x0>=21&&
23、y0<=436;x0--,y0++) {if(kbhit())goto loop;delay(gamespeed);
if(Juge(direction,x0,y0)!=0)goto swi; putimage(x0-22,y0-22,buf1,0);
}x0++,y0--;if(y0==436){if(x0+20>=x&&x0-20<=x+60) direction=1;else{ for(;y0<=500;y0++,x0--){delay(gamespeed); putimage(x0-22,y0-22,buf1,0);}
return 0;} }else direction=-1;
24、 break;
}
}loop: key=bioskey(0);
switch(key)
{ case LEFT:setfillstyle(1,9);floodfill(x+10,470,5);setcolor(9);rectangle(x,460,x+60,480);bar(x,460,x+60 ,480);
setcolor(5);setfillstyle(1,BLUE); if(x<=9){sprintf(s,"%d",score);outtextxy(10,470,s); rectangle(0,460,60,480);floodfill(40,470,5);x=0;}els
25、e{sprintf(s,"%d",score);outtextxy(x,470,s); rectangle(x-10,460,x+50,480);floodfill(x+20,470,5);x-=10;}break;
case RIGHT:setfillstyle(1,9);floodfill(x+10,470,5);setcolor(9);rectangle(x,460,x+60,480);bar(x,460,x+ 60,480);
setcolor(5);setfillstyle(1,BLUE); if(x>=579){sprintf(s,"%d",score);outtextxy(5
26、89,470,s);
rectangle(579,460,639,480);floodfill(600,470,5);x=579;}else{sprintf(s,"%d",score);outtextxy(x+2 0,470,s);rectangle(x+10,460,x+70,480);floodfill(x+30,470,5);x+=10; }break;
case ESC: break;
default: break;
}if(key==ESC)break;
}return 0;
int main()
{ chose();
init();
play();
getch(); closegraph();
return 0;
}