资源描述:
《打砖块JAVA游戏代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#include#include#include#includevoiddraw(intx1){intm=0,n=0,x=40,y=20;intt=0,i,j,k=1;inta=0,b=127,c=88;for(i=0;i<8;i++){n=i*20;y=n+20;for(j=0;j<16-t;j++){m=(j+i)*40;x=m+40;POINTpoints[]={{m,n},{x,n},{x,y},{m,y}};setfillcolor(RG
2、B(a,b,c));fillpolygon(points,4);a=8*k+8;b=j*3+k+200;c=20*k;k=k+8;}t=t+2;k=1;}m=300;n=160;x=340;y=180;POINTpoints[]={{m,n},{x,n},{x,y},{m,y}};setfillcolor(RGB(a,b,c));fillpolygon(points,4);}voidend(){settextstyle(50,0,"宋体",0,0,FW_BOLD,false,false,false);settextcolor(RED);outtextxy(200,
3、200,"游戏结束!");getch();closegraph();}voidstart(){intn=0;loadimage(NULL,"IMSGE","background");while(1){setbkmode(TRANSPARENT);settextstyle(50,0,"楷体",0,0,FW_BOLD,false,false,false);if(n%2==0)settextcolor(GREEN);elsesettextcolor(RED);outtextxy(80,100,"请按空格键开始游戏");Sleep(250);if(_kbhit())bre
4、ak;n++;}}voidmain(){intx=320,y=430,m=270,n=370;inta,b,c,e=0,f=0,g=0,k[3];inti,j;chard;initgraph(640,480);start();setbkcolor(WHITE);cleardevice();setlinecolor(WHITE);draw(1);while(1){setlinecolor(LIGHTBLUE);setlinestyle(PS_SOLID,10);line(m,445,n,445);setlinestyle(PS_SOLID,0);setlinecol
5、or(WHITE);setfillcolor(BROWN);fillcircle(x,y,10);Sleep(60);setfillcolor(WHITE);fillcircle(x,y,10);if(_kbhit()){d=getch();setlinecolor(WHITE);setlinestyle(PS_SOLID,10);line(m,445,n,445);if(n<640&&d=='d'){m=m+27;n=n+27;}elseif(m>0&&d=='a'){m=m-27;n=n-27;}}//确定x,y的值//if(y>=435)end();if(y
6、==430&&x>=m-5&&x<=n+5){if(x>m&&x<=m+25){a=0;b=2;c=2;if(10/(x-m)==0)k[0]=2;elseif(10/(x-m)>3)k[0]=3;elsek[0]=10/(x-m);}elseif(x>m+25&&x<=m+55){a=2;b=0;c=2;if(15/(x-m-25)==0)k[1]=2;elseif(15/(x-m-25)>3)k[1]=3;elsek[1]=10/(x-m-25);}elseif(x>m+55&&x<=n){a=2;b=2;c=0;if(10/(x-m-55)==0)k[2]=
7、2;elseif(10/(x-m-55)>3)k[2]=3;elsek[2]=10/(x-m-55);}}if(1){if(e==0){y=y-10;if(y<=10){g=1-g;e=1;}if(getpixel(x-1,y-10)!=WHITE
8、
9、getpixel(x-1,y+10)!=WHITE
10、
11、getpixel(x+1,y-10)!=WHITE
12、
13、getpixel(x+1,y+10)!=WHITE){e=1;setfillcolor(WHITE);for(i=8;i<=18;i++){for(j=8;j<=18;j++){floodfill(x-i,y-
14、j,WHI