您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > 面向技术华容道操作步骤何重点讲义资料
1华容道游戏程序操作步骤头文件放置:(1)确定VC6.0安装是默认路径还是自定义路径A、默认路径:将openGL文件夹内所有‘.h’类型文件复制到C:\ProgramFile\MicrosoftVisualC++6.0\VC98\Include\GL文件夹下。将openGL文件夹内所有‘.lib’类型文件复制到C:\ProgramFile\MicrosoftVisualC++6.0\VC98\Lib文件夹下。B、自定义路径:先找到安装VisualC++6.0的路径。找到VC98文件夹将openGL文件夹内所有‘.h’类型文件复制到…\VC98\Include\GL文件夹下。将openGL文件夹内所有‘.lib’类型文件复制到…\VC98\Lib文件夹下。(2)将openGL文件夹内所有‘.dll’类型文件复制到C:\WINDOWS\System32文件夹中。1,打开VC++6.0,新建MFC单文档应用程序,项目名称:HUARD,并将picture文件夹拷贝到此项目文件夹下。(先建工程,再将picture文件夹拷贝到所建立文件夹HUARD中)图1新建MFC单文档应用程序工程,工程名称:HUARD2图2选择“单文档”程序类型,点击“完成”2打开“资源视图”,在Menu下双击“IDR_MAINFRAME”,新建如下菜单:图3新建菜单菜单子项ID比翼横空ID_BYHK三军联防ID_SJLF重重包围ID_CCBW调兵遣将ID_DBQJ水泄不通ID_SXBT3点击”HUARDclasses”,鼠标右击,选择“newclass”.3图3_1新建Cell类选择Genericclass,单击ok.(genericCWnd是派生cwind类)图3_2新建cell类4.在cell.h文件中的classcell中添加如下成员变量和成员函数:右击类classcell,加成员变量和成员函数。(cell类型是一个单元格类型。通过界面不难看出棋子是由一个或多个正方形构成的。而cell类型则是构建这个正方形的单元格)Public:4voidSetpos(GLfloatx,GLfloaty);voidSetchessname(GLintname);voidSetcellstate(GLintstate);intGetchessname();intGetcellstate();boolDrawChess(GLuint*texture);boolCopyCell(cell&tcell);boolclear();private:GLfloatpos_x;GLfloatpos_y;GLintcellstate;GLintchessname;GLuinttexid;//(在这里很多类似GLint数据类型的定义。其实就是我们所熟悉的int类型数据。GL是一个平台转换功能。可根据平台的不同,而使后面的int类型能自动适应所在平台。)添加方法如下:图4_1新建成员函数5图4_2添加成员函数voidSetpos(GLfloatx,GLfloaty);图4_3添加成员变量6图4_4添加成员变量GLfloatpos_x;5.在步骤4中添加的函数中添加对应代码,并在cell.h文件首添加头文件:“#includeGL/glut.h”,并在cell.cpp中添加函数boolcell::CopyCell(cell&tcell)//复制单元中棋子名称和位置。传引用调用CELL类型变量{chessname=tcell.Getchessname();cellstate=tcell.Getcellstate();tcell.clear();returntrue;}boolcell::clear()//将位置和名字置为0{chessname=CN_EMPTY;cellstate=CS_EMPTY;returntrue;}voidcell::Setpos(GLfloatx,GLfloaty)//赋值位置坐标{pos_x=x;pos_y=y;}voidcell::Setchessname(GLintname)//赋值棋子名字{chessname=name;}voidcell::Setcellstate(GLintstate)//赋值棋子部分{cellstate=state;}intcell::Getchessname()//获得棋子名字{returnchessname;}intcell::Getcellstate()//获得位置{returncellstate;}7boolcell::DrawChess(GLuint*texture)//画棋子,并为每个棋子的纹理标号。{glPushMatrix();//把当前的矩阵数据压栈(就是保存起来)glTranslatef(pos_x,pos_y,0.0);//沿着矩阵中X和Y的位置移动switch(chessname){caseCN_CAOCAO:glBindTexture(GL_TEXTURE_2D,texture[0]);//建立一个绑定到目标纹理的有名称的纹理break;caseCN_ZHANGFEI:switch(cellstate){caseCS_LEFT:caseCS_RIGHT:glBindTexture(GL_TEXTURE_2D,texture[6]);break;caseCS_BOTTOM:caseCS_TOP:glBindTexture(GL_TEXTURE_2D,texture[7]);break;}break;caseCN_ZHAOYUN:switch(cellstate){caseCS_LEFT:caseCS_RIGHT:glBindTexture(GL_TEXTURE_2D,texture[8]);break;caseCS_BOTTOM:caseCS_TOP:glBindTexture(GL_TEXTURE_2D,texture[9]);break;}break;caseCN_MACHAO:switch(cellstate){caseCS_LEFT:caseCS_RIGHT:glBindTexture(GL_TEXTURE_2D,texture[4]);break;8caseCS_BOTTOM:caseCS_TOP:glBindTexture(GL_TEXTURE_2D,texture[5]);break;}break;caseCN_GUANYU:switch(cellstate){caseCS_LEFT:caseCS_RIGHT:glBindTexture(GL_TEXTURE_2D,texture[1]);break;caseCS_BOTTOM:caseCS_TOP:glBindTexture(GL_TEXTURE_2D,texture[1]);break;}break;caseCN_HUANGZHONG:switch(cellstate){caseCS_LEFT:caseCS_RIGHT:glBindTexture(GL_TEXTURE_2D,texture[2]);break;caseCS_BOTTOM:caseCS_TOP:glBindTexture(GL_TEXTURE_2D,texture[3]);break;}break;caseCN_BIN:caseCN_YONG:caseCN_ZU:caseCN_DIN:glBindTexture(GL_TEXTURE_2D,texture[10]);break;caseCN_EMPTY:glBindTexture(GL_TEXTURE_2D,texture[12]);break;9}glBegin(GL_QUADS);switch(cellstate){caseCS_TOPLEFT:glTexCoord2f(0.0f,0.5f);glVertex3f(0.0,0.0,0.0);//glTexCoord*()设置纹理坐标,glVertex*()设置顶点坐标glTexCoord2f(0.5f,0.5f);glVertex3f(1.0,0.0,0.0);glTexCoord2f(0.5f,1.0f);glVertex3f(1.0,1.0,0.0);glTexCoord2f(0.0f,1.0f);glVertex3f(0.0,1.0,0.0);break;caseCS_TOPRIGHT:glTexCoord2f(0.5f,0.5f);glVertex3f(0.0,0.0,0.0);glTexCoord2f(1.0f,0.5f);glVertex3f(1.0,0.0,0.0);glTexCoord2f(1.0f,1.0f);glVertex3f(1.0,1.0,0.0);glTexCoord2f(0.5f,1.0f);glVertex3f(0.0,1.0,0.0);break;caseCS_BOTTOMLEFT:glTexCoord2f(0.0f,0.0f);glVertex3f(0.0,0.0,0.0);glTexCoord2f(0.5f,0.0f);glVertex3f(1.0,0.0,0.0);glTexCoord2f(0.5f,0.5f);glVertex3f(1.0,1.0,0.0);glTexCoord2f(0.0f,0.5f);glVertex3f(0.0,1.0,0.0);break;caseCS_BOTTOMRIGHT:glTexCoord2f(0.5f,0.0f);glVertex3f(0.0,0.0,0.0);glTexCoord2f(1.0f,0.0f);glVertex3f(1.0,0.0,0.0);glTexCoord2f(1.0f,0.5f);glVertex3f(1.0,1.0,0.0);glTexCoord2f(0.5f,0.5f);glVertex3f(0.0,1.0,0.0);break;caseCS_LEFT:glTexCoord2f(0.0f,0.0f);glVertex3f(0.0,0.0,0.0);glTexCoord2f(0.5f,0.0f);glVertex3f(1.0,0.0,0.0);glTexCoord2f(0.5f,1.0f);glVertex3f(1.0,1.0,0.0);glTexCoord2f(0.0f,1.0f);glVertex3f(0.0,1.0,0.0);break;caseCS_RIGHT:glTexCoord2f(0.5f,0.0f);glVertex3f(0.0,0.0,0.0);glTexCoord2f(1.0f,0.0f);glVertex3f(1.0,0.0,0.0);glTexCoord2f(1.0f,1.0f);glVertex3f(1.0,1.0,0.0);glTexCoord2f(0.5f,1.0f);glVertex3f(0.0,1.0,0.0);break;caseCS_TOP:glTexCoord2f(0.0f,0.5f);glVertex3f(0.0,0.0,0.0);glTexCoord2f(1.0f,0.5f);glVertex3f(1.0,0.0,0.0);10glTexCoord2f(1.0f,1.0f);glVertex3f(1.0,1.0,0.0);glTexCoord2f(0.0f,1.0f);glVertex3f(0.0,1.0,0.0);break;caseCS_BOTTOM:glTexCoord2f(0.0f,0.0f);glVertex3f(0.0,0.0,0.0);glTexCoord2f(1.0f,0.0f);glVertex3f(1.0,0.0,0.0);glTexCoord2f(1.0f,0.5f);glVertex3f(1.0,1.0,0.0);glTexCoord2f(0.0f,0.5f);glVertex3f(0.0,1.0,0.0);break;caseCS_BIN:caseCS_EMPTY:glTexCoord2f(0.0f,
本文标题:面向技术华容道操作步骤何重点讲义资料
链接地址:https://www.777doc.com/doc-3196579 .html