带爆炸效果的扫雷(源码3)

队列:当点击一个空白格子的时候,算法如下:

将当前格子入队;

循环:一个格子出队。将没有打开的空白格子进队(要没有打开过,且是空白)。将周围的格子置为“已打开”。不断重复,直至队列为空。为了方便,将一个格子周围8个格子的坐标差值放到数组中,循环使用。

void GameMap::SearchBlank(int x,int y)
{
 int tempindex[16]={-1, -1,  0, -1, 1, -1,
                 -1 ,0,          1, 0,
        -1, 1,   0, 1,  1, 1};             
.......

}

队列: queue.h  queue.cpp


#ifndef __QUEUE_H
#define  __QUEUE_H

class  GQUEUE
{
public:
    GQUEUE();
    
~GQUEUE();

    
void CreateQueue(int len);
    
void DeleteQueue();

    
void CreateLog();    

    
int InQueue(POINT x);
    POINT OutQueue(
void);
    
int IsFull();
    
int IsEmpty();

private:
    POINT pData[
400];
    
int front;
    
int rear;
    
int length;
}
;

#endif

/ queue.cpp //
// 队列,用来做空白格子的搜索
#include  " stdafx.h "

#include 
" queue.h "
#include 
" stdio.h "

GQUEUE::GQUEUE()
{
    front
=0;
    rear
=0;
    length
=0;
}

GQUEUE::
~ GQUEUE()
{
}


void  GQUEUE::CreateQueue( int  len)
{
    front
=0;
    rear
=0;
    length
=len;

    memset(pData,
-1,sizeof(pData));
}

void  GQUEUE::DeleteQueue()
{
}


int  GQUEUE::InQueue(POINT x)
{
    pData[rear]
=x;
    rear
=(rear+1)%length;
    
return 1;
}


POINT GQUEUE::OutQueue(
void )
{
    
int temp_index;
    temp_index
=front;
    front
=(front+1)%length;
    
    
return pData[temp_index];
}

int  GQUEUE::IsFull()
{
    
return ((rear+1)%length == front)?1:0;
}

int  GQUEUE::IsEmpty()
{
    
return (rear == front)?1:0;
}


void  GQUEUE::CreateLog()
{
//    flog=fopen("queuelog.txt","w");
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值