#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<