收藏 分销(赏)

C专业课程设计俄罗斯方块.doc

上传人:精*** 文档编号:2727369 上传时间:2024-06-05 格式:DOC 页数:30 大小:858.04KB
下载 相关 举报
C专业课程设计俄罗斯方块.doc_第1页
第1页 / 共30页
C专业课程设计俄罗斯方块.doc_第2页
第2页 / 共30页
C专业课程设计俄罗斯方块.doc_第3页
第3页 / 共30页
C专业课程设计俄罗斯方块.doc_第4页
第4页 / 共30页
C专业课程设计俄罗斯方块.doc_第5页
第5页 / 共30页
点击查看更多>>
资源描述

1、C#程序设计实训汇报题目:俄罗斯方块 专 业_计算机科学和技术 _年级班别_ 计算机09-2班_ 学 号 学生姓名_ _指导老师_ 成 绩 年 1 月 目 录一 系统设计要求31.1 课题分析错误!未定义书签。1.2 设计环境31.3 设计思绪3二 课题总体框架设计32.1程序步骤图42.2类结构图5三 课题实现63.1程序主界面63.2 开始游戏界面63.3 游戏结束界面73.4 暂停游戏界面73.5使用说明界面.83.6 关键程序代码8四 总结214.1设计总结214.2 设计体会22一、系统设计要求1.1 课题分析本游戏系统是利用C#实现, 是制作为我们所熟悉很简单俄罗斯方块游戏,该系统

2、能实现具体功效以下:1) 能简便开始游戏,游戏中方块功效和日常我们所熟悉游戏功效一致,多种块设置也一致,包含方块旋转,加速下降,左右移动,满行消去,满行消去自动加分,和到顶游戏结束等功效;2) 能够经过对话框窗体说明各个功效使用说明,和部分其它功效。3) 界面简练美观,简单易用。跟其它通常游戏相差不大。1.2 设计环境本程序选择Visual Studio 作为试验环境。1.3 设计思绪用面向对象方法分析系统对于俄罗斯方块程序制作,我们能够定义一个或多个类,专门来描述俄罗斯方块,在这个类中,包含和之相关方法、属性和字段,经过封装,实现其业务逻辑。其中,每一个俄罗斯方块全部有相同特征,由4个小正方

3、形组成,有旋转,左右移动,下落动作,整行被填满除去并计算分数而组成行小正方体块。基中块形状类型有7种:田、一、L、倒L、Z、倒Z、上。在窗口中经过调用主窗体Form1当中菜单栏来设置游戏开始、暂停、结束、重新开始和推出程序。还能够经过其菜单中游戏说明选项来查看游戏各个键使用说明,还可调用帮助菜单来查看版权说明。二、课题总体框架设计 2.1、 程序步骤图开始窗口初始化读取游戏开始游戏开启游戏时钟随机形成方块判定是否可移旋转左移右移加速下降暂停结束绘制方块是否越顶是否满行消行结束加分2.2、 类结构图三、课题实现3.1程序主界面3.2 开始游戏界面3.3游戏结束3.4暂停游戏3.5使用说明界面和版

4、权界面3.6关键程序代码1、Form1类1) 结构函数,设定目前运行方块,下一个立即出现方块,方块产生位置,玩家积分,游戏开关等。public partial class Form1 : Form private Block currentBlock; /目前在运行方块private Block nextBlock; /下一个立即出现方块private Point startLocation = new Point(bianjie.SingleSquareSize * 8, 0); /方块产生位置private int score = 0; /玩家积分private bool stillRun

5、ing = false; /游戏运行开关2) 键盘操作:用来选择方块移动方向,是向右移动,向左移动,向下加速,旋转,还是暂停。/*键盘操作*/private void Form1_KeyDown(object sender, KeyEventArgs e) switch (e.KeyCode) case Keys.Right: currentBlock.right() ; break;/向右移动 case Keys.Left: currentBlock.left() ; break; /向左移动 case Keys.Up: currentBlock.Rotate(); break; /旋转 c

6、ase Keys.Down: while (currentBlock.down() ; break; /向下加速 case Keys.Space: /空格:暂停 timer1.Enabled = !timer1.Enabled; if (!timer1.Enabled) showMsg(暂 停); else msg.SendToBack(); break; picBack.Focus(); 3) 时钟触发处理函数,使方块自动向下移动,每1秒使方块向下移动一次 /*游戏时钟*/ private void timer1_Tick(object sender, EventArgs e) if (!s

7、tillRuning) return; /检测是否还能够下移 if (!currentBlock.down() if (currentBlock.Top() = 0) /假如到顶则游戏结束 showMsg(Game Over!); stillRuning = false; timer1.Stop(); return; /不然计算分数并继续 int eraseLines = bianjie.CheckLines(); if (eraseLines 0) score += bianjie.width * eraseLines; t_score.Text = score.ToString(); pi

8、cBack.Invalidate(); Application.DoEvents(); bianjie.Redraw(); /产生下一个block currentBlock = new Block(startLocation, nextBlock.blockType); currentBlock.Draw(bianjie.winHandle); pic_preView.Refresh();nextBlock = new Block(new Point(50, 50), Block.BlockTypes.undefined); nextBlock.Draw(pic_preView.Handle)

9、; currentBlock.down(); 4) 对窗口进行重绘 /*窗口重绘*/ private void Form1_Activated(object sender, EventArgs e) picBack.Invalidate(); Application.DoEvents(); bianjie.Redraw(); 2、SingleBlock类1) 结构单个方块尺寸,颜色,前景色,背景色public SingleBlock(Size initSize,Color initForeColor,Color initBackColor) size = initSize; foreColor

10、 = initForeColor; backColor = initBackColor; 2) 画方块,用GDI+绘画,画出填充正方形 /画方块 public void Draw(System.IntPtr winHandle) Graphics g = Graphics.FromHwnd(winHandle); GraphicsPath gp = new GraphicsPath(); Rectangle rect = new Rectangle(location, size); gp.AddRectangle(rect); Color surroundColor = new Color b

11、ackColor ; PathGradientBrush pgb = new PathGradientBrush(gp); pgb.CenterColor = foreColor; pgb.SurroundColors = surroundColor; g.FillPath(pgb, gp); /擦除方块 public void Erase(System.IntPtr winHandle) Graphics g = Graphics.FromHwnd(winHandle); Rectangle rect = new Rectangle(location,size); g.FillRectang

12、le(new SolidBrush(bianjie.BackColor),rect); 3、Block类1)随机产生方块形状,并设置四个方块颜色public Block(Point thisLocation,BlockTypes bType) /当blockType为undefined时,随机产生方块形状 Random rand=new Random(); if (bType = BlockTypes.undefined) blockType = (BlockTypes)(rand.Next(7) + 1); else blockType = bType; /设置四小方块颜色 int i=(i

13、nt)blockType-1; foreColor = bianjie.BlockForeColori; backColor = bianjie.BlockBackColori; Size SingleSquareS=new Size(SingleSquareSize,SingleSquareSize); SingleSquare1 = new SingleBlock(SingleSquareS, foreColor, backColor); SingleSquare2 = new SingleBlock(SingleSquareS, foreColor, backColor); Single

14、Square3 = new SingleBlock(SingleSquareS, foreColor, backColor); SingleSquare4 = new SingleBlock(SingleSquareS, foreColor, backColor);2)设置小方块位置,组合成指定形状方块 /设置小方块位置,组合成指定形状一个大方块 switch (blockType) case BlockTypes.SingleSquare: /组合成正方形 SingleSquare1.location = new Point(thisLocation.X, thisLocation.Y);

15、SingleSquare2.location = new Point(thisLocation.X + SingleSquareSize, thisLocation.Y); SingleSquare3.location = new Point(thisLocation.X,thisLocation.Y+SingleSquareSize);SingleSquare4.location = new Point(thisLocation.X+SingleSquareSize,thisLocation.Y+SingleSquareSize); break;case BlockTypes.line: /

16、组合成线形 SingleSquare1.location = new Point(thisLocation.X, thisLocation.Y); SingleSquare2.location = new Point(thisLocation.X + SingleSquareSize, thisLocation.Y); SingleSquare3.location = new Point(thisLocation.X + 2 * SingleSquareSize, thisLocation.Y); SingleSquare4.location = new Point(thisLocation.

17、X + 3 * SingleSquareSize, thisLocation.Y); break; case BlockTypes.J: /组合成J形 SingleSquare1.location = new Point(thisLocation.X + SingleSquareSize, thisLocation.Y); SingleSquare2.location = new Point(thisLocation.X + SingleSquareSize, thisLocation.Y + SingleSquareSize); SingleSquare3.location = new Po

18、int(thisLocation.X + SingleSquareSize, thisLocation.Y + 2 * SingleSquareSize); SingleSquare4.location = new Point(thisLocation.X, thisLocation.Y + 2 * SingleSquareSize); break; case BlockTypes.L: /组合成l形 SingleSquare1.location = new Point(thisLocation.X, thisLocation.Y); SingleSquare2.location = new

19、Point(thisLocation.X, thisLocation.Y + SingleSquareSize); SingleSquare3.location = new Point(thisLocation.X, thisLocation.Y + 2 * SingleSquareSize); SingleSquare4.location = new Point(thisLocation.X + SingleSquareSize, thisLocation.Y + 2 * SingleSquareSize); break; case BlockTypes.T: /组合成T形 SingleSq

20、uare1.location = new Point(thisLocation.X, thisLocation.Y); SingleSquare2.location = new Point(thisLocation.X + SingleSquareSize, thisLocation.Y); SingleSquare3.location = new Point(thisLocation.X + 2*SingleSquareSize, thisLocation.Y); SingleSquare4.location = new Point(thisLocation.X + SingleSquare

21、Size, thisLocation.Y +SingleSquareSize); break; case BlockTypes.Z: /组合成z形 SingleSquare1.location = new Point(thisLocation.X, thisLocation.Y); SingleSquare2.location = new Point(thisLocation.X + SingleSquareSize, thisLocation.Y); SingleSquare3.location = new Point(thisLocation.X + SingleSquareSize, t

22、hisLocation.Y + SingleSquareSize); SingleSquare4.location = new Point(thisLocation.X + 2*SingleSquareSize, thisLocation.Y + SingleSquareSize); break;case BlockTypes.S: /组合成S形 SingleSquare1.location = new Point(thisLocation.X, thisLocation.Y + SingleSquareSize); SingleSquare2.location = new Point(thi

23、sLocation.X + SingleSquareSize, thisLocation.Y + SingleSquareSize); SingleSquare3.location = new Point(thisLocation.X + SingleSquareSize, thisLocation.Y); SingleSquare4.location = new Point(thisLocation.X + 2 * SingleSquareSize, thisLocation.Y); break; /*画方块*/ public void Draw(System.IntPtr winHandl

24、e) SingleSquare1.Draw(winHandle); SingleSquare2.Draw(winHandle); SingleSquare3.Draw(winHandle); SingleSquare4.Draw(winHandle); /*擦方块*/ public void Erase(System.IntPtr winHandle) SingleSquare1.Erase(winHandle); SingleSquare2.Erase(winHandle); SingleSquare3.Erase(winHandle); SingleSquare4.Erase(winHan

25、dle); 3) 移动方块 /*移动*/ public bool down() /检测是否能够下移 if (bianjie.isEmpty(SingleSquare1.location.X / SingleSquareSize, SingleSquare1.location.Y / SingleSquareSize + 1) & bianjie.isEmpty(SingleSquare2.location.X / SingleSquareSize, SingleSquare2.location.Y / SingleSquareSize + 1) &bianjie.isEmpty(SingleS

26、quare3.location.X / SingleSquareSize, SingleSquare3.location.Y / SingleSquareSize + 1) &bianjie.isEmpty(SingleSquare4.location.X / SingleSquareSize, SingleSquare4.location.Y / SingleSquareSize + 1) Erase(bianjie.winHandle); SingleSquare1.location = new Point(SingleSquare1.location.X, SingleSquare1.l

27、ocation.Y + SingleSquareSize); SingleSquare2.location = new Point(SingleSquare2.location.X, SingleSquare2.location.Y + SingleSquareSize);SingleSquare3.location = new Point(SingleSquare3.location.X, SingleSquare3.location.Y + SingleSquareSize); SingleSquare4.location = new Point(SingleSquare4.locatio

28、n.X, SingleSquare4.location.Y + SingleSquareSize); Draw(bianjie.winHandle); return true; else /假如不能下移了 bianjie.stopSingleSquare(SingleSquare1, SingleSquare1.location.X / SingleSquareSize, SingleSquare1.location.Y / SingleSquareSize);bianjie.stopSingleSquare(SingleSquare2, SingleSquare2.location.X /

29、SingleSquareSize, SingleSquare2.location.Y / SingleSquareSize); bianjie.stopSingleSquare(SingleSquare3, SingleSquare3.location.X / SingleSquareSize, SingleSquare3.location.Y / SingleSquareSize); bianjie.stopSingleSquare(SingleSquare4, SingleSquare4.location.X / SingleSquareSize, SingleSquare4.locati

30、on.Y / SingleSquareSize); return false; /表示能够弹出下一个block了 public bool left() /检测是否能够左移 if (bianjie.isEmpty(SingleSquare1.location.X / SingleSquareSize-1, SingleSquare1.location.Y / SingleSquareSize) &bianjie.isEmpty(SingleSquare2.location.X / SingleSquareSize-1, SingleSquare2.location.Y / SingleSquar

31、eSize) &bianjie.isEmpty(SingleSquare3.location.X / SingleSquareSize-1, SingleSquare3.location.Y / SingleSquareSize) & bianjie.isEmpty(SingleSquare4.location.X / SingleSquareSize-1, SingleSquare4.location.Y / SingleSquareSize) Erase(bianjie.winHandle); SingleSquare1.location = new Point(SingleSquare1

32、.location.X - SingleSquareSize, SingleSquare1.location.Y); SingleSquare2.location = new Point(SingleSquare2.location.X - SingleSquareSize, SingleSquare2.location.Y); SingleSquare3.location = new Point(SingleSquare3.location.X - SingleSquareSize, SingleSquare3.location.Y); SingleSquare4.location = ne

33、w Point(SingleSquare4.location.X - SingleSquareSize, SingleSquare4.location.Y); Draw(bianjie.winHandle); return true; else /假如不能左移了 return false; public bool right() /检测是否能够右移 if (bianjie.isEmpty(SingleSquare1.location.X / SingleSquareSize +1, SingleSquare1.location.Y / SingleSquareSize) &bianjie.is

34、Empty(SingleSquare2.location.X / SingleSquareSize +1, SingleSquare2.location.Y / SingleSquareSize) &bianjie.isEmpty(SingleSquare3.location.X / SingleSquareSize +1, SingleSquare3.location.Y / SingleSquareSize) &bianjie.isEmpty(SingleSquare4.location.X / SingleSquareSize +1, SingleSquare4.location.Y /

35、 SingleSquareSize) Erase(bianjie.winHandle); SingleSquare1.location = new Point(SingleSquare1.location.X + SingleSquareSize, SingleSquare1.location.Y ); SingleSquare2.location = new Point(SingleSquare2.location.X + SingleSquareSize, SingleSquare2.location.Y); SingleSquare3.location = new Point(Singl

36、eSquare3.location.X + SingleSquareSize, SingleSquare3.location.Y); SingleSquare4.location = new Point(SingleSquare4.location.X + SingleSquareSize, SingleSquare4.location.Y); Draw(bianjie.winHandle); return true; else /假如不能右移了 return false; 4) 旋转方块/*旋转block*/public void Rotate() /保留每个小块位置 Point oldPo

37、sition1 = SingleSquare1.location; Point oldPosition2 = SingleSquare2.location; Point oldPosition3 = SingleSquare3.location; Point oldPosition4 = SingleSquare4.location; /保留目前方向 RotateDirections oldRotation = myRotation; /开始试着旋转方块,旋转方向:顺时针方向 旋转中心点为形状拐点 Erase(bianjie.winHandle); switch(blockType) case

38、 BlockTypes.SingleSquare: break; case BlockTypes.line: /直线旋转只有两种方向 switch (myRotation) case RotateDirections.North: myRotation = RotateDirections.East; SingleSquare1.location = new Point(SingleSquare2.location.X-SingleSquareSize,SingleSquare2.location.Y); SingleSquare3.location = new Point(SingleSqu

39、are2.location.X+SingleSquareSize,SingleSquare2.location.Y); SingleSquare4.location = new Point(SingleSquare2.location.X + 2 * SingleSquareSize, SingleSquare2.location.Y); break; case RotateDirections.East: myRotation = RotateDirections.North; SingleSquare1.location = new Point(SingleSquare2.location.X,SingleSquare2.location.Y-SingleSquareSize); SingleSquare3.location = new Point(SingleSquare2.location.X, SingleSquare2.location.Y +SingleSquareSize); SingleSquare4.location = new Poin

展开阅读全文
部分上传会员的收益排行 01、路***(¥15400+),02、曲****(¥15300+),
03、wei****016(¥13200+),04、大***流(¥12600+),
05、Fis****915(¥4200+),06、h****i(¥4100+),
07、Q**(¥3400+),08、自******点(¥2400+),
09、h*****x(¥1400+),10、c****e(¥1100+),
11、be*****ha(¥800+),12、13********8(¥800+)。
相似文档                                   自信AI助手自信AI助手
搜索标签

当前位置:首页 > 学术论文 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服