java课程设计报告俄罗斯方块_第1页
java课程设计报告俄罗斯方块_第2页
java课程设计报告俄罗斯方块_第3页
java课程设计报告俄罗斯方块_第4页
java课程设计报告俄罗斯方块_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

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

文档简介

1、 java程序设计课程设计 之 俄罗斯方块学院:计算机年级:09级 班级:网络工程1班 时间:2011年12月15日目录摘要1第一章 课程设计要求2第二章 设计概要32.1 功能设计32.2 程序系统功能模块32.3 功能分析42.3.1 功能流程图42.3.2 系统操作界面52.3.3 程序主要功能说明51.界面按钮设计和功能的实现5第三章 调试分析与测试结果133.1 游戏运行界面133.2 测试项目133.2.1 功能区按键测试133.2.2 键盘功能测试143.2.3 计分与过关测试143.2.4 游戏结束测试14第四章 设计总结154.1 改进意见154.2 java课程设计心得体会

2、15第五章 参考文献16摘要在现代,高科技的飞跃发展,人们工作习惯的改变,特别是电脑的大量普及,人们生活节奏越来越快,一些有趣的桌面游戏已经成为人们在使用计算机进行工作或学习之余休闲娱乐的首选,而俄罗斯方块游戏是人们最熟悉的小游戏之一。俄罗斯方块(tetris, 俄文:)是一款风靡全球的电视游戏机和掌上游戏机游戏,它由俄罗斯人阿列克谢帕基特诺夫发明,故得此名。俄罗斯方块的基本规则是移动、旋转和摆放游戏自动输出的各种方块,使之排列成完整的一行或多行并且消除得分。由于上手简单、老少皆宜,从而家喻户晓,风靡世界。 为此,我们设计了一款简单的俄罗斯方块java游戏程序,以便更好的满足广大电脑工作者闲暇

3、之余的消遣,并且也让我们学到编程技术与团队意识。关键字:俄罗斯方块、java游戏、编程第1章 课程设计要求题目名称:俄罗斯方块题目类型:设计型课程设计目的: 1)了解java的基本使用方法。 2)熟悉eclipse的运行环境。 3)用java面向对象的方法来设计一个俄罗斯方块的小游戏。 4)基本实现俄罗斯方块的应用功能。实验原理:java程序分析与设计、类的灵活运用、多态技术、模板技术、异常处理等。实验内容:本俄罗斯方块游戏是对于随机给出不同的形状(长条形、z字形、反z形、田字形、7字形、反7形、t字型)下落填充给定的区域,若填满一条便消掉,记分,当达到一定的分数时,过关,每关方块下落的速度不

4、同,若在游戏中各形状填满了给定区域,为输者。 第二章 设计概要2.1 功能设计本项目是为了实现俄罗斯方块的基本功能而设计的,基本能够达到俄罗斯方块的各种游戏性。项目需求分析如下:1)由方块组成的不同的随机图形会从区域上方开始缓慢落下。2)玩家可以做的操作有: 以90度为单位旋转方每一格块。以格子为单位左右移动方块,让方块加速落下。3)方块移到区域最下方或是着地到其他方块上无法移动时,就会固定在该处,而新的随机图形会出现在区域上方开始落下。4)当区域中某一列横向格子全部由方块填满,则该列会自动消除并成为玩家的得分。5)当固定的方块堆到区域最上方,则游戏结束。2.2 程序系统功能模块俄罗斯方块游戏

5、游戏区游戏控制显示玩家操作显示操作结果开始暂停/继续停止退出保存高分2.3 功能分析2.3.1 功能流程图:处理玩家操作是否到顶部开始 定义画布 创建游戏区游戏开局随机选择方块类型是否到顶部方块下落一行游戏结束是否2.3.2 系统操作界面2.3.3 程序主要功能说明1.界面按钮设计和功能的实现代码:class controlpanel extends jpanel/* * */private static final long serialversionuid = 1l;protected static final string do_nothing_on_close = null;prote

6、cted static final frame frame = null;protected static final int information_message = 0;private jtextfield tflevel = new jtextfield( + ersblocksgame.initlevel),/初始级别 tfscore = new jtextfield(0);/初始得分private jbuttonbtlist=new jbutton(保存高分),btabout=new jbutton(关于), btplay = new jbutton(开始), btpause =

7、new jbutton(暂停), btstop = new jbutton(停止), btexit=new jbutton(退出);private jpanel showbefore = new jpanel(new borderlayout();/设置显示下一个图案的容器private showbeforepanel plshowbeforeblock = new showbeforepanel();private jpanel plinfo = new jpanel(new gridlayout(4, 1);private jpanel plbutton = new jpanel(new

8、gridlayout(5, 1);private timer timer;private ersblocksgame game;public controlpanel(final ersblocksgame game) setlayout(new gridlayout(3, 1, 0, 4);/设置网格的行列以及水平垂直间距this.game = game;showbefore.add(new jlabel(即将到来), borderlayout.north);/添加“即将到来”标签showbefore.add(plshowbeforeblock);/添加下一个图案plinfo.add(new

9、 jlabel(level);plinfo.add(tflevel);plinfo.add(new jlabel(score);plinfo.add(tfscore); tflevel.seteditable(false);tfscore.seteditable(false);plbutton.add(btplay);plbutton.add(btpause);plbutton.add(btstop);plbutton.add(btexit);plbutton.add(btabout);plbutton.add(btlist);add(showbefore);add(plinfo);add(p

10、lbutton);addkeylistener(new controlkeylistener();btplay.addactionlistener(new actionlistener() public void actionperformed(actionevent ae) game.playgame(););btpause.addactionlistener(new actionlistener() public void actionperformed(actionevent ae) if (btpause.gettext().equals(new string(暂停) game.pau

11、segame();else game.resumegame(););btstop.addactionlistener(new actionlistener() public void actionperformed(actionevent ae) game.stopgame(););btexit.addactionlistener(new actionlistener()public void actionperformed(actionevent ae)setdefaultcloseoperation(do_nothing_on_close); int option=joptionpane.

12、showconfirmdialog(btexit, 确定退出游戏? , 退出 ,joptionpane.yes_no_cancel_option); if(option=joptionpane.yes_option) system.exit(0); else return; private void setdefaultcloseoperation(string donothingonclose) / todo auto-generated method stub);btabout.addactionlistener(new actionlistener()public void action

13、performed(actionevent ae) string message= 俄罗斯方块v1.0; string title=关于; joptionpane.showmessagedialog(frame, message,title,information_message););btlist.addactionlistener(new actionlistener()public void actionperformed(actionevent ae)jfilechooser jfc1=new jfilechooser();jfc1.setdialogtitle(保存到);jfc1.s

14、howsavedialog(null);jfc1.setvisible(true);string url1=jfc1.getselectedfile().getabsolutepath();bufferedwriter bw;try bw = new bufferedwriter(new filewriter(url1+.txt);bw.write(高分+tfscore.gettext();bw.close(); catch (ioexception e1) / todo auto-generated catch blocke1.printstacktrace(););2. 背景框图形功能代码

15、:class gamecanvas extends jpanel /画布类/* * */private static final long serialversionuid = 1l;private color backcolor = color.white, frontcolor = color.blue;private int rows, cols, score = 0, scoreforlevelupdate = 0;private ersbox boxes;private int boxwidth, boxheight;public gamecanvas(int rows, int c

16、ols)this.rows = rows;this.cols = cols;boxes = new ersboxrowscols;for (int i = 0; i boxes.length; i+) for (int j = 0; j boxesi.length; j+)boxesij = new ersbox(false); public gamecanvas(int rows, int cols, color backcolor, color frontcolor) this(rows, cols);this.backcolor = backcolor;this.frontcolor =

17、 frontcolor;public void setbackgroundcolor(color backcolor)this.backcolor = backcolor;public color getbackgroundcolor()return backcolor;public void setblockcolor(color frontcolor)this.frontcolor = frontcolor;public color getblockcolor()return frontcolor;public int getrows()return rows;public int get

18、cols()return cols;public int getscore() return score;public int getscoreforlevelupdate()return scoreforlevelupdate;public void resetscoreforlevelupdate()scoreforlevelupdate -= ersblocksgame.everylevelscore;public ersbox getbox(int row, int col)if (row boxes.length - 1| col boxes0.length - 1)return n

19、ull;return (boxesrowcol); public void fanning()boxwidth = getsize().width / cols;boxheight = getsize().height / rows;public void paintcomponent(graphics g)super.paintcomponent(g); g.setcolor(frontcolor);for (int i = 0; i boxes.length; i+)for (int j = 0; j 0; i-) for (int j = 0; j cols; j+)boxesij =

20、(ersbox) boxesi - 1j.clone();score += ersblocksgame.alinescore;scoreforlevelupdate += ersblocksgame.alinescore;repaint();public void reset() score = 0;scoreforlevelupdate = 0;for (int i = 0; i boxes.length; i+) for (int j = 0; j boxesi.length; j+)boxesij.setcolor(false);repaint();3. 方块自动下落功能 代码:publ

21、ic void run()/方块自动下落while (moving)try sleep(betweenleveltime * (ersblocksgame.maxlevel - level);/级别越高速度越快(多线程) catch (interruptedexception ie)ie.printstacktrace();if (!pausing)moving = (moveto(y + 1, x) & moving);4. 游戏运行功能代码:private class game implements runnable /游戏流程!public void run() int col = (i

22、nt) (math.random() * (canvas.getcols() - 3), style = ersblock.styles(int) (math.random() * 7)(int)(math.random() * 4);while (playing)if (block != null) if (block.isalive() try thread.currentthread();thread.sleep(100); catch (interruptedexception ie) ie.printstacktrace();continue;checkfullline(); if

23、(isgameover() ctrlpanel.setplaybuttonenable(true);ctrlpanel.setpausebuttonlabel(true);reportgameover();return;block = new ersblock(style, -1, col, getlevel(), canvas);block.start();col = (int) (math.random() * (canvas.getcols() - 3);style = ersblock.styles(int) (math.random() * 7)(int)(math.random()

24、 * 4);ctrlpanel.setshowbeforestyle(style);第3章 调试分析与测试结果3.1 游戏运行界面3.2 测试项目3.2.1 功能区按键测试测试结果:开始:游戏开始,方块下落;暂停:游戏暂停;继续:游戏继续;停止:游戏停止,再按开始则重新开局;退出:游戏退出;关于:打印游戏信息;保存高分:显示保存路径选择。3.2.2 键盘功能测试测试结果:方向键“”:旋转方块;方向键“”:使方块加速下落;方向键“”:使方块左移;方向键“”:使方块右移。3.2.3 计分与过关测试测试结果:经过测试员不断的亲身游戏,本程序的计分与过关项目基本无问题,由于能力有限,只能测试到第五关。3.2.4 游戏结束测试第4章 设计总结4.1 改进意见本程序中还存在一些不足之处,例如:1进一步地功能扩展,如添加音效等;2美化玩家进入游戏的

温馨提示

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

评论

0/150

提交评论