turbo_c下的扫雷游戏源代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#includestdio.h#includegraphics.h#includeconio.h#includebios.h#includestdlib.h#includetime.h#defineESC283#defineUP18432#defineDOWN20480#defineLEFT19200#defineRIGHT19712#defineENTER7181#defineSPACE14624#defineWIDTH15#defineAO0#defineTU1#defineMINE-1intm_maxx,m_maxy;intm_row,m_col;intm_x0,m_y0;int*m_mine;int*m_flag;intm_num;inta[8]={-1,-1,-1,0,1,1,1,0};intb[8]={-1,0,1,1,1,0,-1,-1};intm_count;intm_countdown;intfirst;voidinit_system();voidclose_system();voiddraw_box(int,int,int,int,int,int);voiddraw_mine_region();voidcount_x0y0();voiddraw_title();voiddraw_smile(int);voiddraw_mine(int,int);voidclean_mine();intshift_k_by_ij(int,int);voidshift_ij_by_k(int,int*,int*);voidshift_xy_by_ij(inti,intj,int*x,int*y);voidset_mines();voiddisp_all_mines();voidfind_mine(int,int);voidcount_around_mines();intdig_mine1(int,int);voiddig_mine2(int,int);voiddig_mine3(int,int);voidgameover();voiddisp_number(int,int);voidall_number();voidgamewin();voidmake_flag(int,int);voiddraw_redflag(int,int);voiddraw_questionmark(int,int);voiddisp_rest_mine();voiddisp_time(time_t);voidjudge_error_flag();voiddisp_all_redflags();voiddraw_cursor(int,int);main(){init_system();set_mines();draw_mine_region();clean_mine();getch();close_system();}voiddisp_time(time_tt){intx,y;charstr[4];if(t999)return;x=m_x0+m_col*(WIDTH+1)+1-40;y=m_y0-30;draw_box(x,y,x+30,y+20,AO,LIGHTGRAY);settextstyle(DEFAULT_FONT,HORIZ_DIR,1);sprintf(str,%3ld,t);setcolor(RED);outtextxy(x+3,y+6,str);}voiddisp_rest_mine(){intx,y;charstr[4];x=m_x0+10;y=m_y0-30;draw_box(x,y,x+30,y+20,AO,LIGHTGRAY);settextstyle(DEFAULT_FONT,HORIZ_DIR,1);sprintf(str,%3d,m_countdown);x=x+(WIDTH-textwidth(str))/2;y=y+3+(WIDTH-textheight(str))/2;setcolor(RED);outtextxy(x,y,str);}voiddraw_questionmark(inti,intj){intx,y;charstr[]=?;m_countdown++;disp_rest_mine();shift_xy_by_ij(i,j,&x,&y);draw_box(x,y,x+WIDTH,y+WIDTH,TU,LIGHTGRAY);setcolor(BLACK);settextstyle(DEFAULT_FONT,HORIZ_DIR,1);x=x+(WIDTH-textwidth(str))/2;y=y+(WIDTH-textheight(str))/2;outtextxy(x,y,str);}voiddraw_redflag(inti,intj){intx,y;m_countdown--;disp_rest_mine();shift_xy_by_ij(i,j,&x,&y);draw_box(x,y,x+WIDTH,y+WIDTH,TU,LIGHTGRAY);setcolor(RED);line(x+WIDTH/4,y+WIDTH/4,x+3*WIDTH/4,y+WIDTH/2+1);line(x+WIDTH/4,y+WIDTH/2+1,x+3*WIDTH/4,y+WIDTH/2+1);setfillstyle(SOLID_FILL,RED);/*floodfill(x+WIDTH/2,y+WIDTH/2,RED);*/setcolor(BLACK);line(x+WIDTH/4,y+WIDTH/4,x+WIDTH/4,y+3*WIDTH/4+1);setlinestyle(SOLID_LINE,0,3);line(x+WIDTH/4-2,y+3*WIDTH/4+1,x+WIDTH/4+2,y+3*WIDTH/4+1);setlinestyle(SOLID_LINE,0,1);}voidmake_flag(inti,intj){intk,x,y;k=shift_k_by_ij(i,j);shift_xy_by_ij(i,j,&x,&y);if(m_flag[k]==0){draw_redflag(i,j);draw_cursor(i,j);m_flag[k]=-1;}elseif(m_flag[k]==-1){draw_questionmark(i,j);m_flag[k]=-2;draw_cursor(i,j);}elseif(m_flag[k]==-2){draw_box(x,y,x+WIDTH,y+WIDTH,TU,LIGHTGRAY);m_flag[k]=0;draw_cursor(i,j);}}voidcount_around_mines(){inti,j,k,m,n,x,y;for(k=0;km_row*m_col;k++){shift_ij_by_k(k,&i,&j);for(m=0;m8;m++){x=i+a[m];y=j+b[m];if(x=1&&x=m_row&&y=1&&y=m_col&&m_mine[k]!=MINE){n=shift_k_by_ij(x,y);if(m_mine[n]==MINE)m_mine[k]++;}}}}voidgamewin(){intx,y;charstr[]=WIN!!!;setcolor(RED);settextstyle(DEFAULT_FONT,HORIZ_DIR,4);x=m_x0+(m_col*(WIDTH+1)-1-textwidth(str))/2;y=m_y0+(m_row*(WIDTH+1)-1-textheight(str))/2;outtextxy(x,y,str);}voidgameover(){intx,y;charstr[]=GAMEOVER!;setcolor(RED);settextstyle(DEFAULT_FONT,HORIZ_DIR,4);x=m_x0+(m_col*(WIDTH+1)-1-textwidth(str))/2;y=m_y0+(m_row*(WIDTH+1)-1-textheight(str))/2;outtextxy(x,y,str);}voiddig_mine3(inti,intj){intk,x,y,m,c,d;k=shift_k_by_ij(i,j);if(m_mine[k]0||m_mine[k]8||m_flag[k]==-1)return;elseif(m_mine[k]0&&m_mine[k]9){disp_number(i,j);m_count++;m_mine[k]+=20;return;}elseif(m_mine[k]==0){shift_xy_by_ij(i,j,&x,&y);draw_box(x,y,x+WIDTH,y+WIDTH,AO,LIGHTGRAY);m_count++;m_mine[k]+=20;}for(m=0;m8;m++){c=i+a[m];d=j+b[m];if(c=1&&c=m_row&&d=1&&d=m_col)dig_mine3(c,d);}}voidall_number(){inti,j;for(i=1;im_row;i++)for(j=1;jm_col;j++)disp_number(i,j);}voiddisp_number(inti,intj){intk,x,y;charstr[2];k=shift_k_by_ij(i,j);if(m_mine[k]==MINE)return;shift_xy_by_ij(i,j,&x,&y);draw_box(x,y,x+WIDTH,y+WIDTH,AO,LIGHTGRAY);if(m_mine[k]==0)return;settextstyle(DEFAULT_FONT,HORIZ_DIR,1);sprintf(str,%d,m_mine[k]);x=x+(WIDTH-textwidth(str))/2;y=y+(WIDTH-textheight(str))/2;switch(m_mine[k]){case1:setcolor(BLUE);break;case2:setcolor(GREEN);break;case3:setcolor(RED);break;case4:setcolor(CYAN);break;case5:setcolor(YELLOW);break;case6:setcolor(BLACK);break;case7:setcolor(BROWN);break;case8:setcolor(MAGENTA);break;}outtextxy(x,y,str);}voiddig_mine2(inti,intj){intk,x,y;k=shift_k_by_ij(i,j);if(m_flag[k]==-1)return;shift_xy_by_ij(i,j,&x,&y);draw_box(x,y,x+WIDTH,y+WIDTH,AO,LIGHTGRAY);disp_number(i,j);m_count++;m_mine[k]+=20;}voidjudge_error_flag(){intk,m,i,j,x,y;m=m_row*m_col;for(k=0;km;k++){if(m_flag[k]==MINE&&m_mine[k]!=MINE){shift_ij_by_k(k,&i,&j);shift_xy_by_ij(i,j,&x,&y);draw_box(x,y,x+WIDTH,y+WIDTH,AO,LIGHTGRAY);draw_mine(i,j);setcolor(RED);setlinestyle(SOLID_LINE,0,3);line(x+2,y+2,x+WIDTH-2,y+WIDTH-2);line(x+W

1 / 15
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功