ImageVerifierCode 换一换
格式:DOCX , 页数:17 ,大小:18.09KB ,
资源ID:4909394      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/4909394.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(俄罗斯方块代码.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

俄罗斯方块代码.docx

1、俄罗斯方块代码俄罗斯方块代码清单:#define MAXCOM 7 /部件数#define WIDE 13 /游戏区域宽#define HIGH 26 /高#define SIZE 12 /组成游戏区域的方格大小#define TOP 50 /游戏左上角坐标#define LEFT 50#define EASY 500 /游戏难度#define NORMAL 300#define HARD 200typedef struct tagComponet int intComID; /部件的ID号 int intDimension; /存储该部件所需的数组维数 int* pintArray; /指向

2、存储该部件的数组Componet;class CRusBlockView : public CView private: int m_intComID; / 当前下落的部件 int m_intStateHIGHWIDE; /当前状态 Componet m_ComponetsMAXCOM; /所有部件的内部表示 int m_intScore; /分数 int m_intLevel; Componet m_CurrentCom; /当前的部件 POINT ptIndex; /部件数组在全局数组中的索引 / 产生一个新的部件 void NewComponet(void); / 是否还可以下落 boo

3、l CanDown(void); / 刷新函数 void MyInvalidateRect(POINT ptStart, int intDimension); / 消去行 void Disappear(void); / 判断游戏是否结束 bool CheckFail(void); / 是否还可以旋转 bool CanRotate(void); / 是否还可以左移 bool CanLeft(void); / 是否还可以右移 bool CanRight(void); /检查是否有足够的空位显示新的部件,否则游戏结束 bool CanNew();CRusBlockView:CRusBlockView

4、() / TODO: add construction code here for (int i=0;iHIGH;i+) for(int j=0;jWIDE;j+) m_intStateij=0; m_intLevel=NORMAL; /初始化难度 srand(unsigned) time(NULL); /初始化随机数 m_intScore=0; m_CurrentCom.intComID=-1; m_CurrentCom.intDimension=0; m_CurrentCom.pintArray=NULL; /初始化7个部件 /0:方块 m_Componets0.intComID=0; m

5、_Componets0.intDimension=2; m_Componets0.pintArray=new int4; for (i=0;i4;i+) m_Componets0.pintArrayi=1; / 1 1 / 1 1 /1:-| m_Componets1.intComID=1; m_Componets1.intDimension=3; m_Componets1.pintArray=new int9; m_Componets1.pintArray0=0; m_Componets1.pintArray1=1; m_Componets1.pintArray2=0; / 0 1 0 m_

6、Componets1.pintArray3=1; / 1 1 1 m_Componets1.pintArray4=1; / 0 0 0 m_Componets1.pintArray5=1; m_Componets1.pintArray6=0; m_Componets1.pintArray7=0; m_Componets1.pintArray8=0; /2 m_Componets2.intComID=2; m_Componets2.intDimension=3; m_Componets2.pintArray=new int9; m_Componets2.pintArray0=1; m_Compo

7、nets2.pintArray1=0; m_Componets2.pintArray2=0; / 1 0 0 m_Componets2.pintArray3=1; / 1 1 0 m_Componets2.pintArray4=1; / 0 1 0 m_Componets2.pintArray5=0; m_Componets2.pintArray6=0; m_Componets2.pintArray7=1; m_Componets2.pintArray8=0; /3 m_Componets3.intComID=3; m_Componets3.intDimension=3; m_Componet

8、s3.pintArray=new int9; m_Componets3.pintArray0=0; m_Componets3.pintArray1=0; m_Componets3.pintArray2=1; / 0 0 1 m_Componets3.pintArray3=0; / 0 1 1 m_Componets3.pintArray4=1; / 0 1 0 m_Componets3.pintArray5=1; m_Componets3.pintArray6=0; m_Componets3.pintArray7=1; m_Componets3.pintArray8=0; /4 m_Compo

9、nets4.intComID=4; m_Componets4.intDimension=3; m_Componets4.pintArray=new int9; m_Componets4.pintArray0=1; m_Componets4.pintArray1=0; m_Componets4.pintArray2=0; / 1 0 0 m_Componets4.pintArray3=1; / 1 1 1 m_Componets4.pintArray4=1; / 0 0 0 m_Componets4.pintArray5=1; m_Componets4.pintArray6=0; m_Compo

10、nets4.pintArray7=0; m_Componets4.pintArray8=0; /5 m_Componets5.intComID=5; m_Componets5.intDimension=3; m_Componets5.pintArray=new int9; m_Componets5.pintArray0=0; m_Componets5.pintArray1=0; m_Componets5.pintArray2=1; / 0 0 1 m_Componets5.pintArray3=1; / 1 1 1 m_Componets5.pintArray4=1; / 0 0 0 m_Co

11、mponets5.pintArray5=1; m_Componets5.pintArray6=0; m_Componets5.pintArray7=0; m_Componets5.pintArray8=0; /6 m_Componets6.intComID=6; m_Componets6.intDimension=4; m_Componets6.pintArray=new int16; m_Componets6.pintArray0=0; m_Componets6.pintArray1=1; m_Componets6.pintArray2=0; / 0 1 0 0 m_Componets6.p

12、intArray3=0; / 0 1 0 0 m_Componets6.pintArray4=0; / 0 1 0 0 m_Componets6.pintArray5=1; / 0 1 0 0 m_Componets6.pintArray6=0; m_Componets6.pintArray7=0; m_Componets6.pintArray8=0; m_Componets6.pintArray9=1; m_Componets6.pintArray10=0; m_Componets6.pintArray11=0; m_Componets6.pintArray12=0; m_Componets

13、6.pintArray13=1; m_Componets6.pintArray14=0; m_Componets6.pintArray15=0;CRusBlockView:CRusBlockView() /释放内存 for(int i=0;iSelectObject(&brushBK); pDC-Rectangle(LEFT-1,TOP-1,LEFT+WIDE*SIZE+1, TOP+HIGH*SIZE+1); /画不能移动的方块 CBrush brushStick(RGB(127,127,127); pDC-SelectObject(&brushStick); for (int i=0;iH

14、IGH;i+) for(int j=0;jRectangle(LEFT+SIZE*j,TOP+SIZE*i,LEFT+SIZE*(j+1), TOP+SIZE*(i+1); /画下落的部件 if(m_CurrentCom.intComID=0) CBrush brushCom(RGB(0,255,0); pDC-SelectObject(&brushCom); int intDimension=m_CurrentCom.intDimension; for(int i=0;iRectangle(LEFT+SIZE*n,TOP+SIZE*m,LEFT+SIZE*(n+1), TOP+SIZE*(m

15、+1); /显示得分 CString strOut; strOut.Format(得分 %d,m_intScore); pDC-TextOut(LEFT+WIDE*SIZE+50,TOP+100,strOut); pDC-SelectObject(&pbrushOld);void CRusBlockView:OnTimer(UINT nIDEvent) / TODO: Add your message handler code here and/or call default int intDimension=m_CurrentCom.intDimension; if(CanDown() /可

16、以下落 /擦除 MyInvalidateRect(ptIndex,intDimension); /下落 ptIndex.x+; /显示新位置上的部件 MyInvalidateRect(ptIndex,intDimension); else for(int i=0;iintDimension*intDimension;i+) if(m_CurrentCom.pintArrayi=1) int m=ptIndex.x+i/intDimension; /找出部件对应整体数组中的位置 int n=ptIndex.y+(i%intDimension); m_intStatemn=1; MyInvalid

17、ateRect(ptIndex,intDimension); Disappear(); /消去行 if(CheckFail() /游戏结束 m_CurrentCom.intComID=-1; KillTimer(1); MessageBox(Game Over!); else NewComponet(); /新部件 CView:OnTimer(nIDEvent);void CRusBlockView:OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) / TODO: Add your message handler code here and/or

18、 call default int intDimension=m_CurrentCom.intDimension; switch(nChar) /left 37, right 39, up 38 case 37: if(CanLeft() /擦除 MyInvalidateRect(ptIndex,intDimension); /左移 ptIndex.y-; /显示新位置上的部件 MyInvalidateRect(ptIndex,intDimension); break; case 39: if(CanRight() /擦除 MyInvalidateRect(ptIndex,intDimensi

19、on); /右移 ptIndex.y+; /显示新位置上的部件 MyInvalidateRect(ptIndex,intDimension); break; case 38: if(CanRotate() /擦除 MyInvalidateRect(ptIndex,intDimension); /转动 int* pintNewCom=new intintDimension*intDimension; for(int i=0;iintDimension*intDimension;i+) int intR=intDimension*(intDimension-(i%intDimension)-1)+

20、(i/intDimension); pintNewComi=m_CurrentCom.pintArrayintR; for(i=0;iintDimension*intDimension;i+) m_CurrentCom.pintArrayi=pintNewComi; delete pintNewCom; /显示新位置上的部件 MyInvalidateRect(ptIndex,intDimension); break; CView:OnKeyDown(nChar, nRepCnt, nFlags);void CRusBlockView:NewComponet(void) int intComID

21、=rand()%7; /产生随机数 m_CurrentCom.intComID=intComID; int intDimension=m_ComponetsintComID.intDimension; m_CurrentCom.intDimension=intDimension; delete m_CurrentCom.pintArray; /删除上一个部件的内存分配 m_CurrentCom.pintArray=new intintDimension*intDimension; /拷贝部件 for(int i=0;iintDimension*intDimension;i+) m_Curren

22、tCom.pintArrayi=m_ComponetsintComID.pintArrayi; ptIndex.x=0;/行 ptIndex.y=5;/列 /检查是否有足够的空位显示新的部件,否则游戏结束 if(CanNew() /显示该部件 MyInvalidateRect(ptIndex,intDimension); else m_CurrentCom.intComID=-1; KillTimer(1); MessageBox(Game Over!); bool CRusBlockView:CanDown(void) bool boolDown=true; POINT intNewInde

23、x=ptIndex; /假设可以下落 intNewIndex.x+; int intDimension=m_CurrentCom.intDimension; for(int i=0;i=HIGH | m_intStatemn=1) /被挡住或出游戏区域 boolDown=false; return boolDown;/ 可以左移bool CRusBlockView:CanLeft(void) bool boolLeft=true; int intDimension=m_CurrentCom.intDimension; POINT ptNewIndex=ptIndex; /假设可以左移 ptNe

24、wIndex.y-; for(int i=0;iintDimension*intDimension;i+) if(m_CurrentCom.pintArrayi=1) int m=ptNewIndex.x+i/intDimension; /找出部件对应整体数组中的位置 int n=ptNewIndex.y+(i%intDimension); if(n0 | m_intStatemn=1) /被挡住或出游戏区域 boolLeft=false; return boolLeft;/ 可以右移bool CRusBlockView:CanRight(void) bool boolRight=true;

25、int intDimension=m_CurrentCom.intDimension; POINT ptNewIndex=ptIndex; /假设可以右移 ptNewIndex.y+; for(int i=0;i=WIDE | m_intStatemn=1) /被挡住或出游戏区域 boolRight=false; return boolRight;/ 可以旋转bool CRusBlockView:CanRotate(void) bool boolRotate=true; int intDimension=m_CurrentCom.intDimension; POINT ptNewIndex=ptIndex; /假设可以转动 /新的矩阵存储转动后的部件 int* pintNewCom=new intintDimension*intDimension

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1