谁有c/c++编的扫雷程序代码啊?不要#include <graphics.h>,这个在vc6.0里运行不了。谢了!

发布时间:2019-09-12 19:09:27

谁有c/c++编的扫雷程序代码啊?不要#include <graphics.h>,这个在vc6.0里运行不了。谢了!

推荐回答

#include<conio.h>#include<windows.h>#include<iostream.h>#include <ctime>#include <cstdlib>const int high=15,wide=45,lei_num=77;const int lei_tubiao=4,//设置雷的图标(1~6) flag_tubiao=6;//设置旗的图标(1~6)int xy_x,xy_y,flag,t;int right,wrong;char temp;char now[high][wide]={'#','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','#', 'I','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','I', 'I','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','I', 'I','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','I', 'I','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','I', 'I','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','I', 'I','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','I', 'I','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','I', 'I','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','I', 'I','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','I', 'I','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','I', 'I','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','I', 'I','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','I', 'I','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','I', '#','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','#'};char map[high][wide]={'#','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','#', 'I',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', '#','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','#'};char wel[high][wide]={'#','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','#', 'I',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*','*','*','*','*','*','*','*','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ','*','*','*','*','*',' ','*','*','*','*','*','*','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ','*',' ',' ','*','*',' ',' ','*',' ',' ','*','*',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ','*',' ','*',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ','*','*',' ',' ',' ','*','*','*','*','*','*',' ',' ',' ',' ',' ',' ','*',' ',' ','*','*',' ',' ','*',' ',' ','*','*',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ','*','*','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*','*','*','*','*','*','*','*','*','*','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ','*',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*','*','*','*','*','*','*','*','*','*','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ','*','*',' ',' ',' ','*','*','*','*','*','*','*',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I', 'I',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*','*','*','*','*','*','*','*','*','*','*',' ',' ','V','e','r','.','1','.','0',' ','I', 'I',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','M','a','d','e',' ','B','y',' ','S','e','v','e','n','_','L',' ',' ','I', '#','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','#'};void print(char[][wide]);void setlei(int);void kongzhi();void play();void walei(int,int);void search0(int,int);void bflag(int,int);int leishu(int,int);void gamewin();void check();void gameover();void wele();void shandong();void chushihua();//主函数void main(){ wele(); chushihua(); play();}//欢迎说明void wele(){/* for(int i=0;i<high;i++) {for(int j=0;j<wide;j++)cout<<wel[i][j]; cout<<endl; }*/ int k,h; for(k=0;k<wide;k++)cout<<wel[0][k]; cout<<endl; cout<<"I◤ ◥I"<<endl; cout<<"I ▍ ▃▃▃▃ ㊣ I"<<endl; cout<<"I ▃▃▃▃ ▃▃▃ ▃▃▃▃▃ I"<<endl; cout<<"I ▍ ▍ ▍■ ▎ ■ ▍ I"<<endl; cout<<"I ▍ ▍ ▍■ ▎ ■ ▍ I"<<endl; cout<<"I ▍ ▃▃▍ ▎ I"<<endl; cout<<"I ▁▂▍▃ ▍ ▃▃▃ I"<<endl; cout<<"I ▍ ▍ ▍▃ ▎▃ ▍ I"<<endl; cout<<"I ◥▍ ▃▃▃▍ ▍▃▃▃ ▍ I"<<endl; cout<<"I◣ ◢I"<<endl; cout<<"I I"<<endl; cout<<"I I"<<endl; cout<<"I Ver.1.0 I"<<endl; for(h=0;h<wide;h++)cout<<wel[high-1][h]; cout<<endl; cout<<endl; cout<<" 按任意键继续... ..."<<endl; while(!kbhit()); getch(); system("cls"); for(k=0;k<wide;k++)cout<<wel[0][k]; cout<<endl; cout<<"I 游戏说明 I"<<endl; cout<<"I 本游戏为试玩版本,主要用作学习交流,顺I"<<endl; cout<<"I 便制造点商机^ ^请于下载后24小时内自动自觉 I"<<endl; cout<<"I 删除,购买正版请到华工C10-507宿舍~听说女的I"<<endl; cout<<"I 还有折打哦~谢谢合作! I"<<endl; cout<<"I 控制说明: I"<<endl; cout<<"I 按键: W(w) 功能: 向上移动光标 I"<<endl; cout<<"I S(s) 向下移动光标 I"<<endl; cout<<"I A(a) 向左移动光标 I"<<endl; cout<<"I D(d) 向右移动光标 I"<<endl; cout<<"I J(j) 扫雷 I"<<endl; cout<<"I K(k) 标旗 I"<<endl; cout<<"I ESC 退出 I"<<endl; for(h=0;h<wide;h++)cout<<wel[high-1][h]; cout<<endl; cout<<endl; cout<<" 按任意键继续... ..."<<endl; cout<<endl; while(!kbhit()); getch();};//打印屏幕void print(char pic[][wide]){ system("cls"); for(int i=0;i<high;i++) {for(int j=0;j<wide;j++)cout<<pic[i][j]; cout<<endl; } cout<<" Flag: "<<flag<<" Time: "<<((clock()-t)/1000)<<endl;}//输入控制void kongzhi(){ char c='?',keystate='N'; now[xy_y][xy_x]=temp; do { if(kbhit()) { c = getch(); switch(c) {case 'w': case 'W':{if(xy_y>1){now[xy_y][xy_x]=temp;xy_y--;keystate='Y';}break;} case 'A': case 'a':{if(xy_x>1){now[xy_y][xy_x]=temp;xy_x--;keystate='Y';}break;} case 's': case 'S':{if(xy_y<high-2){now[xy_y][xy_x]=temp;xy_y++;keystate='Y';}break;} case 'd': case 'D':{if(xy_x<wide-2){now[xy_y][xy_x]=temp;xy_x++;keystate='Y';}break;} case 'j': case 'J':{if(now[xy_y][xy_x]=='#'||now[xy_y][xy_x]=='+'){now[xy_y][xy_x]=temp;walei(xy_x,xy_y);keystate='Y';}break;} case 'K': case 'k':{if(now[xy_y][xy_x]=='#'||now[xy_y][xy_x]==flag_tubiao||now[xy_y][xy_x]=='+'){now[xy_y][xy_x]=temp;bflag(xy_x,xy_y);keystate='Y';}break;} case 27 : exit(0); }; }; if(((clock()-t)%1000)==0)shandong(); } while (keystate=='N');}//游戏过程void play(){ int win0=0; while(1) {kongzhi(); temp=now[xy_y][xy_x]; now[xy_y][xy_x]='+'; print(now); if(flag==0) {win0=1; for(int i=1;i<high-1;i++) for(int j=1;j<wide-1;j++) if(now[i][j]==flag_tubiao) if(map[i][j]!=lei_tubiao)win0=0; }; if(win0==1)gamewin(); };}//初始化void chushihua(){ for(int i0=1;i0<high-1;i0++) for(int j=1;j<wide-1;j++) {map[i0][j]=' '; now[i0][j]='#'; }; t = clock(); flag=lei_num; right=0; wrong=0; xy_y=1; xy_x=1; temp=now[xy_y][xy_x]; now[xy_y][xy_x]='+'; setlei(lei_num); check(); print(now);}//布置雷场void setlei(int n){ srand(time(0)); int lei_x,lei_y; for(int i=0;i<n;) {lei_x = (rand() % (wide-1))+1; lei_y = (rand() % (high-1))+1; if(map[lei_y][lei_x]==' ') {map[lei_y][lei_x]=lei_tubiao;i++;} }} //计算周边雷数 int leishu(int m,int n){ int s=0; for(int i=m-1;i<=m+1;i++) for(int j=n-1;j<=n+1;j++) if(map[i][j]==lei_tubiao)s+=1; return(s);}void check(){ for(int i=1;i<high-1;i++) for(int j=1;j<wide-1;j++) if((map[i][j]!=lei_tubiao)&&(leishu(i,j)!=0))map[i][j]=char(leishu(i,j)+48);}//扫雷void walei(int x,int y){ if(map[y][x]==lei_tubiao){gameover();} else{ now[y][x]=map[y][x];if(map[y][x]==' ')search0(x,y);} }void search0(int x,int y){ for(int i=y-1;i<y+2;i++) for(int j=x-1;j<x+2;j++) if((now[i][j]=='#')&&(map[i][j]!=lei_tubiao)){now[i][j]=map[i][j];if(map[i][j]==' ')search0(j,i);}}void bflag(int x,int y){ if(now[xy_y][xy_x]=='#'){if(flag>0){now[y][x]=flag_tubiao;flag--;}}; if(temp==flag_tubiao){now[y][x]='#';flag++;};}; //游戏结束 void gameover(){ char ch; for(int i=0;i<high;i++) for(int j=0;j<wide;j++) if(now[i][j]==flag_tubiao) {if(map[i][j]==lei_tubiao){map[i][j]=2;right++;} else {map[i][j]=1;wrong++;}; } print(map); cout<<" GAME OVER!"<<endl; cout<<endl; cout<<" ¤ 数据统计 ¤"<<endl; cout<<"正确 ("<<char(2)<<"): "<<right<<endl; cout<<"错误 ("<<char(1)<<"): "<<wrong<<endl; cout<<"时间 "<<(clock()-t)/1000<<" 秒"<<endl; cout<<endl; cout<<"非友情提示:空格键继续,ESC键退出... ..."<<endl; //while(1){if((kbhit())&&(getch()==' '))break;}; while(1) {if(kbhit()) {ch=getch(); if(ch==' ')break; if(ch==27)exit(0); }; }; //exit(0); chushihua(); play();}//游戏胜利 void gamewin(){ char ch; cout<<" WIN!"<<char(2)<<endl; cout<<endl; cout<<" ¤奇迹还是发生了,可恶~~!!¤"<<endl; cout<<"时间 "<<(clock()-t)/1000<<" 秒"<<endl; cout<<endl; cout<<endl; cout<<"非友情提示:空格键继续,ESC键退出... ..."<<endl; while(1) {if(kbhit()) {ch=getch(); if(ch==' ')break; if(ch==27)exit(0); }; }; //exit(0); chushihua(); play();}//秒闪void shandong(){ if(now[xy_y][xy_x]=='+')now[xy_y][xy_x]=temp; else now[xy_y][xy_x]='+'; print(now);}代码来自小磊客栈,论坛里面里面还有很多学习知识,大家要是有兴趣的话可以谷歌下小磊客栈,很不错的一个学习交流平台。
以上问题属网友观点,不代表本站立场,仅供参考!