你好,欢迎来到电脑编程技巧与维护杂志社! 杂志社简介广告服务读者反馈编程社区  
合订本订阅
 
 
您的位置:杂志经典 / 图形图象处理与游戏编程
用VC编程迷宫游戏(七)
 

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);

}

  推荐精品文章

·2024年2月目录 
·2024年1月目录
·2023年12月目录
·2023年11月目录
·2023年10月目录
·2023年9月目录 
·2023年8月目录 
·2023年7月目录
·2023年6月目录 
·2023年5月目录
·2023年4月目录 
·2023年3月目录 
·2023年2月目录 
·2023年1月目录 

  联系方式
TEL:010-82561037
Fax: 010-82561614
QQ: 100164630
Mail:gaojian@comprg.com.cn

  友情链接
 
Copyright 2001-2010, www.comprg.com.cn, All Rights Reserved
京ICP备14022230号-1,电话/传真:010-82561037 82561614 ,Mail:gaojian@comprg.com.cn
地址:北京市海淀区远大路20号宝蓝大厦E座704,邮编:100089