




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#include <iostream>#include "windows.h"#include <iostream>#include "time.h"#include "assert.h"#include "conio.h"using namespace std;struct eachcasebool havebomb;int state;/if state = 0,means nothing; less then 8 and more then 1 means there are &quo
2、t;state" bomb near here; 9 means you have find here ;/10 means you have point here;class viewfriend 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* &,
3、int,int);void flashshow();int check();/ check whether ignite the bomb, if not, check arrond/ return 1 means win ;2 means lose; 0 means nothingview();private:int hight,width,numbomb;public:int nhight,nwidth;int main()bool quit = true;while(quit)std:cout<<"-"<<std:endl;std:cout&l
4、t;<"- welcome -"<<std:endl;std:cout<<"- -"<<std:endl;std:cout<<"- -"<<std:endl;std:cout<<"- w:up s:down a:left d :right p:point b:begin e:enter q:qiut -"<<std:endl;std:cout<<"- -"<<std:endl;std
5、:cout<<"- -"<<std:endl;std:cout<<"- -"<<std:endl;std:cout<<"- -"<<std:endl;std:cout<<"- by uil from scut -"<<std:endl;std:cout<<"-"<<std:endl;char gets = cin.get();if(gets = 'q')quit
6、 = false;continue;else if(gets != 'b')system("cls");continue;system("cls");int w,h,b;cout<<"please enter the with:"<<endl;cin>>w;if(w<1)w=10;cout<<"please enter the hight:"<<endl;cin>>h;if(h<1)h=10;cout<<
7、"please enter the number of bomb:"<<endl;cin>>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+)forcheckf = new bool w;for(int r = 0;r < w;r+)forcheckfr = true;/ make it for check() to check
8、whether a case have been findint end=0; / deside whether stopbool 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-
9、1>=0 )/&& views.qipanviews.nhight-1views.nwidth.state%10 = 0)views.nhight-;break;case 's':if(views.nhight+1<views.gethight() /&& views.qipanviews.nhight+1views.nwidth.state%10 = 0)views.nhight+;break;case 'a':if(views.nwidth-1>=0)/ && views.qipanviews
10、.nhightviews.nwidth-1.state%10 = 0)views.nwidth-;break;case 'd':if(views.nwidth+1<views.getwidth()/ && views.qipanviews.nhightviews.nwidth+1.state%10 = 0)views.nwidth+;break;case 'p':end = views.check();break;case 'r':restart = false;break;/ we need to improve here
11、case 'q':quit = false;break;case 'e':end = views.check(forcheck,views.nhight,views.nwidth);break;default:continue;views.show();/the main circle, which get the importif(end = 1)views.falseshow();cout<<endl<<"you are lose"<<endl;cout<<"use time:&q
12、uot;<<(double)(clock() - start)/clocks_per_sec)<<endl;cout<<"try again? y/n"bool restarts = false;while(cin && !restarts)char a;cin>>a;if(a = 'n')return 0;else if(a = 'y')restarts = true;/ need to improve.else if(end = 2)cout<<endl<&
13、lt;"you are win!"<<endl;cout<<"use time:"<<(double)(clock() - start)/clocks_per_sec)<<endl;cout<<"try again? y/n"char a;cin>>a;bool restarts = false;while(cin && !restarts)char a;cin>>a;if(a = 'n')return 0;else i
14、f(a = 'y')restarts = true;/ need to improvesystem("cls");return 0;int view:check(bool* &forcheck,int h,int w)forcheckhw = false;if(qipanhw.havebomb)return 1;int wcheck = bombnear(h,w);/ use to deside continue to check;if(wcheck)qipanhw.state= wcheck;elseqipanhw.state = 9;if(h-1
15、 >=0 && w-1>=0 && forcheckh-1w-1)/ here show the view.qipan here have problemcheck(forcheck,h-1,w-1);if(h-1 >= 0 && forcheckh-1w)check(forcheck,h-1,w);if(h-1 >=0 && w+1 < width && forcheckh-1w+1)check(forcheck,h-1,w+1);if(w-1 >= 0 &&
16、forcheckhw-1)check(forcheck,h,w-1);if(w+1 < width && forcheckhw+1)check(forcheck,h,w+1);if(h+1 < hight && w-1 >= 0 && forcheckh+1w-1)check(forcheck,h+1,w-1);if(h+1 < hight && forcheckh+1w)check(forcheck,h+1,w);if(h+1 < hight && w+1 < width &a
17、mp;& forcheckh+1w+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 bombint b = numofbomb;int h = 0;fo
18、r(;h<=hight;h+)qipanh = new eachcasewidth;/assert(sizeof(qipanh)<0);for(int w = 0; w <= width ; w+)qipanhw.state = 0;qipanhw.havebomb = false;for(int nb = 0; nb <= numbomb-1;)int hb=rand()%hight;int wb=rand()%width;if(!qipanhbwb.havebomb)qipanhbwb.havebomb = true;nb+;int view:gethight()r
19、eturn hight;int view:getwidth()return width;int view:getnumbomb()return numbomb;void view:show()system("cls");/qipannhightnwidth.state=9;for(int n=0;n<=(width)*4+2;n+)std:cout<<'-'for(int h=0;h<=hight-1;h+)std:cout<<std:endl<<'|'for(int w=0;w<=wid
20、th-1;w+)int i=0;if(qipanhw.state = 0)std:cout<<"¡ö "else if( 0 < qipanhw.state && qipanhw.state< 9)std:cout<<qipanhw.state<<" " /need to advancedelse if(qipanhw.state = 9)std:cout<<"¡¤ "else if(qipanhw.state = 10
21、)std:cout<<"p "else if(qipanhw.state = 11)std:cout<<"¡õ "elseassert(0);std:cout<<'|'<<std:endl;for(int k=0;k<=(width)*4+2;k+)std:cout<<'-'cout<<"hight:"<<nhight+1<<" width:"<<nw
22、idth+1<<endl;view:view()for(int n=0;n<=hight;n+)delete qipann;delete qipan;int view:bombnear(int h,int w)int bombs = 0;if(h-1 >=0 && w-1>=0)if(qipanh-1w-1.havebomb)bombs+;if(h-1 >=0)if(qipanh-1w.havebomb)bombs+;if(h-1 >=0 && w+1 < width )if(qipanh-1w+1.havebom
23、b)bombs+;if(w-1>=0)if(qipanhw-1.havebomb)bombs+;if(w+1 < width )if(qipanhw+1.havebomb)bombs+;if(h+1 < hight&& w-1>=0)if(qipanh+1w-1.havebomb)bombs+;if(h+1 < hight)if(qipanh+1w.havebomb)bombs+;if(h+1 < hight && w+1 < width )if(qipanh+1w+1.havebomb)bombs+;return bo
24、mbs;void view:falseshow()system("cls");/qipannhightnwidth.state=9;for(int n=0;n<=(width)*4+2;n+)std:cout<<'-'for(int h=0;h<=hight-1;h+)std:cout<<std:endl<<'|'for(int w=0;w<=width-1;w+)int i=0;if(qipanhw.state = 0)if(qipanhw.havebomb)std:cout<&l
25、t;"¡è "elsestd:cout<<" "else if( 0 < qipanhw.state && qipanhw.state< 9)std:cout<<qipanhw.state<<" " /need to advancedelse if(qipanhw.state = 9)std:cout<<" "else if(qipanhw.state = 10)if(qipanhw.havebomb)std:cout&
26、lt;<"¡ò "elsestd:cout<<"¡Á "else if(qipanhw.state = 11)std:cout<<"¡õ"elseassert(0);std:cout<<'|'<<std:endl;for(int k=0;k<=(width)*4+2;k+)std:cout<<'-'void view:flashshow()system("cls&
27、quot;);/qipannhightnwidth.state=9;for(int n=0;n<=(width)*4+2;n+)std:cout<<'-'for(int h=0;h<hight;h+)std:cout<<std:endl<<'|'for(int w=0;w<width;w+)if( h = nhight && w = nwidth)std:cout<<"¡ð "else if(qipanhw.state = 0)std:cout<<"¡ö "else if( 0 <
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年幼儿园小班标准教案《谁的脚印》
- 2025年幼儿园小班标准教案《快乐轮胎》含反思
- 输电线路迁改环境影响评估
- Module 2 My hometown Unit 3(教学设计)-2024-2025学年外研版英语八年级上册
- 高端装备数字化项目投资回报分析
- 2025年湖北省襄樊市单招职业适应性测试题库及答案一套
- 二零二五年度山坪塘承包及农业循环经济发展合同
- 二零二五年度抖音网红孵化基地合作协议
- 第19课资本主义国家的新变化 教学设计 -2023-2024学年高一统编版2019必修中外历史纲要下册
- 2025年广西金融职业技术学院单招职业适应性测试题库审定版
- 《陶瓷工艺技术》课件
- 供电所安全演讲
- 深度学习架构创新-深度研究
- 供应链韧性提升与风险防范-深度研究
- 基层医疗卫生服务能力提升考核试卷
- 化工原理完整(天大版)课件
- 2025年江苏连云港市赣榆城市建设发展集团有限公司招聘笔试参考题库附带答案详解
- 砥砺前行决心谱写华章
- 2025年开学教导处发言稿(5篇)
- 机电设备安装旁站监理方案
- 2025年度民政局离婚协议书范本模板官方修订2篇
评论
0/150
提交评论