MoveToEx(hdcEmf,0,0,NULL);
LineTo(hdcEmf,STEP*xSize+1,0);
MoveToEx(hdcEmf,0,0,NULL);
LineTo(hdcEmf,0,STEP*ySize+1);
MoveToEx(hdcEmf,STEP*xSize+1,0,NULL);
LineTo(hdcEmf,STEP*xSize+1,STEP*ySize+1);
MoveToEx(hdcEmf,0,STEP*ySize+1,NULL);
LineTo(hdcEmf,STEP*xSize+1,STEP*ySize+1); /*以上几句画出迷宫的外围*/
/*下面的二重循环根据Maze数组表示的迷宫中各块的连通情况,画出迷宫内部的围墙*/
for(i=1;i<ySize+1;i++)
for(j=1;j<xSize+1;j++)
{
int t=abs(Maze[i][j]-Maze[i][j+1]);
if(!(t<=1||(t-1000)==Maze[i][j]||t-1000==Maze[i][j+1]))
{
MoveToEx(hdcEmf,j*STEP,i*STEP-STEP,NULL);
LineTo(hdcEmf,j*STEP,i*STEP);
if (!VWall[j][i-1]) VWall[j][i-1]=1;
}
t=abs(Maze[i][j]-Maze[i+1][j]);
if(!(t<=1||(t-1000)==Maze[i][j]||t-1000==Maze[i+1][j]))
{
MoveToEx(hdcEmf,j*STEP-STEP,i*STEP,NULL);
LineTo(hdcEmf,j*STEP,i*STEP);
if (!HWall[j-1][i]) HWall[j-1][i]=1;
}
}
DeleteObject(SelectObject(hdcEmf,GetStockObject(BLACK_PEN)));
SelectObject(hdcEmf,GetStockObject(WHITE_PEN));
MoveToEx(hdcEmf,STEP,0,NULL);
LineTo(hdcEmf,2*STEP,0);
MoveToEx(hdcEmf,STEP*(xSize-2),STEP*ySize,NULL);
LineTo(hdcEmf,STEP*(xSize-1),STEP*ySize);
DeleteObject(SelectObject(hdcEmf,GetStockObject(WHITE_PEN)));
hemf=CloseEnhMetaFile(hdcEmf); /*释放emf文件的句柄*/
return TRUE;
}
函数int DestroyMaze(),用于销毁迷宫,释放内存,代码如下:
int CMaze::DestroyMaze()
{
int i;
for(i=0;i<ySize+2;i++)
{
|