void CWmFace::CreateBomb()
{
static bool b_seeded = 0;
if(!b_seeded) {
b_seeded = 1;
srand((unsigned)time(NULL));
}
int i=0,x,y,_x,_y,__x,__y;
if(m_Wm) delete m_Wm;
m_Wm = new int[m_iw*m_ih];
for(i=0; i<m_iw*m_ih; i++)
m_Wm[i]=0;
int off[3][3][2] = {
{{-1,-1},{0,-1},{1,-1}},
{{-1,0},{0,0},{1,0}},
{{-1,1},{0,1},{1,1}}
};
i=0;
while (i<m_iWmCnt)
{
x=rand()%m_iw;
y=rand()%m_ih;
if(m_Wm[y*m_iw+x]!=ISMINE)
{
// set bomb
m_Wm[y*m_iw+x]=ISMINE; i++;
// set the eight cells around bomb
for (_x=0;_x<3;_x++)
for (_y=0;_y<3;_y++)
{
__x = x+off[_x][_y][0];
__y = y+off[_x][_y][1];
if((__x>=0)&&(__y>=0)&&(__x<m_iw)&&(__y<m_ih))
if (m_Wm[__y*m_iw+__x]!=ISMINE)
m_Wm[__y*m_iw+__x]++;
}//end for
}// end if
}//end while
}
void CWmFace::FindEmpty(int x, int y)
{
CPoint pt;int i;
que *q=NULL;
InitQue(&q, m_ih*m_iw);
InQue(q, CPoint(x,y));
while (!IsEmptyQue(q))
{
OutQue(q, pt);
int off[4][2]={{pt.x-1,pt.y},{pt.x+1,pt.y},{pt.x,pt.y-1},{pt.x,pt.y+1}};
for (i=0; i<4; i++)
{
if((off[i][0]>=0)&&(off[i][1]>=0)&&(off[i][0]<m_iw)&&(off[i][1]<m_ih))
if (!GetElem(off[i][0],off[i][1])->IsOpened())
{
GetElem(off[i][0],off[i][1])->Open();
if(GetElem(off[i][0],off[i][1])->IsEmpty())
InQue(q, CPoint(off[i][0],off[i][1]));
}
}
}
DestroyQue(&q);
}
saolei.zip_visual c
版权申诉
61 浏览量
2022-09-24
03:28:55
上传
评论
收藏 810B ZIP 举报
weixin_42653672
- 粉丝: 93
- 资源: 1万+
最新资源
- BrushNet电商公司和摄影公司都在用的AI工作流
- 12_base.apk
- 520马上到了两款动态爱心表白HTML代码(附源码)李峋同款爱心,快送给你爱的她或(他)吧12 情侣纪念日代码.zip
- 电子设计竞赛的单相不间断电源设计
- cutcamera1715961370938.png
- 基于MATLAB的图像处理课程设计报告.doc
- tensorflow-gpu-2.6.0-cp38-cp38-manylinux2010-x86-64.whl
- mmexport1715960553858.png
- tensorflow-gpu-2.6.0-cp37-cp37m-manylinux2010-x86-64.whl
- 通过 .NET 应用程序中的源代码查找 SQL 注入
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈