C语言实现宾果消消乐
本文实例为大家分享了C语言宾果消消乐的具体代码,供大家参考,具体内容如下
```c #include#include #include #include #include #include #defineMAPSIZE10 intmap[MAPSIZE][MAPSIZE]; intmap2[MAPSIZE][MAPSIZE]; boolstate[MAPSIZE][MAPSIZE]; boolstate1[MAPSIZE][MAPSIZE]; typedefstructgame { intgame_state; intcounts; intscore; inttargets; intlevel; intstate; intlevel_state; inttool_number; inttool_state; intstart_state; PIMAGEimg[21]; }Game; Gamegame; inthigh=0; voidinit_img() { inti; for(i=0;i<21;i++) game.img[i]=newimage(); getimage(game.img[0],"game\\underground.jpg"); getimage(game.img[1],"game\\red.jpg"); getimage(game.img[2],"game\\green.jpg"); getimage(game.img[3],"game\\blue.jpg"); getimage(game.img[4],"game\\orange.jpg"); getimage(game.img[5],"game\\purple.jpg"); getimage(game.img[6],"game\\brown.jpg"); getimage(game.img[7],"game\\123.jpg"); getimage(game.img[8],"game\\end.jpg"); getimage(game.img[9],"game\\bomb.jpg"); getimage(game.img[10],"game\\win.png"); getimage(game.img[11],"game\\hon.jpg"); getimage(game.img[12],"game\\lu.jpg"); getimage(game.img[13],"game\\lan.jpg"); getimage(game.img[14],"game\\cheng.jpg"); getimage(game.img[15],"game\\zi.jpg"); getimage(game.img[16],"game\\hui.jpg"); getimage(game.img[17],"game\\receive.png"); getimage(game.img[18],"game\\in.jpg"); getimage(game.img[19],"game\\black.jpg"); getimage(game.img[20],"game\\start.jpg"); } voidinit_map() { inti,j; srand(time(0)); for(i=0;i high) { high=game.score; save(&high); } putimage(0,0,game.img[0]); setfont(30,0,"隶书"); setcolor(EGERGB(250,210,0)); setbkmode(TRANSPARENT); outtextxy(10,15,"最高记录:"); outtextxy(10,55,"关卡:"); outtextxy(150,55,"目标分:"); sprintf(str,"%4d",game.level); sprintf(str1,"%4d",high); sprintf(str2,"%4d",game.targets); sprintf(scores,"%4d",game.score); sprintf(str3,"%d",game.tool_number); setcolor(EGERGB(255,255,255)); outtextxy(60,55,str); outtextxy(150,15,str1); outtextxy(260,55,str2); outtextxy(205,102,scores); setfont(25,0,"隶书"); outtextxy(410,1,str3); } voidshow_map() { if(game.level_state==1) show_level(); show_word(); inti,j; for(i=0;i =MAPSIZE||y<0||y>=MAPSIZE||state[y][x]) return0; else return1; } //搜索周围相同颜色 voidsearch_map(intx,inty,inttarget) { if((!avaliable(x,y))||map[y][x]!=target) return; state[y][x]=true; state1[y][x]=true; game.counts++; search_map(x-1,y,target); search_map(x+1,y,target); search_map(x,y-1,target); search_map(x,y+1,target); } //搜索到相同颜色后调整位置 voidadjust_map() { inti,j,r,k; inttemp[10][10]; for(j=MAPSIZE-1;j>=0;j--) { intm=0; intflag=1; k=j; for(i=MAPSIZE-1;i>=0;i--) if(state[i][j]==false) flag=0; if(flag==1) { if(k==MAPSIZE-1) continue; while(1) { if(k==MAPSIZE-1) break; for(i=MAPSIZE-1;i>=0;i--) { map[i][k]=map[i][k+1]; state[i][k]=state[i][k+1]; state[i][k+1]=true; } k++; } } for(i=MAPSIZE-1;i>=0;i--) if(!state[i][j]) { temp[m][j]=map[i][j]; m++; } r=MAPSIZE-1; for(i=0;i =0;r--) { state[r][j]=true; } } } //判断是否通过本关 intend_map() { inti,j,target; intx; inty; intflag=1; for(i=0;i 105&&ms.x<230&&ms.y>380&&ms.y<425) { musicc(); return0; } if(ms.x>240&&ms.x<370&&ms.y>380&&ms.y<420) { musicc(); return1; } } } Sleep(500); } } //点击要炸裂的某一列 voidbomb_map() { inti; intx,y; mouse_msgmsg; while(1) { show_map(); while(mousemsg()) { msg=getmouse(); if(msg.is_left()&&msg.is_down()) { musicc(); x=msg.x/45; y=(msg.y-250)/45; if(!avaliable(x,y)) continue; for(i=0;i 400&&msg.x<450&&msg.y>=40&&msg.y<100&&game.tool_number>=5)//使用炸弹 { musicp(); if(bomb_pop()) { bomb_map(); musicb(); adjust_map(); game.score=game.score+game.counts*20; game.tool_number=game.tool_number-5; show_map(); game.counts=0; } } else { x=msg.x/45; y=(msg.y-250)/45; if(!avaliable(x,y)) continue; target=map[y][x]; if((avaliable(x+1,y)&&map[y][x+1]==target)||(avaliable(x-1,y)&&map[y][x-1]==target) ||(avaliable(x,y-1)&&map[y-1][x]==target)||(avaliable(x,y+1)&&map[y+1][x]==target)) { search_map(x,y,target); game.score=game.score+game.counts*20; if(game.counts>=6) { game.tool_number=game.tool_number+3; musicu(); } flash_map(target); adjust_map(); } game.counts=0; show_map(); Sleep(100); state1_back(); if(end_map()) { if(game.score>=game.targets) { musicsheng(); game.game_state=2; return; } elseif(game.score 170&&ms.x<300&&ms.y>380&&ms.y<420) { musicc(); game.tool_number=10; game.tool_state=0; return; } } } Sleep(500); } } //游戏指南界面 voidinter_game() { mouse_msgms; while(1) { putimage(0,0,game.img[18]); while(mousemsg()) { ms=getmouse(); if(ms.is_left()&&ms.is_down()) { musicc(); game.game_state=0; return; } } Sleep(500); } } voidstart_game() { mouse_msgms; if(game.start_state==1) { putimage(0,0,game.img[19]); Sleep(500); putimage(0,0,game.img[20]); Sleep(500); game.start_state=0; } while(1) { putimage(0,0,game.img[7]); while(mousemsg()) { ms=getmouse(); if(ms.is_left()&&ms.is_down()) { musicc(); if(ms.x>140&&ms.x<310&&ms.y>370&&ms.y<410) { if(game.tool_state==1) { musicp(); get_tool(); } game.game_state=1; game.level_state=1; return; } if(ms.x>140&&ms.x<310&&ms.y>420&&ms.y<460) { game.game_state=3; return; } if(ms.x>140&&ms.x<310&&ms.y>470&&ms.y<500) { game.game_state=5; return; } } } Sleep(500); } } voidfail_again() { inti,j; inttarget; intx,y; intflag=0; mouse_msgmsg; for(i=0;i 400&&msg.x<450&&msg.y>=40&&msg.y<100&&game.tool_number>=5) { musicp(); if(bomb_pop()) { bomb_map(); musicb(); adjust_map(); game.score=game.score+game.counts*20; game.tool_number=game.tool_number-5; show_map(); game.counts=0; } } else { x=msg.x/45; y=(msg.y-250)/45; if(!avaliable(x,y)) continue; target=map[y][x]; if((avaliable(x+1,y)&&map[y][x+1]==target)||(avaliable(x-1,y)&&map[y][x-1]==target) ||(avaliable(x,y-1)&&map[y-1][x]==target)||(avaliable(x,y+1)&&map[y+1][x]==target)) { search_map(x,y,target); game.score=game.score+game.counts*20; if(game.counts>=6) { game.tool_number=game.tool_number+3; musicu(); } flash_map(target); adjust_map(); } game.counts=0; show_map(); Sleep(100); state1_back(); if(end_map()) { if(game.score>=game.targets) { musicsheng(); game.game_state=2; return; } elseif(game.score 115&&msg.x<222&&msg.y>400&&msg.y<430) { musicc(); game.game_state=0; game.state=0; game.level=1; game.targets=1500; game.score=0; return; } if(msg.x>230&&msg.x<336&&msg.y>400&&msg.y<430) { musicc(); if(game.level>1) game.score=game.score-1500; elseif(game.level==1) game.score=0; game.game_state=4; return; } } } Sleep(500); } } voidwin_game() { mouse_msgmsg; while(1) { show_map(); putimage_transparent(NULL,game.img[10],130,300,0); while(mousemsg()) { msg=getmouse(); if(msg.is_left()&&msg.is_down()) { musicc(); game.level++; game.targets=game.targets+1600; game.state=1; game.game_state=1; game.level_state=1; game.tool_number=game.tool_number+2; return; } } Sleep(500); } } voidplay() { while(1) { if(game.game_state==0) start_game(); elseif(game.game_state==1) play_game(); elseif(game.game_state==-1) end_game(); elseif(game.game_state==2) win_game(); elseif(game.game_state==4) fail_again(); elseif(game.game_state==5) inter_game(); elseif(game.game_state==3) return; } } intmain() { initgraph(450,700); game.game_state=0; game.counts=0; game.score=0; game.targets=1500; game.level=1; game.tool_number=0; game.tool_state=1; game.start_state=1; init_img(); mciSendString("opengame\\under.mp3aliasmymusicg",NULL,0,NULL); mciSendString("playmymusicgrepeat",NULL,0,NULL); read(&high); play(); closegraph(); mciSendString("closemymusicgrepeat",NULL,0,NULL); return0; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。