C#俄罗斯方块游戏设计说明书_第1页
C#俄罗斯方块游戏设计说明书_第2页
C#俄罗斯方块游戏设计说明书_第3页
C#俄罗斯方块游戏设计说明书_第4页
C#俄罗斯方块游戏设计说明书_第5页
已阅读5页,还剩22页未读 继续免费阅读

下载本文档

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

文档简介

1、项目名称:c#俄罗斯方块游戏班 级 :2011级计算机3班姓 名 :蔡亲宝指导老师:完成时间 :2012年6月20日c#俄罗斯方块游戏设计说明书一、概述俄罗斯方块(tetris, 俄文:)是一款风靡全球的电视游戏机和掌上游戏机游戏,它由俄罗斯人阿列克谢帕基特诺夫发明,故得此名。俄罗斯方块的基本规则是移动、旋转和摆放游戏自动输出的各种方块,使之排列成完整的一行或多行并且消除得分。它曾经造成的轰动与造成的经济价值可以说是游戏史上的一件大事,它看似简单但却变化无穷,令人上瘾。相信大多数用户都还记得为它痴迷得茶不思饭不想的那个俄罗斯方块时代。俄罗斯方块上手极其简单,但是要熟练地掌握其中的操作与摆放技巧

2、,难度却不低。作为家喻户晓老少皆宜的大众游戏,其普及程度可以说是史上任何一款游戏都无法相比的。二、分析与设计2.1需求分析l 功能性需求u 随机产生经典俄罗斯方块图形u 设置关卡,不同级别关卡速度不同u 用户可以自定义游戏背景颜色和方块颜色u 方向键实现下落图形的左移、右移、加速下落、变形等基本操作u 正确判断游戏结束u 对游戏成绩进行记分l 非功能性需求用户界面需求需求名称详细要求窗体界面友好玩家可以很方便进行操作界面扩展性玩家可以对方块的背景颜色进行自定义支持声音每当玩家拼成一行时产生声音方块自定义玩家可以自定义方块颜色搭配软硬件环境需求需求名称详细要求硬件要求intel pentium

3、iii 800/amd k7以上处理器、128m以上内存系统平台windows2000/winxp/win2003/win7 运行环境windows 系列质量需求主要质量属性详细要求可靠性应用程序异常退出及崩溃的机率小于等于5%易用性不用安装,操作简便可扩展性可在当前需求基础之上进行功能上的扩展兼容性可运行在大多数主流的硬件环境中可移植性可运行在windows操作平台上2.2主要设计说明2.1.1界面设计form1.cs本界面设计简单而人性化,充分考虑到用户的操作习惯布局。详细代码:using system;using system.collections.generic;using syst

4、em.componentmodel;using system.data;using system.drawing;using system.text;using system.windows.forms;using system.io;namespace chinablock public partial class form1 : form private block currentblock; /当前在运行的方块 private block nextblock; /下一个即将出现的方块 private point startlocation = new point(gamefield.sq

5、uaresize * 8, 0);/方块产生的位置 private int score = 0; /玩家积分 private bool stillruning = false; /游戏运行开关 private enum speeds slower=1000, slow=800, quick=500, quicker=350, quickest=250 ; /游戏速度,数字越小越快 public form1() initializecomponent(); private void form1_load(object sender, eventargs e) gamefield.backcolo

6、r = picbackground.backcolor; gamefield.winhandle = picbackground.handle; timer1.interval = (int)speeds.slower; /获取自定义设置 getsettings(); /*加载窗体时从配置文件setting.ini中读取游戏设置*/ private void getsettings() if (!file.exists(setting.ini) return; filestream fs = new filestream(setting.ini, filemode.openorcreate,

7、fileaccess.readwrite); streamreader sr = new streamreader(fs); string line1=sr.readline(); string line2=sr.readline(); string line3=sr.readline(); if (line1 != null & line1.split(=).length 1) gamefield.backcolor = color.fromargb(int.parse(line1.split(=)1); picbackground.backcolor = gamefield.backcol

8、or; if (line2 != null & line2.split(=).length 1) gamefield.blockforecolor = strtocolor(line2.split(=)1); if (line3 != null & line3.split(=).length 1) gamefield.blockbackcolor = strtocolor(line3.split(=)1); sr.close(); fs.close(); /*如果游戏设置被更改,将新的设置保存到setting.ini*/ private void savesettings() filestre

9、am fs = new filestream(setting.ini, filemode.create, fileaccess.readwrite); streamwriter sw = new streamwriter(fs); sw.writeline(gamefieldcolor=+gamefield.backcolor.toargb(); sw.writeline(blockfroecolor= + colortostr(gamefield.blockforecolor); sw.writeline(blockbackcolor= + colortostr(gamefield.bloc

10、kbackcolor); sw.flush(); sw.close(); fs.close(); /*将字符串变回成颜色数组*/ private color strtocolor(string str) string strs = str.split(,); if (strs.length-1) != 7) return null; color colors=new color7; for (int i = 0; i strs.length - 1; i+) colorsi = color.fromargb(int.parse(strsi); return colors; /*将颜色变成可读字

11、符串*/ private string colortostr(color colors) string result = ; for (int i = 0; i 0) score += gamefield.width * eraselines; t_score.text = score.tostring(); picbackground.invalidate(); application.doevents(); gamefield.redraw(); /产生下一个block currentblock = new block(startlocation, nextblock.blocktype)

12、; currentblock.draw(gamefield.winhandle); pic_preview.refresh(); nextblock = new block(new point(80, 50), block.blocktypes.undefined); nextblock.draw(pic_preview.handle); currentblock.down(); /*窗口重绘*/ private void form1_activated(object sender, eventargs e) picbackground.invalidate(); application.do

13、events(); gamefield.redraw(); /*关闭窗体时,提示是否保存设置和确认是否退出*/ private void form1_formclosing(object sender, formclosingeventargs e) if (gamefield.ischanged&messagebox.show(设置已改变,是否在退出前保存?,提示,messageboxbuttons.yesno) = dialogresult.yes) savesettings();else if (messagebox.show(确定退出?,操作提示!,messageboxbuttons.

14、yesno,messageboxicon.information)=dialogresult.no) e.cancel=true ; else messagebox.show(感谢您体验本游戏!); #region 菜单 /*开始游戏*/ private void 开始toolstripmenuitem1_click(object sender, eventargs e) begingame(); /开始游戏的方法 private void begingame() msg.sendtoback(); /将提示窗口隐藏 开始toolstripmenuitem.enabled = false; 暂

15、停toolstripmenuitem1.enabled = true; 结束toolstripmenuitem.enabled = true; if (currentblock = null) /第一次开始 currentblock = new block(startlocation, block.blocktypes.undefined); currentblock.draw(gamefield.winhandle); nextblock = new block(new point(80, 50), block.blocktypes.undefined); nextblock.draw(pi

16、c_preview.handle); stillruning = true; timer1.start(); else timer1.enabled = true; /*暂停游戏*/ private void 暂停toolstripmenuitem1_click(object sender, eventargs e) timer1.enabled = false; showmsg(暂 停); 开始toolstripmenuitem.enabled = true; 暂停toolstripmenuitem1.enabled = false; /*结束游戏*/ private void 结束tool

17、stripmenuitem_click(object sender, eventargs e) stillruning = false; timer1.stop(); currentblock = null; showmsg(结 束); 结束toolstripmenuitem.enabled = false; 暂停toolstripmenuitem1.enabled = false; 开始toolstripmenuitem.enabled = true; picbackground.refresh(); pic_preview.refresh(); /*重新开始一盘*/ private voi

18、d 重新开始toolstripmenuitem_click(object sender, eventargs e) timer1.stop(); picbackground.refresh(); /刷新游戏区 pic_preview.refresh(); /刷新预览区 gamefield.arriveblock = new squaregamefield.width, gamefield.height; /清空所有小方块 gamefield.arrbitblock = new intgamefield.height; score = 0; /重新计算积分 t_score.text = 0; m

19、sg.sendtoback(); /将提示窗口隐藏 currentblock = new block(startlocation, block.blocktypes.undefined); currentblock.draw(gamefield.winhandle); nextblock = new block(new point(80, 50), block.blocktypes.undefined); nextblock.draw(pic_preview.handle); 开始toolstripmenuitem.enabled = false; 暂停toolstripmenuitem1.e

20、nabled = true; 结束toolstripmenuitem.enabled = true; stillruning = true; timer1.start(); /*退出游戏*/ private void 退出toolstripmenuitem_click(object sender, eventargs e) messagebox.show(感谢您体验本游戏!);/游戏退出提示 stillruning = false; timer1.stop(); this.close(); /*显示提示框*/ private void showmsg(string str) msg.text

21、= str; msg.left = picbackground.left + picbackground.width / 2 - msg.width / 2; msg.bringtofront(); /*操作说明*/ private void 操作说明toolstripmenuitem_click(object sender, eventargs e) help helps = new help(); helps.show(); /*关于*/ private void 关于toolstripmenuitem_click(object sender, eventargs e) about ab

22、= new about(); ab.show(); /*背景颜色设置*/ private void 背景颜色设置toolstripmenuitem_click(object sender, eventargs e) setgamefieldbgcolor sb = new setgamefieldbgcolor(); sb.showdialog(); picbackground.backcolor = gamefield.backcolor; /*方块颜色设置*/ private void 方块颜色设置toolstripmenuitem_click(object sender, eventar

23、gs e) setblockcolor sb = new setblockcolor(); sb.showdialog(); /*速度选择较慢*/ private void 较慢toolstripmenuitem_click(object sender, eventargs e) changechecked(较慢toolstripmenuitem); timer1.interval = (int)speeds.slower; /*速度选择慢*/ private void 慢toolstripmenuitem_click(object sender, eventargs e) changeche

24、cked(慢toolstripmenuitem); timer1.interval = (int)speeds.slow; /*速度选择快*/ private void 快toolstripmenuitem_click(object sender, eventargs e) changechecked(快toolstripmenuitem); timer1.interval = (int)speeds.quick; /*速度选择较快*/ private void 较快toolstripmenuitem_click(object sender, eventargs e) changechecke

25、d(较快toolstripmenuitem); timer1.interval = (int)speeds.quicker; /*速度选择非常快*/ private void 非常快toolstripmenuitem_click(object sender, eventargs e) changechecked(非常快toolstripmenuitem); timer1.interval = (int)speeds.quickest; /*速度选择需要用到的方法*/ public void changechecked(toolstripmenuitem oo) 较慢toolstripmenui

26、tem.checked = false; 慢toolstripmenuitem.checked = false; 快toolstripmenuitem.checked = false; 较快toolstripmenuitem.checked = false; 非常快toolstripmenuitem.checked = false; oo.checked = true; private void 恢复默认设置toolstripmenuitem_click(object sender, eventargs e)/游戏的默认设置 gamefield.backcolor = color.tan ;

27、picbackground.backcolor = color.tan; gamefield.blockforecolor = new color color.blue, color.beige, color.darkkhaki, color.darkmagenta, color.darkolivegreen, color.darkorange, color.darkred ; gamefield.blockbackcolor = new color color.lightcyan, color.darkseagreen, color.beige, color.beige, color.bei

28、ge, color.beige, color.beige ; savesettings(); gamefield.ischanged = false; #endregion private void exittoolstripmenuitem_click(object sender, eventargs e) messagebox.show(感谢您体验本游戏!);/游戏退出提示 application.exit(); private void 关于作者toolstripmenuitem_click(object sender, eventargs e)/调用作者信息版块 about ab =

29、new about(); ab.show(); private void 操作说明toolstripmenuitem1_click(object sender, eventargs e)/调用操作说明版块 help helps = new help(); helps.show(); private void timer2_tick(object sender, eventargs e) this.label3.text = system.datetime.now.tostring(); private void menustrip1_itemclicked(object sender, too

30、lstripitemclickedeventargs e) 2.2.2方块产生根据需要,随机产生不同的方块,使游戏具有了较强的可玩性。详细代码:block.csusing system;using system.collections.generic;using system.text;using system.drawing;namespace chinablock class block public square square1; /组成block的四个小方块 public square square2; public square square3; public square squa

31、re4; private const int squaresize = gamefield.squaresize; /小方块的边长 public enum blocktypes undefined = 0, square = 1, line = 2, j = 3, l = 4, t = 5, z = 6, s = 7 ;/一共有7种形状 public blocktypes blocktype; /方块的形状 /七个小方块的颜色数组 private color forecolor; private color backcolor; /方块的方向 public enum rotatedirecti

32、ons north = 1, east = 2, south = 3, west = 4 ; public rotatedirections myrotation = rotatedirections.north; public block(point thislocation,blocktypes btype) /当blocktype为undefined时,随机产生方块形状 random rand=new random(); if (btype = blocktypes.undefined) blocktype = (blocktypes)(rand.next(7) + 1); else b

33、locktype = btype; /设置四小方块的颜色 int i=(int)blocktype-1; forecolor = gamefield.blockforecolori; backcolor = gamefield.blockbackcolori; size squares=new size(squaresize,squaresize); square1 = new square(squares, forecolor, backcolor); square2 = new square(squares, forecolor, backcolor); square3 = new squ

34、are(squares, forecolor, backcolor); square4 = new square(squares, forecolor, backcolor); /设置小方块的位置,组合成指定形状的一个大方块 switch (blocktype) case blocktypes.square: /组合成正方形 square1.location = new point(thislocation.x, thislocation.y); square2.location = new point(thislocation.x + squaresize, thislocation.y);

35、 square3.location = new point(thislocation.x,thislocation.y+squaresize); square4.location = new point(thislocation.x+squaresize,thislocation.y+squaresize); break; case blocktypes.line: /组合成线形 square1.location = new point(thislocation.x, thislocation.y); square2.location = new point(thislocation.x +

36、squaresize, thislocation.y); square3.location = new point(thislocation.x + 2 * squaresize, thislocation.y); square4.location = new point(thislocation.x + 3 * squaresize, thislocation.y); break; case blocktypes.j: /组合成j形 square1.location = new point(thislocation.x + squaresize, thislocation.y); squar

37、e2.location = new point(thislocation.x + squaresize, thislocation.y + squaresize); square3.location = new point(thislocation.x + squaresize, thislocation.y + 2 * squaresize); square4.location = new point(thislocation.x, thislocation.y + 2 * squaresize); break; case blocktypes.l: /组合成l形 square1.location = new point(thislocation.x, thislocation.y); square2.location = new point(thislocation.x, thislocation.y + squaresize); square3.location = new point(thislocation.x, thislocation.y + 2 * squaresize); square4.location = new point(thislocation.x + squa

温馨提示

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

评论

0/150

提交评论