我的扫雷程序

近来自己学习MFC,于是编写了一个扫雷程序,以下对程序中的几点做一下描述:

1、本程序利用SDI(单文档),创建主体框架。

2、利用绘图与BitBlt创建3D效果和雷区。

3、利用三个数组表示雷区。一个是BOOL型的,表示是否已经打开;一个是int的,表示要显示的数,-1表示雷,正数表示周围雷数,一个是int的,表是显示的方式(如:有无标记)。

4、判断周围雷数的算法,采用遍历方法。

如下:countx表示列数,county表示行数,

         int m,n;
       int temp[8][2]={-1,-1,
                       -1, 0,
                          -1, 1,
                        0,-1,
                        0, 1,
                        1,-1,
                        1, 0,
                        1, 1};
       for(i=0;i<countx;i++)
         for(j=0;j<county;j++)
         {
           if(-1!=m_BombText[i][j])
           {
              for(int k=0;k<8;k++)
            {   m=i+temp[k][0];
                n=j+temp[k][1];
                if(m>=0 && m<countx && n>=0 && n<county)
                {
                    if(-1==m_BombText[m][n])
                        count++;
                }
            }
            m_BombText[i][j]=count;
            count=0;
           }
         }

5、当点到空的格时,应用递归的方法将周围格子显示出来。代码如下:

void empty(int i,int j,int xcount,int ycount,int (*status)[31],int (*text)[31],int (*map)[31])
{
    int m,n;
    int temp[8][2]={-1,-1,
                    -1, 0,
                    -1, 1,
                     0,-1,
                     0, 1,
                     1,-1,
                     1, 0,
                     1, 1};
    for(int k=0;k<8;k++)
    {   m=i+temp[k][0];
        n=j+temp[k][1];
        if(0==m_BombMap[m][n])
        {
        if(m>=0 && m<xcount && n>=0 && n<ycount)
        {
            *(*(status+m)+n)=TRUE;
            *(*(map+m)+n)=2;
            *(*(text+i)+j)=-10;
            if(0==*(*(text+m)+n))
                 empty(m,n,xcount,ycount,status,text,map);
            *(*(text+i)+j)=0;
        }
        }

    }

 

源程序见http://smallmuou.download.csdn.net/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值