delete []Maze[i];
}
for(i=0;i<ySize+1;i++)
{
delete []HWall[i];
}
for(i=0;i<ySize+1;i++)
{
delete []VWall[i];
}
return 0;
}
2.在对话框中显示迷宫
显示迷宫需要在WM_PAINT消息的处理函数中添加代码,在程序中走迷宫的主角是一个小动物,如图4所示,这也是一个emf类型的文件,实现的代码如下:
图4 游戏主角
void CMyDlg::OnPaint()
{
…… /*省略部分是工程自动生成的代码*/
this->GetClientRect(&rect); /*获得对话框的客户区参数,赋值给CRect变量rect*/
rect.left=rect.right/8;
rect.right=7*rect.right/8;
rect.top=rect.bottom/8;
rect.bottom=7*rect.bottom/8;
PlayEnhMetaFile(dc.m_hDC,maze.hemf,&rect); /*按比例画出在迷宫中移动的图标*/
nLeft=rect.left;
nTop=rect.top;
nWidth=rect.Width();
nHeight=rect.Height();
/*以下根据图标移动的路线,在迷宫中显示图标*/
HDC hdcEmf1=CreateEnhMetaFile(NULL,"emf2.emf",NULL,NULL);
DrawIcon(hdcEmf1,0,0,HIcon);
rect2.left=rect.left + nWidth*(maze.current_x)/maze.xSize;
rect2.right=rect2.left + nWidth/maze.xSize;
rect2.top=rect.top + nHeight*(maze.current_y)/maze.ySize ;
rect2.bottom=rect2.top + nHeight/maze.ySize;
maze.hemf2=CloseEnhMetaFile(hdcEmf1);
PlayEnhMetaFile(dc.m_hDC,maze.hemf2,&rect2);
}
|