




免费预览已结束,剩余19页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
西安科技大学计算机学院vc+程序设计实验报告题 目 俄罗斯方块游戏 学 号 0808030405 专业及班级 计算机科学与技术专业0804班姓 名 日 期 2010/11/25 一、 实验目的本实验的目的是综合前面所学的知识,参考实验指导书的知识,开发一个俄罗斯游戏。二、 设计思路1 游戏说明及规则tetris游戏在一个m*n的矩形框内进行。游戏开始时,矩形框的顶部会随机出现一个由四个小方块构成的砖块,每过一个很短时间(我们称这个时间为一个tick),它就会下落一格,直到它碰到矩形框的低部,然后再过一个tick它就会固定在矩形框的底部,成为固定块。接着再过一个tick顶部又会现一个随机形状,同样每隔一个 tick都会下落,直到接触到底部或者接触到下面的固定块时,再过一个tick它也会成为固定块,再过一个tick之后会进行检查,发现有充满方块的行则会消除它,同时顶部出现下一个随机形状。直到顶部出现的随机形状在刚出现时就与固定块重叠,表示游戏结束。操作说明:光标左键左移 光标右键右移 光标上键翻转 光标下键下移2 tetris的游戏分析,设计与实现(1)tetris游戏的矩形框类cbin 首先我们应该描述 tetris游戏的矩形框。这里我们定义一个cbin类描述tetris游戏的矩形框。对矩形框进行分析,它应该有三个私有的数据成员为:image,width和height.cbin类将tetris游戏的矩形框描述成为一个二维数组image,变量width和height存储了image的维数。接下来为cbin类添加五个成员函数:构造函数:cbin(unsigned int w,unsigned int h),析构函数:cbin(), void getimage(unsigned char*destimage), void setimage(unsigned char*srcimage),unsigned int removefulliines(). 然后分别在bin.h和bin.cpp中完成cbin类的定义和函数实现。 (2)tetris游戏的砖块类:第一步:建立类:cibrick, clbrick, csbrick,ctbrick, cfsbrick,cflbrick, cobrick,它们的基类都是cbrick类。它们都有有四个数据成员:orientation,posx,posy,colour. orientation表示”1”砖块的四个状态,可能取值为0,1,2,3,由状态0到状态1是”1”砖块固定一个特定点顺时针旋转90度.依次类推,状态3的下一个状态是状态0. posx,posy记录了特定点的坐标, colour为砖块的颜色值. 为cibrick重载7个虚构函数:int shifleft(cbin*bin), int shifright(cbin*bin),int shifdown(cbin*bin), int rotateclockwise(cbin*bin), int checkcollision (cbin*bin),void operator(unsigned char*binimage),void putattop(unsigned int neworient,unsigned int new posx).第二步:仿照cibrick,完成clbrick, csbrick,ctbrick, cfsbrick,cflbrick, cobrick类的实现,同样将类定义代码写在brick.h文件中,类实现代码写在brick.h文件中.3. 进一步完善(1)实现砖块的三维化在试图类定义(newtetrisview .h)中添加两个公有的成员函数声明。在视图类的实现文件(newtetrisview .cpp)中,添加这两个函数的实现代码。修改试图类的drawimage函数,添加代码。(2) 使用双缓冲技术解决屏幕闪烁 修改视图类的ondraw函数。修改视图类的drawimage函数。4背景音乐的实现。三、 代码实现(代码省略部分参照实验指导书)1. 然后分别在bin.h和bin.cpp中完成cbin类的定义和函数实现:在文件bin.h中添加三个成员变量和六个成员函数并初始化(代码省略) unsigned char*imgage; unsigned int width; unsigned int height; cbin(unsigned int w,unsigned int h); cbin(); unsigned int getwidth()return width;; unsigned int getheight()return height;; void getimage(unsigned char*destimage); void setimage(unsigned char*srcimage); unsigned int removefulllines(); ; (2)tetris游戏的砖块类: cbrick 类的说明如下(文件brick.h):class cbrickprotected:unsigned int orientation;/表示砖块的状态unsigned int posx; /砖块特定点的x坐标unsigned int posy; /砖块特定点的y坐标unsigned chai colour; /砖块的颜色public: unsigned int getorientation()return orientation; unsigned int getposx()return posx; unsigned int getposy()return posy; unsigned char getcolour()return colour;void setorientation(unsigned int neworient)orientation=neworient;void setposx(unsigned int newposx)posx=newposx; void setposy(unsigned int newposy)posy=newposy;void setcolour(unsigned char newcolour)colour=newcolour;virtual int shiftleft(cbin* bin)=0; virtual int shiftright(cbin* bin)=0; virtual int shiftdown(cbin* bin)=0; virtual int rotateclockwise(cbin* bin)=0;virtual int checkcollision(cbin* bin)=0;virtual void operator(unsigned char* binimage)=0;virtual void putattop(unsigned int neworient,unsigned int newposx)=0; cibrick需要重载7个虚函数,cibrick类的定义如下(文件brick .h):class cibrick:public cbrickpublic: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(unsigned int neworient,unsigned int newposx);在后面实现clbrick, csbrick,ctbrick, cfsbrick,cflbrick, cobrick的6种方块实现中按照上面的步骤重载7个上述虚函数。后面只将各个类型方块实现的代码列出来。/i型砖块代码的实现部分:cibrick类型砖块:(黑色方块为程序中所选的坐标点)cibrick类的实现代码(代码省略)/l型砖块代码的实现部分:clbrick类型砖块:(黑色方块为程序中所选的坐标点) (左移、右移、上键、下键即以下4个消息响应函数与i型砖块代码的实现部分相同,这里就不列出来了)shiftleft(cbin*bin)shiftdown(cbin*bin)shiftright(cbin*bin)rotateclockwise(cbin*bin)int clbrick:checkcollision(cbin *bin)unsigned int width;unsigned int height;unsigned char*image;unsigned int orientation;unsigned int posx;unsigned int posy;width=bin-getwidth();height=bin-getheight();image=new unsigned char*height;for(unsigned int i=0;igetimage(image);orientation=getorientation();posx=getposx();posy=getposy();if(orientation=0)if(posx+1width-1)|(posyheight-1)return 0;if(imageposy-2posx!=0)|(imageposy-1posx!=0)|(imageposyposx!=0)|(imageposyposx+1!=0)return 0;if(orientation=1)if(posx+1width-1)|(posy+1height-1)return 0;if(imageposyposx!=0)|(imageposyposx+1!=0)|(imageposyposx+2!=0)|(imageposy+1posx!=0)return 0;if(orientation=2)if(posxwidth-1)|(posy+1height-1)return 0;if(imageposyposx-1!=0)|(imageposyposx!=0)|(imageposy+1posx!=0)|(imageposy+2posx!=0)return 0;if(orientation=3)if(posxwidth-1)|(posyheight-1)return 0;if(imageposyposx-2!=0)|(imageposyposx-1!=0)|(imageposyposx!=0)|(imageposy-1posx!=0)return 0;return 1;void clbrick:operator(unsigned char* binimage)unsigned int orientation;unsigned int posx;unsigned int posy;unsigned char colour;posx=getposx();posy=getposy();orientation=getorientation();colour=getcolour();if(orientation=0)binimageposy-2posx=colour;binimageposy-1posx=colour;binimageposyposx=colour;binimageposyposx+1=colour;if(orientation=1)binimageposyposx=colour;binimageposyposx+1=colour;binimageposyposx+2=colour;binimageposy+1posx=colour;if(orientation=2)binimageposyposx-1=colour;binimageposyposx=colour;binimageposy+1posx=colour;binimageposy+2posx=colour;if(orientation=3)binimageposyposx-1=colour;binimageposyposx-2=colour;binimageposyposx=colour;binimageposy-1posx=colour;void clbrick:putattop(unsigned int neworient, unsigned int newposx)setposx(newposx);setorientation(neworient);switch(neworient)case 0: setposy(2);break;case 1: setposy(0);break;case 2: setposy(0);break;case 3: setposy(1);break; csbrick类型砖块:(黑色方块为程序中所选的坐标点)/s型砖块代码的实现部分:(左移、右移、上键、下键消息响应函数与i型砖块代码的实现部分相同,这里就不列出来了)shiftleft(cbin*bin)shiftdown(cbin*bin)shiftright(cbin*bin)rotateclockwise(cbin*bin)int csbrick:checkcollision(cbin *bin)unsigned int width;unsigned int height;unsigned char*image;unsigned int orientation;unsigned int posx;unsigned int posy;width=bin-getwidth();height=bin-getheight();image=new unsigned char*height;for(unsigned int i=0;igetimage(image);orientation=getorientation();posx=getposx();posy=getposy();if(orientation=0)if(posxwidth-1)|(posy+1height-1)return 0;if(imageposyposx!=0)|(imageposyposx+1!=0)|(imageposy+1posx!=0)|(imageposy+1posx-1!=0)return 0;if(orientation=1)if(posxwidth-1)|(posyheight-1)return 0;if(imageposy-1posx-1!=0)|(imageposyposx-1!=0)|(imageposyposx!=0)|(imageposy+1posx!=0)return 0;if(orientation=2)if(posxwidth-1)|(posyheight-1)return 0;if(imageposyposx-1!=0)|(imageposyposx!=0)|(imageposy-1posx!=0)|(imageposy-1posx+1!=0)return 0;if(orientation=3)if(posx+1width-1)|(posyheight-1)return 0;if(imageposy-1posx!=0)|(imageposyposx!=0)|(imageposyposx+1!=0)|(imageposy+1posx+1!=0)return 0;return 1;void csbrick:putattop(unsigned int neworient, unsigned 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(1);break;void csbrick:operator (unsigned char *binimage)unsigned int orientation;unsigned int posx;unsigned int posy;unsigned char colour;posx=getposx();posy=getposy();orientation=getorientation();colour=getcolour();if(orientation=0)binimageposyposx=colour;binimageposyposx+1=colour;binimageposy+1posx=colour;binimageposy+1posx-1=colour;if(orientation=1)binimageposy-1posx-1=colour;binimageposyposx-1=colour;binimageposyposx=colour;binimageposy+1posx=colour;if(orientation=2)binimageposy-1posx+1=colour;binimageposy-1posx=colour;binimageposyposx=colour;binimageposyposx-1=colour;if(orientation=3)binimageposy-1posx=colour;binimageposyposx=colour;binimageposyposx+1=colour;binimageposy+1posx+1=colour;/t型砖块代码的实现部分:(黑色方块为程序中所选的坐标点)ctbrick类型砖块:(左移、右移、上键、下键消息响应函数与i型砖块代码的实现部分相同,这里就不列出来了)shiftleft(cbin*bin)shiftdown(cbin*bin)shiftright(cbin*bin)rotateclockwise(cbin*bin)int ctbrick:checkcollision(cbin *bin)unsigned int width;unsigned int height;unsigned char*image;unsigned int orientation;unsigned int posx;unsigned int posy;width=bin-getwidth();height=bin-getheight();image=new unsigned char*height;for(unsigned int i=0;igetimage(image);orientation=getorientation();posx=getposx();posy=getposy();if(orientation=0)if(posxwidth-1)|(posyheight-1)return 0;if(imageposy-1posx!=0)|(imageposyposx!=0)|(imageposyposx-1!=0)|(imageposyposx+1!=0)return 0;if(orientation=1)if(posx+1width-1)|(posyheight-1)return 0;if(imageposyposx!=0)|(imageposyposx+1!=0)|(imageposy-1posx!=0)|(imageposy+1posx!=0)return 0;if(orientation=2)if(posxwidth-1)|(posy+1height-1)return 0;if(imageposyposx-1!=0)|(imageposyposx!=0)|(imageposyposx+1!=0)|(imageposy+1posx!=0)return 0;if(orientation=3)if(posxwidth-1)|(posyheight-1)return 0;if(imageposyposx-1!=0)|(imageposyposx!=0)|(imageposyposx+1!=0)|(imageposy+1posx!=0)return 0;return 1;void ctbrick:operator (unsigned char *binimage)unsigned int orientation;unsigned int posx;unsigned int posy;unsigned char colour;posx=getposx();posy=getposy();orientation=getorientation();colour=getcolour();if(orientation=0)binimageposy-1posx=colour;binimageposyposx=colour;binimageposyposx-1=colour;binimageposyposx+1=colour;if(orientation=1)binimageposy-1posx=colour;binimageposyposx=colour;binimageposy+1posx=colour;binimageposyposx+1=colour;if(orientation=2)binimageposyposx-1=colour;binimageposyposx=colour;binimageposyposx+1=colour;binimageposy+1posx=colour;if(orientation=3)binimageposyposx-1=colour;binimageposyposx=colour;binimageposy-1posx=colour;binimageposy+1posx=colour;void ctbrick:putattop(unsigned int neworient, unsigned 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;/反l型砖块代码的实现部分:(黑色方块为程序中所选的坐标点) cflbrick类型砖块:(左移、右移、上键、下键消息响应函数与i型砖块代码的实现部分相同,这里就不列出来了)shiftleft(cbin*bin)shiftdown(cbin*bin)shiftright(cbin*bin)rotateclockwise(cbin*bin)int cflbrick:checkcollision(cbin *bin)unsigned int width;unsigned int height;unsigned char*image;unsigned int orientation;unsigned int posx;unsigned int posy;width=bin-getwidth();height=bin-getheight();image=new unsigned char*height;for(unsigned int i=0;igetimage(image);orientation=getorientation();posx=getposx();posy=getposy();if(orientation=0)if(posxwidth-1)|(posyheight-1)return 0;if(imageposy-2posx!=0)|(imageposy-1posx!=0)|(imageposyposx!=0)|(imageposyposx-1!=0)return 0;if(orientation=1)if(posx+1width-1)|(posyheight-1)return 0;if(imageposy-1posx!=0)|(imageposyposx!=0)|(imageposyposx+1!=0)|(imageposyposx+2!=0)return 0;if(orientation=2)if(posx+1width-1)|(posy+1height-1)return 0;if(imageposyposx!=0)|(imageposyposx+1!=0)|(imageposy+1posx!=0)|(imageposy+2posx!=0)return 0;if(orientation=3)if(posxwidth-1)|(posy+1height-1)return 0;if(imageposyposx-2!=0)|(imageposyposx-1!=0)|(imageposyposx!=0)|(imageposy+1posx!=0)return 0;return 1;void cflbrick:operator (unsigned char *binimage)unsigned int orientation;unsigned int posx;unsigned int posy;unsigned char colour;posx=getposx();posy=getposy();orientation=getorientation();colour=getcolour();if(orientation=0)binimageposy-2posx=colour;binimageposy-1posx=colour;binimageposyposx=colour;binimageposyposx-1=colour;if(orientation=1)binimageposy-1posx=colour;binimageposyposx=colour;binimageposyposx+1=colour;binimageposyposx+2=colour;if(orientation=2)binimageposyposx=colour;binimageposyposx+1=colour;binimageposy+1posx=colour;binimageposy+2posx=colour;if(orientation=3)binimageposyposx-2=colour;binimageposyposx-1=colour;binimageposyposx=colour;binimageposy+1posx=colour;void cflbrick:putattop(unsigned int neworient, unsigned int newposx) setposx(newposx);setorientation(neworient);switch(neworient)case 0: setposy(2);break;case 1: setposy(1);break;case 2: setposy(0);break;case 3: setposy(0);break;/反s型砖块代码的实现部分:(黑色方块为程序中所选的坐标点)cfsbrick类型砖块:(左移、右移、上键、下键消息响应函数与i型砖块代码的实现部分相同,这里就不列出来了)shiftleft(cbin*bin)shiftdown(cbin*bin)shiftright(cbin*bin)rotateclockwise(cbin*bin)int cfsbrick:checkcollision(cbin *bin)unsigned int width;unsigned int height;unsigned char*image;unsigned int orientation;unsigned int posx;unsigned int posy;width=bin-getwidth();height=bin-getheight();image=new unsigned char*height;for(unsigned int i=0;igetimage(image);orientation=getorientation();posx=getposx();posy=getposy();if(orientation=0)if(posxwidth-1)|(posyheight-1)return 0;if(imageposy-1posx!=0)|(imageposyposx!=0)|(imageposyposx-1!=0)|(imageposy+1posx-1!=0)return 0;if(orientation=1)if(posx+1width-1)|(posyheight-1)return 0;if(imageposy-1posx-1!=0)|(imageposy-1posx!=0)|(imageposyposx!=0)|(imageposyposx+1!=0)return 0;if(orientation=2)if(posx+1width-1)|(posyheight-1)return 0;if(imageposyposx!=0)|(imageposy+1posx!=0)|(imageposy-1posx+1!=0)|(imageposyposx+1!=0)return 0;if(orientation=3)if(posxwidth-1)|(posy+1height-1)return 0;if(imageposyposx-1!=0)|(imageposyposx!=0)|(imageposy+1posx!=0)|(imageposy+1posx+1!=0)return 0;return 1;void cfsbrick:operator (unsigned char *binimage)unsigned int orientation;unsigned int posx;unsigned int posy;unsigned char colour;posx=getposx();posy=getposy();orientation=getorientation();colour=getcolour();if(orientation=0)binimageposy-1posx=colour;binimageposyposx=colour;binimageposyposx-1=colour;binimageposy+1posx-1=colour;if(orientation=1)binimageposy-1posx-1=colour;binimageposy-1posx=colour;binimageposyposx=colour;binimageposyposx+1=colour;if(orientation=2)binimageposyposx=colour;binimageposy+1posx=colour;binimageposy-1posx+1=colour;binimageposyposx+1=colour;if(orientation=3)binimageposyposx-1=colour;binimageposyposx=colour;binimageposy+1posx=colour;binimageposy+1posx+1=colour;void cfsbrick:putattop(unsigned int neworient, unsigned int newposx)setposx(newposx);setorientation(neworient);switch(neworient)case 0: setposy(1);break;case 1: setposy(1);break;case 2: setposy(1);break;case 3: setposy(0);break;/田字形型砖块代码的实现部分:(黑色方块为程序中所选的坐标点)cobrick类型砖块:(左移、右移、上键、下键消息响应函数与i型砖块代码的实现部分相同,这里就不列出来了)shiftleft(cbin*bin)shiftdown(cbin*bin)shiftright(cbin*bin)rotateclockwise(cbin*bin)int cobrick:checkcollision(cbin *bin)unsigned int width;unsigned int height;unsigned char*image;unsigned int orientation;unsigned int posx;unsigned int posy;width=bin-getwidth();height=bin-getheight();image=new unsigned char*h
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年VB考试难点试题及答案剖析
- 企业波动与战略调整的风险管理试题及答案
- 软件生命周期管理最佳实践试题及答案
- 行政法学的学术贡献与试题答案探讨
- 软件设计师考试系统化知识体系试题及答案
- 2025年商业环境对企业战略决策的影响试题及答案
- 具体案例2025年法学概论考试试题及答案
- 2025年市场变化与企业战略修正的挑战试题及答案
- 高考数学研究分析方法试题及答案
- 行政管理知识点的深入梳理:试题及答案
- 黑龙江省自然科学基金项目申请书联合引导项目JJSBYB
- 英国食物介绍british-food(课堂)课件
- 神经系统疾病的康复课件
- DB32 4181-2021 行政执法案卷制作及评查规范
- 涉密文件借阅登记表
- 脊髓损伤康复讲义
- 布草洗涤服务方案完整版
- 气体安全知识培训(72张)课件
- 电子类产品结构设计标准-
- 音乐神童莫扎特详细介绍和作品欣赏课件
- 共线向量与共面向量全面版课件
评论
0/150
提交评论