课程设计报告——基于vc的俄罗斯方块游戏设计报告内容摘要:

对游戏区域进行初始化外,还对各个类型的下坠物的到底以否的初始化(穷举)。 部分代码如下:CMy_RectView::CMy_RectView(){int i,j。 //赋初值for (i=0。 i100。 i++)for (j=0。 j100。 j++)GameStatus[i][j]=0。 //各种形状方块的接触面数据,参见设计书的接触面表格, //如果某种形状的方块没有 4 个接触面,则后面的数据填1for (i=0。 i74。 i++)for (j=0。 j4。 j++)InterFace[i][j] = 1。 24/*1 */InterFace[1][0] = 3。 InterFace[11][0] = 0。 InterFace[11][1] = 1。 InterFace[11][2] = 2。 InterFace[11][3] = 3。 /*2 */ InterFace[2][0] = 1。 InterFace[2][1] = 3。 /*3 */InterFace[3][0] = 0。 InterFace[3][1] = 2。 InterFace[3][2] = 3。 InterFace[31][0] = 2。 InterFace[31][1] = 3。 InterFace[32][0] = 0。 InterFace[32][1] = 2。 InterFace[32][2] = 3。 InterFace[33][0] = 0。 InterFace[33][1] = 3。 /*4 25 */InterFace[4][0] = 1。 InterFace[4][1] = 3。 InterFace[41][0] = 0。 InterFace[41][1] = 2。 InterFace[41][2] = 3。 /*5 */InterFace[5][0] = 1。 InterFace[5][1] = 3。 InterFace[51][0] = 0。 InterFace[51][1] = 2。 InterFace[51][2] = 3。 /*6 */InterFace[6][0] = 0。 InterFace[6][1] = 3。 InterFace[61][0] = 1。 InterFace[61][1] = 2。 InterFace[61][2] = 3。 InterFace[62][0] = 2。 InterFace[62][1] = 3。 InterFace[63][0] = 0。 InterFace[63][1] = 1。 InterFace[63][2] = 3。 /*267 */InterFace[7][0] = 2。 InterFace[7][1] = 3。 InterFace[71][0] = 1。 InterFace[71][1] = 2。 InterFace[71][2] = 3。 InterFace[72][0] = 0。 InterFace[72][1] = 3。 InterFace[73][0] = 0。 InterFace[73][1] = 1。 InterFace[73][2] = 3。 }(7)RectDown()将下坠物向下移动一个单元。 包括清除原来位置,位置坐标数据加一和和重绘下一位置两部分。 // 内部函数:当前方块下降void CMy_RectView::RectDown(){IsBottom()。 if (!m_isBottom){//清除以前的方块int x1,x2,x3,x4,y1,y2,y3,y4。 x1 = ActiveStatus[0][0]。 x2 = ActiveStatus[1][0]。 x3 = ActiveStatus[2][0]。 27x4 = ActiveStatus[3][0]。 y1 = ActiveStatus[0][1]。 y2 = ActiveStatus[1][1]。 y3 = ActiveStatus[2][1]。 y4 = ActiveStatus[3][1]。 GameStatus[x1][y1]=MAP_STATE_EMPTY。 GameStatus[x2][y2]=MAP_STATE_EMPTY。 GameStatus[x3][y3]=MAP_STATE_EMPTY。 GameStatus[x4][y4]=MAP_STATE_EMPTY。 InvalidateCurrent()。 //方块下落ActiveStatus[0][0] += 1。 ActiveStatus[1][0] += 1。 ActiveStatus[2][0] += 1。 ActiveStatus[3][0] += 1。 GameStatus[x1+1][y1]=MAP_STATE_NOT_EMPTY。 GameStatus[x2+1][y2]=MAP_STATE_NOT_EMPTY。 GameStatus[x3+1][y3]=MAP_STATE_NOT_EMPTY。 GameStatus[x4+1][y4]=MAP_STATE_NOT_EMPTY。 InvalidateCurrent()。 }28}(8)InvaliddateCurrent()函数对 44 的区域进行重绘,其代码如下://内部函数:刷新当前的区域// 只刷新需要刷新的四个小方块区域,防止屏幕抖动情况发生void CMy_RectView::InvalidateCurrent(){int i。 for (i=0。 i4。 i++){CRect rect(m_iStartX+ActiveStatus[i][1]*m_iLarge, m_iStartY+ActiveStatus[i][0]*m_iLarge,m_iStartX+(ActiveStatus[i][1]+1)*m_iLarge+5,m_iStartY+(ActiveStatus[i][0]+1)*m_iLarge)。 //InvalidateRect(amp。 rect)。 Invalidate(FALSE)。 }} 中断操作流程的实现整个游戏中,中断操作分别为向左移动、向右移动、向下加速和变形。 对于按键命令消息的响应,可以通过对 WM_KEYDOWN 消息的29处理函数进行截获并重写来实现,对于这个消息的添加,可以通过在 CMy_RectView 中通过添加 ClassWizard 进行实现,下面是对OnKeyDown()函数的重写。 // 名称:OnKeyDown// 功能:处理用户的输入,方块的左,右移,加速及变形void CMy_RectView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) {switch(nChar){case VK_LEFT:RectArrow(LEFT)。 break。 case VK_RIGHT:RectArrow(RIGHT)。 break。 case VK_UP:RectChange()。 break。 case VK_DOWN:RectArrow(DOWN)。 break。 30}CView::OnKeyDown(nChar, nRepCnt, nFlags)。 }用到的参数定义如下://中断操作的运动趋势define LEFT 0 //向左移动define RIGHT 1 //向左移动define UP 2 //向上(变形) define DOWN 3 //向下移动(加速)(1)左右移动和加速下移的实现//内部函数:当前方块下降加速,左移,右移void CMy_RectView::RectArrow(int m_Type){//获取当前下坠物 4 个小方块的位置坐标int x1,x2,x3,x4,y1,y2,y3,y4。 x1 = ActiveStatus[0][0]。 x2 = ActiveStatus[1][0]。 x3 = ActiveStatus[2][0]。 x4 = ActiveStatus[3][0]。 y1 = ActiveStatus[0][1]。 y2 = ActiveStatus[1][1]。 31y3 = ActiveStatus[2][1]。 y4 = ActiveStatus[3][1]。 //对不同的移动命令指示进行分类实现switch(m_Type){case LEFT://对每种不同的移动命令指示特性作相应的可移动分析if ( (ActiveStatus[0][1]0) amp。 amp。 IsLeftLimit() amp。 amp。 !m_isBottom){//清原来的方块GameStatus[x1][y1]=MAP_STATE_EMPTY。 GameStatus[x2][y2]=MAP_STATE_EMPTY。 GameStatus[x3][y3]=MAP_STATE_EMPTY。 GameStatus[x4][y4]=MAP_STATE_EMPTY。 // InvalidateCurrent()。 //添加新的移动后数据状态ActiveStatus[0][1] = 1。 ActiveStatus[1][1] = 1。 ActiveStatus[2][1] = 1。 32ActiveStatus[3][1] = 1。 GameStatus[x1][y11]=MAP_STATE_NOT_EMPTY。 GameStatus[x2][y21]=MAP_STATE_NOT_EMPTY。 GameStatus[x3][y31]=MAP_STATE_NOT_EMPTY。 GameStatus[x4][y41]=MAP_STATE_NOT_EMPTY。 InvalidateCurrent()。 }break。 case RIGHT:if ( (ActiveStatus[3][1] m_iCol1) amp。 amp。 IsRightLitmit() amp。 amp。 !m_isBottom){//清原来的方块GameStatus[x1][y1]=MAP_STATE_EMPTY。 GameStatus[x2][y2]=MAP_STATE_EMPTY。 GameStatus[x3][y3]=MAP_STATE_EMPTY。 GameStatus[x4][y4]=MAP_STATE_EMPTY。 // InvalidateCurrent()。 //添加新的移动后数据状态33ActiveStatus[0][1] += 1。 ActiveStatus[1][1] += 1。 ActiveStatus[2][1] += 1。 ActiveStatus[3][1] += 1。 GameStatus[x1][y1+1]=MAP_STATE_NOT_EMPTY。 GameStatus[x2][y2+1]=MAP_STATE_NOT_EMPTY。 GameStatus[x3][y3+1]=MAP_STATE_NOT_EMPTY。 GameStatus[x4][y4+1]=MAP_STATE_NOT_EMPTY。 InvalidateCurrent()。 }break。 case DOWN:RectDown()。 break。 }}在上面 Rect_Arrow()函数中对移动的方向进行了限制,分别是左限制 IsLeftLimit()和右限制 IsRightLimit()。 它们的原理是一样的,区别仅在于坐标而已。 下面给出 IsLeftLimit()的实现代码。 34// 内部函数:方块是否还可以左移BOOL CMy_RectView::IsLeftLimit(){int x1,x2,x3,x4,y1,y2,y3,y4。 x1 = ActiveStatus[0][0]。 x2 = ActiveStatus[1][0]。 x3 = ActiveStatus[2][0]。 x4 = ActiveStatus[3][0]。 y1 = ActiveStatus[0][1]。 y2 = ActiveStatus[1][1]。 y3 = ActiveStatus[2][1]。 y4 = ActiveStatus[3][1]。 //根据当前下坠物的具体形态,分析判断其是否有向左移动的空间switch(m_currentRect){/*| | | 1字形形态类型,判断其四个方块的正左边都35没有任何物件(空间没有被占据) | */case 1:if (GameStatus[x1][y11] || GameStatus[x2][y21。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。