打砖块c语言源代码,打砖块游戏的源代码(请多指教)
Posted weixin_39890543
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了打砖块c语言源代码,打砖块游戏的源代码(请多指教)相关的知识,希望对你有一定的参考价值。
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include#include#include#include#includevoid draw(int x1){int m=0,n=0,x=40,y=20;int t=0,i,j,k=1;int a=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;int points[]={m,n,x,n,x,y,m,y}; setfillstyle(RGB(a,b,c)); fillpoly(4,points);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;int points[]={m,n,x,n,x,y,m,y};setfillstyle(RGB(a,b,c)); fillpoly(4,points);}void end(){setfont(50, 0, "宋体", 0, 0, FW_BOLD, false, false, false);setcolor(RED);outtextxy(200,200,"游戏结束!");getch();closegraph();}void start(){int n=0;loadimage(NULL,"IMSGE","background");while(1){setbkmode(TRANSPARENT);setfont(50, 0, "楷体", 0, 0, FW_BOLD, false, false, false);if(n%2==0)setcolor(GREEN);else setcolor(RED);outtextxy(80,100,"请按空格键开始游戏");Sleep(250);if(_kbhit())break;n++;}}void main(){int x=320,y=430,m=270,n=370;int a,b,c,e=0,f=0,g=0,k[3];int i,j;char d;initgraph(640,480);start();setbkcolor(WHITE);cleardevice();setcolor(WHITE);draw(1);while(1){setcolor(LIGHTBLUE); setlinestyle(PS_SOLID, NULL, 10); line(m,445,n,445);setlinestyle(PS_SOLID, NULL, 0);setcolor(WHITE);setfillstyle(BROWN);fillcircle(x,y,10);Sleep(60);setfillstyle(WHITE);fillcircle(x,y,10);if(_kbhit()){d=getch(); setcolor(WHITE); setlinestyle(PS_SOLID, NULL, 10); line(m,445,n,445);if(n<640&&d=='d'){m=m+27;n=n+27;}else if(m>0&&d=='a'){m=m-27;n=n-27;}}//确定x,y的值//if(y>=435)end();if(y==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;else if(10/(x-m)>3)k[0]=3;else k[0]=10/(x-m);}else if(x>m+25&&x<=m+55){a=2;b=0;c=2;if(15/(x-m-25)==0)k[1]=2;else if(15/(x-m-25)>3)k[1]=3;else k[1]=10/(x-m-25);}else if(x>m+55&&x<=n){a=2;b=2;c=0;if(10/(x-m-55)==0)k[2]=2;else if(10/(x-m-55)>3)k[2]=3;else k[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||getpixel(x-1,y+10)!=WHITE||getpixel(x+1,y-10)!=WHITE||getpixel(x+1,y+10)!=WHITE){ e=1; setfillstyle(WHITE); for(i=8;i<=18;i++){ for(j=8;j<=18;j++){ floodfill(x-i,y-j,WHITE); floodfill(x+i,y-j,WHITE); floodfill(x-i,y+j,WHITE); floodfill(x+i,y+j,WHITE);}}}}else if(e==1){y=y+10;if(getpixel(x-1,y-14)!=WHITE||getpixel(x-1,y+14)!=WHITE||getpixel(x+1,y-14)!=WHITE||getpixel(x+1,y+14)!=WHITE){e=0;setfillstyle(WHITE);for(i=8;i<=18;i++){for(j=8;j<=18;j++){floodfill(x-i,y-j,WHITE);floodfill(x+i,y-j,WHITE);floodfill(x-i,y+j,WHITE);floodfill(x+i,y+j,WHITE);}}}else if(y==430&&x>=m-5&&x<=n+5)e=0;}if(g==0&&a==0){x=x-k[0]*5;if(y<=10)g=1-g;else if(x<=10||x>=630)g=1;if(getpixel(x-1,y-10)!=WHITE||getpixel(x-1,y+10)!=WHITE||getpixel(x+1,y-10)!=WHITE||getpixel(x+1,y+10)!=WHITE){g=1;setfillstyle(WHITE);for(i=8;i<=18;i++){for(j=8;j<=18;j++){floodfill(x-i,y-j,WHITE);floodfill(x+i,y-j,WHITE);floodfill(x-i,y+j,WHITE);floodfill(x+i,y+j,WHITE);}}}}else if(g==1&&a==0){x=x+k[0]*5;if(y<=10)g=1-g;else if(x<=10||x>=630)g=0;else if(getpixel(x-1,y-10)!=WHITE||getpixel(x-1,y+10)!=WHITE||getpixel(x+1,y-10)!=WHITE||getpixel(x+1,y+10)!=WHITE){g=0;setfillstyle(WHITE);for(i=10;i<=18;i++){for(j=10;j<=18;j++){floodfill(x-i,y-j,WHITE);floodfill(x+i,y-j,WHITE);floodfill(x-i,y+j,WHITE);floodfill(x+i,y+j,WHITE);}}}}if(g==0&&b==0){x=x-k[1]*2;if(y<=10)g=1-g;else if(x<=10||x>=630)g=1;else if(getpixel(x-1,y-10)!=WHITE||getpixel(x-1,y+10)!=WHITE||getpixel(x+1,y-10)!=WHITE||getpixel(x+1,y+10)!=WHITE){g=1;setfillstyle(WHITE);for(i=8;i<=18;i++){for(j=8;j<=18;j++){floodfill(x-i,y-j,WHITE);floodfill(x+i,y-j,WHITE);floodfill(x-i,y+j,WHITE);floodfill(x+i,y+j,WHITE);}}}}else
以上是关于打砖块c语言源代码,打砖块游戏的源代码(请多指教)的主要内容,如果未能解决你的问题,请参考以下文章
手把手教学弟用js写的打砖块游戏,学弟乐哉~ 附(思路注释+源码)
手把手教学弟用js写的打砖块游戏,学弟乐哉~ 附(思路注释+源码)