队列:当点击一个空白格子的时候,算法如下:
将当前格子入队;
循环:一个格子出队。将没有打开的空白格子进队(要没有打开过,且是空白)。将周围的格子置为“已打开”。不断重复,直至队列为空。为了方便,将一个格子周围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");
}