为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

扫雷代码(C )

2019-01-13 19页 doc 36KB 102阅读

用户头像

is_882336

暂无简介

举报
扫雷代码(C )#include #include "windows.h" #include #include "time.h" #include "assert.h" #include "conio.h" using namespace std; struct eachcase { bool havebomb; int state; //if state = 0,means nothing; less then 8 and more then 1 means there are "state" bomb near...
扫雷代码(C  )
#include #include "windows.h" #include #include "time.h" #include "assert.h" #include "conio.h" using namespace std; struct eachcase { bool havebomb; int state; //if state = 0,means nothing; less then 8 and more then 1 means there are "state" bomb near here; 9 means you have find here ; //10 means you have point here; }; class view { friend int check(); public: view(int width,int hight,int numofbomb); void show(); eachcase **qipan; int gethight(); int getwidth(); int getnumbomb(); void falseshow(); int bombnear(int,int); int check(bool** &,int,int); void flashshow(); int check(); // check whether ignite the bomb, if not, check arrond // return 1 means win ;2 means lose; 0 means nothing ~view(); private: int hight,width,numbomb; public: int nhight,nwidth; }; int main() { bool quit = true; while(quit) { std::cout<<"----------------------------------------------------------------"<>w; if(w<1) w=10; cout<<"please enter the hight:"<>h; if(h<1) h=10; cout<<"please enter the number of bomb:"<>b; if(b<1) b=10; view views(h,w,b); clock_t start=clock(); clock_t flash = start; bool** forcheck = new bool*[h]; for(int f = 0; f < h;f++) { forcheck[f] = new bool [w]; for(int r = 0;r < w;r++) { forcheck[f][r] = true; } } // make it for check() to check whether a case have been find int end=0; // deside whether stop bool restart = true ; while(cin&&!end&&restart&&quit) { if((double)((clock() - flash)/clocks_per_sec) > 0.5) { views.flashshow(); sleep(300); } views.show(); char get; get = _getch(); switch(get) { case 'w': if(views.nhight-1>=0 )//&& views.qipan[views.nhight-1][views.nwidth].state%10 == 0) { views.nhight--; } break; case 's': if(views.nhight+1=0)// && views.qipan[views.nhight][views.nwidth-1].state%10 == 0) { views.nwidth--; } break; case 'd': if(views.nwidth+1>a; if(a == 'n') return 0; else if(a == 'y') { restarts = true; } } }// need to improve. else if(end == 2) { cout<>a; bool restarts = false; while(cin && !restarts) { char a; cin>>a; if(a == 'n') return 0; else if(a == 'y') { restarts = true; } } }// need to improve system("cls"); } return 0; } int view::check(bool** &forcheck,int h,int w) { forcheck[h][w] = false; if(qipan[h][w].havebomb) { return 1; } int wcheck = bombnear(h,w); // use to deside continue to check; if(wcheck) { qipan[h][w].state= wcheck; } else { qipan[h][w].state = 9; if(h-1 >=0 && w-1>=0 && forcheck[h-1][w-1]) // here show the view.qipan[][] here have problem { check(forcheck,h-1,w-1); } if(h-1 >= 0 && forcheck[h-1][w]) { check(forcheck,h-1,w); } if(h-1 >=0 && w+1 < width && forcheck[h-1][w+1]) { check(forcheck,h-1,w+1); } if(w-1 >= 0 && forcheck[h][w-1]) { check(forcheck,h,w-1); } if(w+1 < width && forcheck[h][w+1]) { check(forcheck,h,w+1); } if(h+1 < hight && w-1 >= 0 && forcheck[h+1][w-1]) { check(forcheck,h+1,w-1); } if(h+1 < hight && forcheck[h+1][w]) { check(forcheck,h+1,w); } if(h+1 < hight && w+1 < width && forcheck[h+1][w+1]) { check(forcheck,h+1,w+1); } } return 0; } view::view(int hights,int widths,int numofbomb) { hight = hights;//////////////// width = hights;/////////////// numbomb = numofbomb; nhight = 0; nwidth = 0; qipan = new eachcase*[hight]; //assert(sizeof(qipan)<0); srand(time(0)); // we use it to make bomb int b = numofbomb; int h = 0; for(;h<=hight;h++) { qipan[h] = new eachcase[width]; //assert(sizeof(qipan[h])<0); for(int w = 0; w <= width ; w++) { qipan[h][w].state = 0; qipan[h][w].havebomb = false; } } for(int nb = 0; nb <= numbomb-1;) { int hb=rand()%hight; int wb=rand()%width; if(!qipan[hb][wb].havebomb) { qipan[hb][wb].havebomb = true; nb++; } } } int view::gethight() { return hight; } int view::getwidth() { return width; } int view::getnumbomb() { return numbomb; } void view::show() { system("cls"); //qipan[nhight][nwidth].state=9; for(int n=0;n<=(width)*4+2;n++) { std::cout<<'-'; } for(int h=0;h<=hight-1;h++) { std::cout<
/
本文档为【扫雷代码(C )】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索