俄罗斯方块课程设计.doc_第1页
俄罗斯方块课程设计.doc_第2页
俄罗斯方块课程设计.doc_第3页
俄罗斯方块课程设计.doc_第4页
俄罗斯方块课程设计.doc_第5页
已阅读5页,还剩42页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

院 系: 班 级: 姓 名: 学 号: 合 作 者: 指导教师: 2008年12月24日面向对象程序设计课程设计任务书一、题目:俄罗斯方块游戏二、设计要求12小组成员分工协作完成设计任务。每人应完成自己相对独立的模块并读懂其他组员的模块。不得抄袭。3设计一个具有一定复杂度、业务性、操作性且界面美观的系统。4要求利用面向对象编程思想以及.NET开发平台,并采用C#作为编程语言来完成系统的设计。5.一组最多4个学生协同完成。6按要求写出课程设计报告,并于设计结束后1周内提交。其主要内容包括:封皮、课程设计任务书,指导教师评语与成绩、目录、概述、软件总体设计、详细设计、软件的调试、总结、谢启、附录:带中文注释的程序清单、参考文献。报告一律用A4纸打印,中文字体为宋体,西文字体用Time New Roma,一律用小四号字,行距采用“固定值”18磅,首行缩进2字符。总体设计应配合软件总体模块结构图来说明软件应具有的功能。详细设计应介绍主要编程思路、所使用的主要函数(方法)和屏幕抓图说明,调试的叙述应配合出错场景的抓图来说明出现了哪些错误,如何解决的。三、课程设计工作量由于是设计小组团结协作完成设计任务,一般每人的程序量应在240行有效程序行以上。不得抄袭,否则给不及格成绩。四、课程设计工作计划2008年12月6日指导教师讲课,学生准备文献资料。 2008年12月9日 设计小组进行总体方案设计和任务分工。 2008年12月10日2008年12月17日每人完成自己承担的模块,将各个程序模块集成为一个完整的系统。 2008年12月18日2008年12月19日课程设计验收。2008年12月20日2008年12月24日学生撰写课程设计报告。 指导教师签字: 教研室主任签章: 面向对象程序设计课程设计指导教师评语与成绩指导教师评语:课程设计表现成绩: 课程设计验收成绩: 课程设计报告成绩: 课程设计 总成绩: 指导教师签字: 2008年 月 日目 录一、概述4二、软件总体设计5三详细设计6四 软件的调试16五 总结16六、谢启17七 附录17参考文献46一、概述1 程序设计的题目:俄罗斯方块游戏2 程序设计目的:使学生更深入地理解和掌握面向对象课程中的基本概念,程序设计思想和方法。培养学生综合运用所学知识独立完成课题的能力。培养学生勇于探索、严谨推理、实事求是、有错必改,用实践来检验理论,全方位考虑问题等科学技术人员应具有的素质。提高学生对工作认真负责、一丝不苟,对同学团结友爱,协作攻关的基本素质。培养学生从资料文献、科学实验中获得知识的能力,提高学生从别人经验中找到解决问题的新途径的悟性,培养学生的创新能力。对学生掌握知识的深度、运用理论去解决问题的能力、实验能力、书面及口头表达能力进行考察。3 程序设计要求:要求掌握C#面向对象程序设计的基本理论知识和熟练运用C#基本知识,熟悉C#程序的编辑、编译、调试和运行过程,了解面向对象程序设计的类与对象、继承和模板各部分的理论知识并能熟练的运用。同时查找并参照其它书籍对程序设计进行创新。4 程序设计的思想:我们设计了一个俄罗斯方块游戏,它实现了启动游戏,暂停游戏,移动和旋转方块,高分记录和退出游戏等功能,从而完成了游戏的实现,玩家可以自己控制游戏的开始,选择难度,查看高分记录,选择旋转时针,是否添加音乐等,具有一定的实用性。 二、软件总体设计1 需求分析(1)具有良好的人机交互界面,玩家可以很方便地对游戏进行各种操作。(2)支持对声音的处理。(3)支持分数排行榜的功能,玩家可以随时打开排行榜来查看前若干名的成绩。2 软件的功能简介本软件主要可以实现以下的功能:启动游戏,选择难度,移动方块,旋转方块,暂停游戏,高分记录,退出游戏。3 项目规划俄罗斯方块游戏软件由登陆注册,启动游戏,选择难度,控制方块,暂停游戏,高分记录,退出游戏几个模块组成。(1)登陆注册模块该模块的主要任务是维护软件的正常运行和安全性设置,包括登录、注册用户等。(2)启动游戏,暂停游戏和退出游戏模块:该模块的主要功能是实现启动,暂停,退出游戏功能(3)选择难度模块该模块主要功能是实现选择难度功能,使用户选择合适的难度。(4)控制方块模块该模块主要功能是实现游戏的基本操作。(5)高分记录模块该模块主要功能是实现高分的记录,以方便查找和记录。4软件开发的目标完成游戏的所有功能,增加游戏的乐趣。总体流程图如下:俄罗斯方块游戏控制游戏功能启动游戏暂停游戏退出游戏旋转方块移动方块高分记录三详细设计此系统由我和我的同学共同完成的,在此只介绍由我做的模块。1 选择难度模块界面为:代码为:private void butOk_Click(object sender, System.EventArgs e)/ Sets the level attribute to the chosen level.level = (short)(txtLevelStart.Value);/ Closes the dialog.this.Close();/ summary/ The click of the Cancel button. Closes the dialog./ /summary/ param name=senderThe parent control who triggered the event./param/ param name=eDefault event arguments./paramprivate void butCancel_Click(object sender, System.EventArgs e)/ Closes the dialog.this.Close();/ summary/ Readonly property that holds the chosen level./ /summarypublic short Levelget/ Returns the value in the level attribute.return level; private void StartAt_Load(object sender, EventArgs e) private void txtLevelStart_ValueChanged(object sender, EventArgs e) private void lblTextStartAtLevel_Click(object sender, EventArgs e) 以下模块的界面为:代码为:2 移动方块模块public bool MoveCurrentBlockDown()bool hit = false;currentBlock.Top+;if (currentBlock.Top + currentBlock.Height) PlayingFieldHeight)hit = true;elsefor(int i = 0; i currentBlock.Width; i+)for(int j = 0; j currentBlock.Height; j+)int fx, fy;fx = currentBlock.Left + i;fy = currentBlock.Top + j;if (currentBlock.Shapei, j.Filled = true) (pilefx, (fy + 1).Filled = true)/ Current block has hit the pile./ Sets the hit flag to true.hit = true;if (hit)MoveBlockToPile();if (this.GameState != GameState.Over)CreateNewBlock();return hit;public void MoveCurrentBlockCompletelyDown()while(!MoveCurrentBlockDown();public void RotateCurrentBlock(bool clockwise)bool canRotate = true;currentBlock.Rotate(clockwise);for(int i = 0; i currentBlock.Width; i+)for(int j = 0; j currentBlock.Height; j+)int fx, fy;fx = currentBlock.Left + i;fy = (currentBlock.Top + 1) + j;if (currentBlock.Shapei, j.Filled = true) (pilefx, fy.Filled = true)/ Current block cant be rotated./ Sets the canRotate flag to false.canRotate = false;if (!canRotate)currentBlock.Rotate(!clockwise);public void MoveCurrentBlockSide(bool left)bool canMove = true;if (left)if (currentBlock.Left 0)for(int i = 0; i currentBlock.Width; i+)for(int j = 0; j currentBlock.Height; j+)int fx, fy;fx = currentBlock.Left + i;fy = (currentBlock.Top + 1) + j;if (currentBlock.Shapei, j.Filled = true) (pile(fx - 1), fy.Filled = true)canMove = false;if (canMove)currentBlock.Left-;elseif (currentBlock.Left + currentBlock.Width) PlayingFieldWidth)for(int i = 0; i currentBlock.Width; i+)for(int j = 0; j currentBlock.Height; j+)int fx, fy;fx = currentBlock.Left + i;fy = (currentBlock.Top + 1) + j;if (currentBlock.Shapei, j.Filled = true) (pile(fx + 1), fy.Filled = true)canMove = false;if (canMove)currentBlock.Left+;3 旋转方块模块private void mnuRotateClockwise_Click(object sender, System.EventArgs e)/ Checks the Rotate clockwise menu.mnuRotateClockwise.Checked = true;/ Unchecks the Rotate counterclockwise menu.mnuRotateCounterclockwise.Checked = false;/ Saves the options to the registry.SaveConfigs();/ summary/ The click of the Rotate counterclockwise menu. Sets the option to rotate the block counterclockwise./ /summary/ param name=senderThe parent control who triggered the event./param/ param name=eDefault event arguments./paramprivate void mnuRotateCounterclockwise_Click(object sender, System.EventArgs e)/ Unchecks the Rotate clockwise menu.mnuRotateClockwise.Checked = false;/ Checks the Rotate counterclockwise menu.mnuRotateCounterclockwise.Checked = true;/ Saves the options to the registry.SaveConfigs();4 按键设置模块private void AnotherBlockMain_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)/ Checks if there is a current game.if (game != null)/ There is a current game./ Checks if the game is running.if (game.GameState = GameState.Running)/ Game is running./ Checks for the key code pressed.switch(e.KeyCode)case Keys.Up:/ Up arrow pressed./ Rotate the current block, clockwise or counterclockwise, according to options.game.RotateCurrentBlock(mnuRotateClockwise.Checked);break;case Keys.Down:/ Down arrow pressed./ Checks if the block can be moved down.if (!dontMoveDown)/ Block can be moved down./ Move the current block down and checks if there was a hit.if (game.MoveCurrentBlockDown()/ There was a hit./ Checks if the sounds menu is checked.if (mnuSounds.Checked)/ Sounds menu is checked./ Plays the hit sound.soundHit.Play();/ Makes the dontMoveDown attribute true, so that the user cant force the next block to move down.dontMoveDown = true;/ Makes the timer interval the default interval, like level 1.tmrTimer.Interval = basicInterval;break;case Keys.Right:/ Right arrow pressed./ Move the current block to the right.game.MoveCurrentBlockSide(false);break;case Keys.Left:/ Left arrow pressed./ Move the current block to the left.game.MoveCurrentBlockSide(true);break;case Keys.Space:/ Space bar pressed./ Checks if the sounds menu is checked.if (mnuSounds.Checked)/ Sounds menu is checked./ Plays the hit sound.soundHit.Play();/ Move the current block all the way down.game.MoveCurrentBlockCompletelyDown();break;/ Forces the paint event to occurr in both picture boxes (the playing field and the next block).picPlayingField.Invalidate();picNextBlock.Invalidate();5 消层模块private int CheckForLines()int numLines = 0;int completeLines = new intPlayingFieldHeight;for (int j = PlayingFieldHeight; j 0; j-)bool fullLine = true;for (int i = 0; i PlayingFieldWidth; i+)if (pilei, j.Filled = false)fullLine = false;break;if (fullLine)numLines+;this.GameState = GameState.Paused;completeLinesnumLines = j;this.GameState = GameState.Running;if (numLines 0)for(int i = 1; i = numLines; i+)ClearLine(completeLinesi + (i - 1);score += 5 * (numLines * (numLines + 1);lines += numLines;level = (short)(lines / LevelEveryLines) + startLevel);return numLines;private void ClearLine(int lineNumber)for (int j = lineNumber; j 0; j-)for (int i = 0; i PlayingFieldWidth; i+)/ Move the current brick down.pilei, j = pilei, (j - 1);for (int i = 0; i PlayingFieldWidth; i+)pilei, 0.Filled = false;四 软件的调试在系统的开发过程中,遇到了许许多多的问题,但在老师和同学的帮助下,都解决掉了,例如:开始时程序无法实现难度的选择,后来经过反复调试才使问题得以解决。五 总结经过一周的课程设计,我们组设计的作品俄罗斯方块游戏终于完成,在一次次的调试后,程序比较完美。 我们做的俄罗斯方块游戏可以完成完成一下功能:(1)具有良好的人机交互界面,玩家可以很方便地对游戏进行各种操作。(2)支持对声音的处理。(3)支持分数排行榜的功能,玩家也可以随时打开排行榜来查看前若干名的成绩。基本可以满足游戏的需要,并且利用数据库的相关知识,登陆以及注册本程序的最大优点是可以记录高分玩家的名次以及成绩。程序的不足是软件截面设计的不是太美观。总体来说,我们组的作品比较成功,存在的问题会在以后的学习中加以解决和应用,希望各位老师和广大同学提出宝贵意见,相信我们会做的更好。六、谢启感谢学校给了我们这次机会来丰富我们的知识,提高我们的技能,更加感谢我们的李卓老师在百忙之中来辅导我们,在辅导过程中,她耐心的引导我们从何入手,如何解决问题,以及解决问题的办法。指出我们的不足,告诉我们应如何提高自身水平,总之,我们对她表示深深的谢意。同时也感谢在此过程中给我提供帮助的同学。还有管理机房的老师,谢谢他为我们提供便利条件,使我能够顺利地完成这次任务。七 附录程序清单 :using System;using System.Drawing;namespace AnotherBlockpublic class Blockpublic Block()/ Creates a random number generator.Random randomGenerator = new Random();/ Randomizes the block type.BlockType randomBlockType = (BlockType)(randomGenerator.Next(1, 8);/ Sets the block type.this.BlockType = randomBlockType;/ summary/ Class constructor that creates a block with a given block type./ /summary/ param name=blockTypeBlock type of the new block being created./parampublic Block(BlockType blockType)/ Sets the block type.this.BlockType = blockType;/ summary/ Property that holds and sets the top position of the block in the play field (in block units)./ /summary/ remarks/ Value must be between 0 and the playing field height./ /remarkspublic short Topget/ Returns the value in the top attribute.return top;set/ Checks if the value is within the allowed range.if (value -1) (value (Game.PlayingFieldHeight + 1)/ The value is within the allowed range./ Sets the top attribute to the value.top = value;else/ The value is not within the allowed range./ Throws an argument exception with the error.throw new ArgumentException(Property Top must be between 0 and + Game.PlayingFieldHeight.ToString() + .);/ summary/ Property that holds and sets the left position of the block in the play field (in block units)./ /summary/ remarks/ Value must be between 0 and the playing field width, taking into consideration the block width./ /remarkspublic short Leftget/ Returns the value in the left attribute.return left;set/ Checks if the value is within the allowed range.if (value -1) (value + this.Width) = Game.PlayingFieldWidth)/ The value is within the allowed range./ Sets the left attribute to the value.left = value;else/ The value is not within the allowed range./ Throws an argument exception with the error.throw new ArgumentException(Property Left must be between 0 and + (int)(Game.PlayingFieldWidth - this.Width).ToString() + .);/ summary/ Property that holds and sets the current width of the block (in block units)./ /summary/ remarks/ Value must be between 1 and 4./ /remarkspublic short Widthget/ Returns the value in the width attribute.return width;set/ Checks if the value is within the allowed range.if (value 0) (value 5)/ The value is within the allowed range./ Sets the width attribute to the value.width = value;else/ The value is not within the allowed range./ Throws an argument exception with the error.throw new ArgumentException(Property Width must be between 1 and 4.);/ summary/ Property that holds and sets the current height of the block (in block units)./ /summary/ remarks/ Value must be between 1 and 4./ /remarkspublic short Heightget/ Returns the value in the height attribute.return height;set/ Checks if the value is within the allowed range.if (value 0) (value 5)/ The value is within the allowed range./ Sets the width attribute to the value.height = value;else/ The value is not within the allowed range./ Throws an argument exception with the error.throw new ArgumentException(Property Height must be between 1 and 4.);/ summary/ Property that holds and sets the shape of the block./ /summarypublic Brick, Shapeget/ Returns the value in the shape attribute.return shape;set/ Checks if the length of the value to be set is right, according the the width and height of the block.if (value.Length = width * height)/ The value is right./ Sets the shape attribute to the value.shape = value;else/ The value is not right./ Throws an argument exception with the error.throw new ArgumentException(Specified index length does not match block dimensions.);/ summary/ Property that holds and sets the block type./ /summary/ remarks/ The block type can be set only one time./ /remarkspublic BlockType BlockTypeget/ Returns the value in the blockType attribute.return blockType;set/ Creates a new shape.Brick, shape;/ Tests if the current block type is Undefined.if (blockType = BlockType.Undefined)/ Current block type is Undefined./ Sets the blockType = value;/ Checks for the new block type.switch(blockType)case BlockType.Straight:/ Block type is Straight./ Sets the Width, Height, Top and Left properties.this.Width = 4;this.Height = 1;this.Top = 0;this.Left = 3;/ Creates the new shape for this block.shape = new Brickthis.Width, this.Height;shape0, 0.Filled = true;shape1, 0.Filled = true;shape2, 0.Filled = true;shape3, 0.Filled = true;/ Creates the images for this block.shape0, 0.BrickImage = blockImage13;shape1, 0.BrickImage = blockImage14;shape2, 0.BrickImage = blockImage13;shape3, 0.BrickImage = blockImage14;/ Sets the Shape property to the new shape created.this.Shape = shape;break;case BlockType.Rectangle:/ Block type is Rectangle./ Sets the Width, Height, Top and Left properties.this.Width = 2;this.Height = 2;this.Top = 0;this.Left = 4;/ Creates the new shape for this block.shape = new Brickthis.Width, this.Height;shape0, 0.Filled = true;shape0, 1.Filled = true;shape1, 0.Filled = true

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论