俄罗斯方块游戏代码分析doc.doc

  1. 1、本文档共41页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
俄罗斯方块游戏代码分析doc

俄罗斯方块游戏代码分析 这个游戏虽然简单,但是还是有点复杂的,对于初学C#的我来说困难很大,这些代码都是我照着书上敲出来的,我自己肯定写不出来,特别是有些函数到现在还没看懂。下面就来简单分析下这个游戏设计。 把俄罗斯方块游戏中的对象抽象成3类:Square(方块)、Block(组合快)、GameField(游戏区)。 对以上3个对象对应的类进行说明 1.Square对象(对应Square.cs类) Square对象包含4个字段:squareLocation表示方块在游戏区中的位置;squareSize表示方块的大小;还有方块绘制时的前景色foregroundColor和背景色backgroundColor。 Square对象包含3个方法:Hide()是隐藏方块;Show()是现实方块;Square()是构造函数; 主要代码: public void Hide(System.IntPtr winHandle) { Graphics graphics = Graphics.FromHwnd(winHandle); Rectangle rectangle = new Rectangle(SquareLocation.X,SquareLocation.Y,SquareSize.Width,SquareSize.Height); graphics.FillRectangle(new SolidBrush(GameField.DefaultBackColor),rectangle); } public void Show(System.IntPtr winHandle) { Graphics GameGraphics; GraphicsPath graphPath; PathGradientBrush brushSquare; Color [] surroundColor; Rectangle rectSquare; GameGraphics = Graphics.FromHwnd(winHandle); graphPath=new GraphicsPath(); rectSquare=new Rectangle(SquareLocation.X,SquareLocation.Y,SquareSize.Width,SquareSize.Height); graphPath.AddRectangle(rectSquare); brushSquare=new PathGradientBrush(graphPath); brushSquare.CenterColor=foregroundColor; brushSquare.SurroundColors=new Color[]{backgroundColor}; GameGraphics.FillPath(brushSquare,graphPath); } Square squareLocation squareSize forgroundColor backgroundColor Hide Show Square Square.cs Block对象(对应Block.cs) 组合块是由4个方块对象构成的。其种类有7个。 Block对象包含9个字段:Square[0]~Square[3],组合块类型blockType,,组合块的当前旋转方向机RoTation,等。 Block对象包含8个方法:Hide()是隐藏组合块,Show()是显示组合块,Down()是组合块向下移动,类似还有Left(),Right(),Up()是对组合块进行旋转,Top()是返回组合块四个方块中最小的y坐标值。 Block backColors formColors blockTpye Random Square[3] Rotation Block Hide Show Down Left Right Up Top block.cs 部分主要代码如下: public Block(Point Location, int newblockType,Size size) { if (newblockType == 7

文档评论(0)

jiaoyuguanliji + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档