弹跳球源代码.docx
- 文档编号:24121013
- 上传时间:2023-05-24
- 格式:DOCX
- 页数:9
- 大小:15.49KB
弹跳球源代码.docx
《弹跳球源代码.docx》由会员分享,可在线阅读,更多相关《弹跳球源代码.docx(9页珍藏版)》请在冰豆网上搜索。
弹跳球源代码
#include"stdio.h"
#include"graphics.h"
#include"stdlib.h"
#include"bios.h"
#defineLEFT0x4b00
#defineRIGHT0x4d00
#defineESC0x011b
/*存放方块的信息*/
structbox
{
intm;/*方块右上角横坐标*/
intn; /*方块右上角纵坐标*/
intkey; /*方块是否被击中过,1表示被击中过,0表示没有被击中过*/
}a[10][20];
intk; /*用来判断游戏的结束方式,0:
按ESC退出,1:
正常退出*/
/*初始化图形*/
voidinitgr()
{
intgd=DETECT,gm;
initgraph(&gd,&gm,"");
}
/*画出初始图*/
voidpicture()
{intm,n,i,color;
setcolor(GREEN);
outtextxy(0,0,"ANYKEY...");
while(!
kbhit())
{
settextstyle(0,0,6);
for(i=1;i<=15;i++)
{setcolor(i);
outtextxy(150,180,"hello");
delay(1000000);
}}
cleardevice();
setbkcolor(WHITE);
setfillstyle(SOLID_FILL,RED);
bar(300,400,348,404);
/*画屏幕上端的方块*/
randomize();
for(n=0;n<=150;n=n+15)
for(m=0;m<=640;m=m+32)
{color=((rand()%5)+2);
setfillstyle(1,color);
bar(m,n,m+32,n+15);
}
sleep
(1);
}
/*关闭图形*/
voidclosegr()
{
cleardevice();
closegraph();
}
/*游戏结束*/
voidend()
{
cleardevice();
setbkcolor(3);
switch(k)
{
case1:
setcolor(RED);
settextstyle(0,0,4);
outtextxy(130,200,"YOUAREFALUIRE");
sleep
(1);
cleardevice();
settextstyle(0,0,7);
outtextxy(80,220,"Again");
sleep
(2);
break;
case0:
setcolor(RED);
settextstyle(0,0,4);
outtextxy(180,220,"GameOver");
sleep
(2);
break;
}
}
/*爆裂效果*/
voidbomb(intm,intn)
{
intr1,i;
intpointM,pointN,point_color;
setcolor(YELLOW);
for(r1=1;r1<=4;r1++)
{
circle(m+1,n+1,r1);
delay(1000000);
}
delay(3000000);
setcolor(RED);
for(r1=1;r1>=6;r1++)
{
circle(m+1,n+1,r1);
delay(1000000);
}
delay(3000000);
setcolor(BLUE);
for(r1=6;r1>=1;r1--)
{
circle(m+1,n+1,r1);
delay(1000000);
}
for(i=1;i<=50;i++)
{
point_color=rand()%15;
pointM=(rand()%32+m);
pointN=(rand()%15+n);
putpixel(pointM,pointN,point_color);
delay(1000000);
}
setfillstyle(1,BLUE);
bar(m,n,m+32,n+15);
}
/*开始游戏*/
voidmove()
{
intkey;
inti,j,boxM,boxN;
intballM,ballN,dM=1,dN=1;
intbarM=300,barN=400,m,n;
randomize();
ballM=rand()%620+10;
ballN=rand()%200+190;
for(;;) /*受侦察的指点....*/
{
/*小球的运动*/
while(!
kbhit())
{
if((ballM<=10)||(ballM>=630))
dM=dM*(-1);
if((ballN<=10)||(ballN>=470))
dN=dN*(-1);
setcolor(YELLOW);
circle(ballM+=dM,ballN-=dN,5);
setfillstyle(SOLID_FILL,YELLOW);
floodfill(ballM,ballN,YELLOW);
delay(6666);
setcolor(BLUE);
circle(ballM,ballN,5);
setfillstyle(SOLID_FILL,BLUE);
floodfill(ballM,ballN,BLUE);
/*判断是否击中方块*/
for(boxN=0,i=0;boxN<=150;boxN=boxN+15,i++)
for(boxM=0,j=0;boxM<=640;boxM=boxM+32,j++)
{
if((ballM
{
dN=dN*(-1);
setfillstyle(1,BLUE);
bar(boxM,boxN,boxM+32,boxN+15);
bomb(boxM,boxN);
a[i][j].key=1;
break;
}
}
/*判断反弹或出界*/
if((ballM>=barM)&&(ballM<=barM+60)&&(ballN>=390))
dN=dN*(-1);
if(((ballM
{
sleep
(1);
k=1;
return;
}
}
/*球拍的运动*/
key=bioskey(0);
m=barM;
n=barN;
if(key==LEFT)
{
barM-=66;
setfillstyle(SOLID_FILL,BLUE);
bar(m,n,m+60,n+4);
setfillstyle(SOLID_FILL,RED);
bar(barM,barN,barM+60,barN+4);
}
elseif(key==RIGHT)
{
barM+=66;
setfillstyle(SOLID_FILL,BLUE);
bar(m,n,m+60,n+4);
setfillstyle(SOLID_FILL,RED);
bar(barM,barN,barM+60,barN+4);
}
elseif(key==ESC)
{
k=0;
break;
}
}
}
voidmain()
{
inti,j,m,n;
for(i=0,n=0;i<10;i++)
{
m=0;
for(j=0;j<20;j++)
{
a[i][j].m=m;
a[i][j].n=n;
a[i][j].key=0;
m=m+32;
}
n=n+15;
}
initgr();
picture();
move();
end();
closegr();
}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 弹跳 源代码