已阅读5页,还剩26页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
西安科技大学 VC VC 程序设计程序设计 实验报告实验报告 题 目 双人版俄罗斯方块 院 系 部 计算机科学与技术 专业及班级 计科 1401 班 学 号 1408030126 姓 名 黄培 日 期 2016 5 30 1 1 题目要求 双人同时进行的俄罗斯方块 2 功能需求 1 双人同时进行的俄罗斯方块 2 方块可进行左右移动 旋转变形 加速下落 3 可以进行游戏难度的选择 分别为简单 中等 高级 3 总体设计 3 1系统模块 1 砖块显示模块 2 用户的控制模块 移动 旋转 加速下落 3 游戏难度模块 难度选择 分别为简单 中等 高级 3 2 系统业务处理流程 是 开始 选择游戏难度 开始游戏 随机产生方块 响应用户操作 到达底部 2 否 4 详细设计 1 Tetris 游戏的矩形框类设计 CBin 主要实现代码 2 2 Bin hBin h 3 ifndef BIN H 4 define BIN H 5 class CBin 6 private 7 unsigned char image 8 unsigned int width 9 unsigned int height 10 11 public 12 CBin unsigned int w unsigned int h 13 CBin 14 15 unsigned int getWidth return width 16 unsigned int getHeight return height 17 18 void getImage unsigned char destImage 19 void setImage unsigned char srcImage 20 21 unsigned int removeFullLines 22 23 endif 占满一行 下降一行 砖块是否到达顶端 是否 结束 3 Bin cpp include stdafx h include bin h CBin CBin unsigned int w unsigned int h width w height h image new unsigned char height for unsigned int i 0 i height i image i new unsigned char width for unsigned int j 0 j width j image i j 0 CBin CBin for unsigned int i 0 i height i delete image i delete image void CBin getImage unsigned char destImage for unsigned int i 0 i height i for unsigned int j 0 j width j destImage i j image i j void CBin setImage unsigned char srcImage for unsigned int i 0 i height i for unsigned int j 0 j width j image i j srcImage i j unsigned int CBin removeFullLines unsigned int flag EmptyLine 0 unsigned int i j m for i 0 i height i flag 0 for j 0 j width j 4 if image i j 0 flag 1 一行完全被填满 if flag 0 for j 0 j0 m for j 0 j width j image m j image m 1 j for j 0 j unsigned char binImage 0 virtual void putAtTop int newOrient int newPosX 0 virtual void putAtMid int newOrient int newPosX 0 class CIBrick public CBrick public int shiftLeft CBin bin int shiftRight CBin bin int shiftDown CBin bin int rotateClockwise CBin bin int checkCollision CBin bin void operator unsigned char binImage void putAtTop int newOrient int newPosX void putAtMid int newOrient int newPosX class CLBrick public CBrick public int shiftLeft CBin bin int shiftRight CBin bin int shiftDown CBin bin int rotateClockwise CBin bin 6 int checkCollision CBin bin void operator unsigned char binImage void putAtTop int newOrient int newPosX void putAtMid int newOrient int newPosX class CSBrick public CBrick public int shiftLeft CBin bin int shiftRight CBin bin int shiftDown CBin bin int rotateClockwise CBin bin int checkCollision CBin bin void operator unsigned char binImage void putAtTop int newOrient int newPosX void putAtMid int newOrient int newPosX class COBrick public CBrick public int shiftLeft CBin bin int shiftRight CBin bin int shiftDown CBin bin int rotateClockwise CBin bin int checkCollision CBin bin void operator unsigned char binImage void putAtTop int newOrient int newPosX void putAtMid int newOrient int newPosX endif Brick cpp int CIBrick shiftLeft CBin bin int posX posX getPosX setPosX posX 1 if checkCollision bin 0 setPosX posX return 0 7 return 1 int CIBrick shiftDown CBin bin int posY posY getPosY setPosY posY 1 if checkCollision bin 0 setPosY posY return 0 return 1 int CIBrick shiftRight CBin bin int posX posX getPosX setPosX posX 1 if checkCollision bin 0 setPosX posX return 0 return 1 int CIBrick rotateClockwise CBin bin int orientation oldOrientation orientation getOrientation oldOrientation orientation if orientation 3 orientation 0 else orientation orientation 1 setOrientation orientation if checkCollision bin 0 setOrientation oldOrientation return 0 return 1 int CIBrick checkCollision CBin bin 8 int width int height unsigned char image int orientation int posX int posY width bin getWidth height bin getHeight image new unsigned char height for int i 0 igetImage image orientation getOrientation posX getPosX posY getPosY I brick状态0 if orientation 0 砖块碰到边界 if posXwidth 1 posYheight 1 return 0 砖块碰到其他固定砖块 if image posY 1 posX 0 image posY posX 0 image posY 1 posX 0 image posY 2 posX 0 return 0 状态1 if orientation 1 if posXwidth 1 posYheight 1 return 0 if image posY posX 2 0 image posY posX 1 0 image posY posX 0 image posY posX 1 0 9 return 0 状态 2 if orientation 2 if posXwidth 1 posYheight 1 return 0 if image posY 2 posX 0 image posY 1 posX 0 image posY posX 0 image posY 1 posX 0 return 0 if orientation 3 if posXwidth 1 posYheight 1 return 0 if image posY posX 1 0 image posY posX 0 image posY posX 1 0 image posY posX 2 0 return 0 return 1 void CIBrick operator unsigned char binImage int orientation int posX int posY unsigned char colour posX getPosX posY getPosY orientation getOrientation colour getColour 状态 0 if orientation 0 10 binImage posY 1 posX colour binImage posY posX colour binImage posY 1 posX colour binImage posY 2 posX colour 状态 1 if orientation 1 binImage posY posX 2 colour binImage posY posX 1 colour binImage posY posX colour binImage posY posX 1 colour 状态 2 if orientation 2 binImage posY 2 posX colour binImage posY 1 posX colour binImage posY posX colour binImage posY 1 posX colour 状态 3 if orientation 3 binImage posY posX 1 colour binImage posY posX colour binImage posY posX 1 colour binImage posY posX 2 colour void CIBrick putAtTop int newOrient int newPosX setPosX newPosX setOrientation newOrient switch newOrient case 0 setPosY 1 break case 1 setPosY 0 break case 2 setPosY 2 break case 3 setPosY 0 break void CIBrick putAtMid int newOrient int newPosX setPosX newPosX 3 11 setOrientation newOrient switch newOrient case 0 setPosY 9 break case 1 setPosY 8 break case 2 setPosY 10 break case 3 setPosY 8 break CLBrick int CLBrick shiftLeft CBin bin int posX posX getPosX setPosX posX 1 if checkCollision bin 0 setPosX posX return 0 return 1 int CLBrick shiftDown CBin bin int posY posY getPosY setPosY posY 1 if checkCollision bin 0 setPosY posY return 0 return 1 int CLBrick shiftRight CBin bin int posX posX getPosX setPosX posX 1 if checkCollision bin 0 setPosX posX return 0 return 1 12 int CLBrick rotateClockwise CBin bin int orientation oldOrientation orientation getOrientation oldOrientation orientation if orientation 3 orientation 0 else orientation orientation 1 setOrientation orientation if checkCollision bin 0 setOrientation oldOrientation return 0 return 1 int CLBrick checkCollision CBin bin int width int height unsigned char image int orientation int posX int posY width bin getWidth height bin getHeight image new unsigned char height for int i 0 igetImage image orientation getOrientation posX getPosX posY getPosY if orientation 0 if posXwidth 1 posYheight 1 return 0 13 if image posY 1 posX 0 image posY posX 0 image posY 1 posX 0 image posY 1 posX 1 0 return 0 if orientation 1 if posXwidth 1 posYheight 1 return 0 if image posY 1 posX 1 0 image posY posX 1 0 image posY posX 0 image posY posX 1 0 return 0 if orientation 2 if posXwidth 1 posYheight 1 return 0 if image posY 1 posX 1 0 image posY 1 posX 0 image posY posX 0 image posY 1 posX 0 return 0 if orientation 3 if posXwidth 1 posYheight 1 return 0 if image posY posX 1 0 image posY posX 0 image posY posX 1 0 image posY 1 posX 1 0 return 0 14 return 1 void CLBrick operator unsigned char binImage int orientation int posX int posY unsigned char colour posX getPosX posY getPosY orientation getOrientation colour getColour if orientation 0 binImage posY 1 posX colour binImage posY posX colour binImage posY 1 posX colour binImage posY 1 posX 1 colour if orientation 1 binImage posY 1 posX 1 colour binImage posY posX 1 colour binImage posY posX colour binImage posY posX 1 colour if orientation 2 binImage posY 1 posX 1 colour binImage posY 1 posX colour binImage posY posX colour binImage posY 1 posX colour if orientation 3 binImage posY posX 1 colour binImage posY posX colour binImage posY posX 1 colour binImage posY 1 posX 1 colour void CLBrick putAtTop int newOrient int newPosX setPosX newPosX setOrientation newOrient 15 switch newOrient case 0 setPosY 1 break case 1 setPosY 0 break case 2 setPosY 1 break case 3 setPosY 1 break void CLBrick putAtMid int newOrient int newPosX setPosX newPosX 3 setOrientation newOrient switch newOrient case 0 setPosY 9 break case 1 setPosY 8 break case 2 setPosY 9 break case 3 setPosY 9 break CSBrick int CSBrick shiftLeft CBin bin int posX posX getPosX setPosX posX 1 if checkCollision bin 0 setPosX posX return 0 return 1 int CSBrick shiftDown CBin bin int posY posY getPosY setPosY posY 1 if checkCollision bin 0 setPosY posY return 0 16 return 1 int CSBrick shiftRight CBin bin int posX posX getPosX setPosX posX 1 if checkCollision bin 0 setPosX posX return 0 return 1 int CSBrick rotateClockwise CBin bin int orientation oldOrientation orientation getOrientation oldOrientation orientation if orientation 3 orientation 0 else orientation orientation 1 setOrientation orientation if checkCollision bin 0 setOrientation oldOrientation return 0 return 1 int CSBrick checkCollision CBin bin int width int height unsigned char image int orientation int posX int posY width bin getWidth height bin getHeight image new unsigned char height for int i 0 igetImage image orientation getOrientation posX getPosX posY getPosY if orientation 0 if posXwidth 1 posYheight 1 return 0 if image posY 1 posX 0 image posY 1 posX 1 0 image posY posX 0 image posY posX 1 0 return 0 if orientation 1 if posXwidth 1 posYheight 1 return 0 if image posY 1 posX 0 image posY posX 1 0 image posY posX 0 image posY 1 posX 1 0 return 0 if orientation 2 if posXwidth 1 posYheight 1 return 0 if image posY posX 1 0 image posY 1 posX 0 image posY posX 0 image posY 1 posX 1 0 return 0 if orientation 3 18 if posXwidth 1 posYheight 1 return 0 if image posY posX 1 0 image posY 1 posX 1 0 image posY posX 0 image posY 1 posX 0 return 0 return 1 void CSBrick operator unsigned char binImage int orientation int posX int posY unsigned char colour posX getPosX posY getPosY orientation getOrientation colour getColour if orientation 0 binImage posY 1 posX colour binImage posY posX colour binImage posY 1 posX 1 colour binImage posY posX 1 colour if orientation 1 binImage posY 1 posX 1 colour binImage posY posX 1 colour binImage posY posX colour binImage posY 1 posX colour if orientation 2 binImage posY posX 1 colour binImage posY 1 posX colour 19 binImage posY posX colour binImage posY 1 posX 1 colour if orientation 3 binImage posY posX 1 colour binImage posY posX colour binImage posY 1 posX 1 colour binImage posY 1 posX colour void CSBrick putAtTop int newOrient int newPosX setPosX newPosX setOrientation newOrient switch newOrient case 0 setPosY 1 break case 1 setPosY 1 break case 2 setPosY 0 break case 3 setPosY 1 break void CSBrick putAtMid int newOrient int newPosX setPosX newPosX 3 setOrientation newOrient switch newOrient case 0 setPosY 9 break case 1 setPosY 9 break case 2 setPosY 8 break case 3 setPosY 9 break COBrick int COBrick shiftLeft CBin bin int posX posX getPosX setPosX posX 1 20 if checkCollision bin 0 setPosX posX return 0 return 1 int COBrick shiftDown CBin bin int posY posY getPosY setPosY posY 1 if checkCollision bin 0 setPosY posY return 0 return 1 int COBrick shiftRight CBin bin int posX posX getPosX setPosX posX 1 if checkCollision bin 0 setPosX posX return 0 return 1 int COBrick rotateClockwise CBin bin int orientation oldOrientation orientation getOrientation oldOrientation orientation if orientation 3 orientation 0 else orientation orientation 1 setOrientation orientation if checkCollision bin 0 setOrientation oldOrientation return 0 21 return 1 int COBrick checkCollision CBin bin int width int height unsigned char image int orientation int posX int posY width bin getWidth height bin getHeight image new unsigned char height for int i 0 igetImage image orientation getOrientation posX getPosX posY getPosY 状态1 if orientation 0 if posXwidth 1 posYheight 1 return 0 if image posY posX 1 0 image posY posX 0 image posY 1 posX 1 0 image posY 1 posX 0 return 0 状态2 if orientation 1 if posXwidth 1 posYheight 1 return 0 if image posY 1 posX 1 0 image posY 1 posX 0 22 image posY posX 1 0 image posY posX 0 return 0 状态3 if orientation 2 if posXwidth 1 posYheight 1 return 0 if image posY 1 posX 0 image posY 1 posX 1 0 image posY posX 0 image posY posX 1 0 return 0 状态4 if orientation 3 if posXwidth 1 posYheight 1 return 0 if image posY posX 1 0 image posY posX 0 image posY 1 posX 0 image posY 1 posX 1 0 return 0 return 1 void COBrick operator unsigned char binImage int orientation int posX int posY unsigned char colour posX getPosX posY getPosY orientation getOrientation colour getColour if orientation 0 23 binImage posY posX 1 colour binImage posY posX colour binImage posY 1 posX 1 colour binImage posY 1 posX colour if orientation 1 binImage posY 1 posX 1 colour binImage posY 1 posX colour binImage posY posX 1 colour binImage posY posX colour if orientation 2 binImage posY 1 posX colour binImage posY 1 posX 1 colour binImage posY posX colour binImage posY posX 1 colour if orientation 3 binImage posY posX 1 colour binImage posY posX colour binImage posY 1 posX colour binImage posY 1 posX 1 colour void COBrick putAtTop int newOrient int newPosX setPosX newPosX setOrientation newOrient switch newOrient case 0 setPosY 0 break case 1 setPosY 1 break case 2 setPosY 1 break case 3 setPosY 0 break void COBrick putAtMid int newOrient int newPosX setPosX newPosX 3 setOrientation newOrient 24 switch newOrient case 0 setPosY 8 break case 1 setPosY 9 break case 2 setPosY 9 break case 3 setPosY 8 break 3 用 AppWizard 新建一个单文档应用程序 NewTetris 将 bin h bin cpp brick h brick cpp 文件加入 NewTetris 工程 4 视图类成员变量的添加 5 CBin bin bin1 定义游戏矩形框指针 6 CBrick activeBrick activeBrick1 定义指向当前下落砖块的指针 7 int gameOver 判断游戏是否结束 8 int gameOver1 9 int brickInFlight 判断砖块是否处于下落状态 10 int brickInFlight1 11 int brickType 砖块类别 12 int brickType1 13 unsigned int initOrientation 初始状态 14 unsigned int initOrientation1 15 int notCollide 冲突否 16 int notCollide1 17 unsigned int numLines 消的行数 18 unsigned int numLines1 19 unsigned char outputImage 20 unsigned char outputImage1 int difficulty 定义难度 4 在视图类定义 NewTetrisView h 中添加公有的成员函数的声明 5 void CNewTerisView DrawImage CBin bin CBin bin1 unsigned char image unsigned char image1 CDC pDC 6 7 unsigned int width i j 8 unsigned int height width1 height1 9 width bin getWidth 10 height bin getHeight 11 width1 bin1 getWidth 12 height1 bin1 getHeight 13 int nSize 20 14 CRect rc 15 16 COLORREF BrickColor 8 0 xFFFFFF 0 xFF0000 0 x00FF00 0 x0000FF 0 x00FFFF 25 0 xFFFF00 0 x800000 0 x800080 17 18 pDC Rectangle 0 0 nSize
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 眉山市彭山区2025年引进人才(事业单位)部分岗位调整考试笔试备考题库及答案解析
- 故宫建筑的颜色搭配与文化意义分析
- 旅游行业策划书制作与销售策略
- 企业高管领导力培训与职业发展指导手册
- 农业经济现状与发展趋势分析
- 求职者如何有效应对面试中的压力问题
- 儿童教育心理学教程及实践指南
- 2026-2031年中国证券IT技术行业市场发展趋势与前景展望战略研究报告
- 轨道交通项目申报及执行要点解析
- 科学教育专业学生毕业论文选题参考
- 2024-2025学年上海市市东实验学校高二下学期3月月考数学试卷
- 货物装卸操作规程及安全操作规范
- 尿毒症患者饮食健康宣教
- 形象提升培训课件
- 假劣药题目及答案
- 税务师事务所管理制度
- 中国阻燃玻璃纤维行业市场前景预测及投资价值评估分析报告
- 托管服务机构转让协议书
- 人工智能在医学护理领域的应用与实践
- 土建工程施工合同协议书
- 签约办证协议书模板
评论
0/150
提交评论