扫雷技巧 逻辑的逻辑问题

2D游戏(6)
&#include &time.h&
#include &stack&
#include &Windows.h&
// TODO: 在此处引用程序要求的附加头文件
struct MapInfo
int nBomboN
bMine=bFind=bShow=
nBomboNum=0;
void Reset()
bMine=bFind=bShow=
nBomboNum=0;
class MineLogic
MineLogic();
~MineLogic();
stack&int&
InitMap(int nWidth,int nHeight);
DestroyMap();
ResetMap();
RandomMap();
SetLevel(int nLevel);
ShowMap();
Clicked(int nRow,int nCol);
ShowUserMap();
SetFind(int nRow,int nCol,bool b);
AllFind();
GetFind(int nRow,int nCol);
#include &stdafx.h&
// TODO: 在 STDAFX.H 中
//引用任何所需的附加头文件,而不是在此文件中引用
MineLogic::MineLogic()
m_pMap=NULL;
m_nMapHeight=m_nMapWidth=0;
m_nLevel=0;//初级 20% 中级40% 高级60%
m_nBomboNum=0;
MineLogic::~MineLogic()
this-&DestroyMap();
MineLogic::InitMap(int nWidth,int nHeight)
this-&m_nMapWidth=nW
this-&m_nMapHeight=nH
if(!m_pMap)
m_pMap=new MapInfo*[nHeight];
for(int i=0;i&nH++i)
*(m_pMap+i)=new MapInfo[nWidth];
MineLogic::ResetMap()
if(!m_pMap)
for(int i=0;i&this-&m_nMapH++i)
memset(*(m_pMap+i),0,sizeof(MapInfo));
MineLogic::SetLevel(int nLevel)
this-&m_nLevel=nL
m_nLevel=(int)m_nMapHeight*m_nMapWidth*nLevel/10;
switch (nLevel)
m_nLevel=(int)m_nMapHeight*m_nMapWidth*0.1f;
m_nLevel=(int)m_nMapHeight*m_nMapWidth*0.3f;
m_nLevel=(int)m_nMapHeight*m_nMapWidth*0.5f;
MineLogic::DestroyMap()
for(int i=0;i&this-&m_nMapH++i)
delete[](*(m_pMap+i));
delete[]m_pM
MineLogic::RandomMap()
if(!m_pMap)
this-&ResetMap();
//srand((unsigned int)time(NULL));
for(int i=0;i&m_nL++i)
if(!m_pMap[(int)(m_nMapHeight*rand()/(RAND_MAX+1.0))][(int)(m_nMapHeight*rand()/(RAND_MAX+1.0))].bMine)
m_pMap[(int)(m_nMapHeight*rand()/(RAND_MAX+1.0))][(int)(m_nMapHeight*rand()/(RAND_MAX+1.0))].bMine=
for(int i=0;i&m_nMapH++i)
for(int j=0;j&m_nMapW++j)
if(m_pMap[i][j].bMine)
m_pMap[i][j].nBomboNum=n;
x=i-1;y=j-1;
if(x&=0&&y&=0)
if(m_pMap[x][y].bMine)
x=i-1;y=j;
if(m_pMap[x][y].bMine)
x=i-1;y=j+1;
if(x&=0&&y&m_nMapWidth)
if(m_pMap[x][y].bMine)
x=i;y=j-1;
if(m_pMap[x][y].bMine)
x=i;y=j+1;
if(y&m_nMapWidth)
if(m_pMap[x][y].bMine)
x=i+1;y=j-1;
if(x&m_nMapHeight&&y&=0)
if(m_pMap[x][y].bMine)
x=i+1;y=j;
if(x&m_nMapHeight)
if(m_pMap[x][y].bMine)
x=i+1;y=j+1;
if(x&m_nMapHeight&&y&m_nMapWidth)
if(m_pMap[x][y].bMine)
m_pMap[i][j].nBomboNum=n;
MineLogic::Clicked(int nRow,int nCol)
m_pMap[nRow][nCol].bShow=
if(m_pMap[nRow][nCol].bMine)
if(m_pMap[nRow][nCol].nBomboNum!=0)
x=nRow-1;y=nCol-1;
if(x&=0&&y&=0)
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum==0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
m_stPoint.push(x);
m_stPoint.push(y);
x=nRow-1;y=nC
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum==0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
m_stPoint.push(x);
m_stPoint.push(y);
x=nRow-1;y=nCol+1;
if(x&=0&&y&m_nMapWidth)
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum==0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
m_stPoint.push(x);
m_stPoint.push(y);
x=nRy=nCol-1;
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum==0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
m_stPoint.push(x);
m_stPoint.push(y);
x=nRy=nCol+1;
if(y&m_nMapWidth)
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum==0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
m_stPoint.push(x);
m_stPoint.push(y);
x=nRow+1;y=nCol-1;
if(x&m_nMapHeight&&y&=0)
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum==0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
m_stPoint.push(x);
m_stPoint.push(y);
x=nRow+1;y=nC
if(x&m_nMapHeight)
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum==0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
m_stPoint.push(x);
m_stPoint.push(y);
x=nRow+1;y=nCol+1;
if(x&m_nMapHeight&&y&m_nMapWidth)
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum==0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
m_stPoint.push(x);
m_stPoint.push(y);
int preSize=m_stPoint.size();
while(m_stPoint.size()!=0)
nCol=m_stPoint.top();
m_stPoint.pop();
nRow=m_stPoint.top();
m_stPoint.pop();
preSize=m_stPoint.size();
x=nRow-1;y=nCol-1;
if(x&=0&&y&=0)
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum==0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
m_stPoint.push(x);
m_stPoint.push(y);
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum!=0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
x=nRow-1;y=nC
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum==0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
m_stPoint.push(x);
m_stPoint.push(y);
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum!=0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
x=nRow-1;y=nCol+1;
if(x&=0&&y&m_nMapWidth)
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum==0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
m_stPoint.push(x);
m_stPoint.push(y);
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum!=0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
x=nRy=nCol-1;
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum==0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
m_stPoint.push(x);
m_stPoint.push(y);
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum!=0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
x=nRy=nCol+1;
if(y&m_nMapWidth)
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum==0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
m_stPoint.push(x);
m_stPoint.push(y);
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum!=0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
x=nRow+1;y=nCol-1;
if(x&m_nMapHeight&&y&=0)
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum==0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
m_stPoint.push(x);
m_stPoint.push(y);
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum!=0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
x=nRow+1;y=nC
if(x&m_nMapHeight)
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum==0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
m_stPoint.push(x);
m_stPoint.push(y);
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum!=0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
x=nRow+1;y=nCol+1;
if(x&m_nMapHeight&&y&m_nMapWidth)
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum==0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
m_stPoint.push(x);
m_stPoint.push(y);
if(!m_pMap[x][y].bShow&&
m_pMap[x][y].nBomboNum!=0&&
!m_pMap[x][y].bMine)
m_pMap[x][y].bShow=
MineLogic::ShowMap()
for(int i=0;i&m_nMapW++i)
for(int j=0;j&m_nMapH++j)
if(m_pMap[i][j].bMine)
printf(& B&);
printf(& %d&,m_pMap[i][j].nBomboNum);
printf(&\n&);
printf(&\n\n&);
MineLogic::ShowUserMap()
for(int i=0;i&m_nMapW++i)
for(int j=0;j&m_nMapH++j)
if(m_pMap[i][j].bShow)
if(m_pMap[i][j].bMine)
printf(& B&);
printf(& %d&,m_pMap[i][j].nBomboNum);
printf(& X&);
printf(&\n&);
printf(&\n\n&);
MineLogic::SetFind(int nRow,int nCol,bool b)
if(m_pMap[nRow][nCol].bMine)
m_pMap[nRow][nCol].bFind=b;
MineLogic::AllFind()
for(int i=0;i&m_nMapH++i)
for(int j=0;j&m_nMapW++j)
if(!m_pMap[i][j].bFind&&
m_pMap[i][i].bMine)
MineLogic::GetFind(int nRow,int nCol)
return m_pMap[nRow][nCol].bF
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:90738次
积分:1517
积分:1517
排名:千里之外
原创:57篇
转载:16篇
评论:36条
(2)(2)(1)(4)(4)(4)(5)(1)(1)(2)(2)(1)(2)(1)(3)(1)(1)(1)(4)(3)(1)(1)(2)(1)(1)(1)(4)(5)(3)(1)(1)(2)(2)(1)(2)(2)

参考资料

 

随机推荐