俄罗斯方块毕业课程设计报告.docx

上传人:b****5 文档编号:7833940 上传时间:2023-01-26 格式:DOCX 页数:28 大小:22.02KB
下载 相关 举报
俄罗斯方块毕业课程设计报告.docx_第1页
第1页 / 共28页
俄罗斯方块毕业课程设计报告.docx_第2页
第2页 / 共28页
俄罗斯方块毕业课程设计报告.docx_第3页
第3页 / 共28页
俄罗斯方块毕业课程设计报告.docx_第4页
第4页 / 共28页
俄罗斯方块毕业课程设计报告.docx_第5页
第5页 / 共28页
点击查看更多>>
下载资源
资源描述

俄罗斯方块毕业课程设计报告.docx

《俄罗斯方块毕业课程设计报告.docx》由会员分享,可在线阅读,更多相关《俄罗斯方块毕业课程设计报告.docx(28页珍藏版)》请在冰豆网上搜索。

俄罗斯方块毕业课程设计报告.docx

俄罗斯方块毕业课程设计报告

(此文档为word格式,下载后您可任意编辑修改!

一、系统概述

1.1现状分析

在个人电脑日益普及的今天,一些有趣的桌面游戏已经成为人们在使用计算机进行工作或学习之余休闲娱乐的首选,而俄罗斯方块游戏是人们最熟悉的小游戏之一,它以其趣味性强,易上手等诸多特点得到了大众的认可,因此开发此游戏软件可满足人们的一些娱乐的需求。

此俄罗斯方块游戏可以为用户提供一个可在普通个人电脑上运行的,界面美观的,易于控制的俄罗斯方块游戏。

1.2项目要求

俄罗斯方块游戏是一款适合大众的游戏软件,它适合不同年龄的人玩。

本软件要实现的功能如下:

(1)游戏区:

玩家可以在游戏区中堆积方块,并能够在游戏过程中随时了解得分情况。

(2)游戏控制:

玩家可以通过游戏控制功能来选择开始新的一局游戏,暂停或退出游戏。

(3)级别设置:

玩家可以根据自己的需要自行设定游戏的开始级别,级别越高,游戏的速度越快,难度越大。

(4)系统功能模块示意图如下:

 

二、设计说明

2.1游戏区模块

2.2控制区模块

2.3系统流程图

2.4系统操作界面

游戏打开界面

游戏进行中界面

三、源程序编码

importjavax.swing.*;

importjava.awt.*;

importjavax.swing.border.Border;

importjava.awt.event.*;

publicclassErsBlocksGameextendsJFrame{

publicfinalstaticintalinescore=100;

publicfinalstaticinteverylevelscore=alinescore*20;

publicfinalstaticintmaxlevel=10;

publicfinalstaticintinitlevel=5;

privateGameCanvascanvas;

privateErsBlockblock;

privatebooleanplaying=false;

privateControlPanelctrlPanel;

privateJMenuBarbar=newJMenuBar();

privateJMenu

mGame=newJMenu("游戏"),

mControl=newJMenu("控制"),

mhelp=newJMenu("帮助");

privateJMenuItem

miNewGame=newJMenuItem("新游戏"),

milevelup=newJMenuItem("提高级数"),

mileveldown=newJMenuItem("降低级数"),

miExit=newJMenuItem("退出"),

miPlay=newJMenuItem("开始"),

miPause=newJMenuItem("暂停"),

miResume=newJMenuItem("重新开始"),

miStop=newJMenuItem("停止"),

miCtrlBlock=newJMenuItem("方块控制键");

publicErsBlocksGame(Stringtitle)

{

super(title);

setSize(315,392);

DimensionscrSize=Toolkit.getDefaultToolkit().getScreenSize();

setLocation((scrSize.width-getSize().width)2,

(scrSize.);

mGame.addSeparator();

mGame.add(miExit);

mControl.add(miPlay);

mControl.addSeparator();

mControl.add(miPause);

mControl.addSeparator();

mControl.add(miResume);

mControl.addSeparator();

mControl.add(miStop);

mhelp.add(miCtrlBlock);

setJMenuBar(bar);

miNewGame.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventae)

{

stopGame();

reset();

setLevel(initlevel);

}

});

mileveldown.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventae)

{

intcurLevel=getLevel();

if(curLevel>1)

setLevel(curLevel-1);

}

});

milevelup.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventae)

{

intcurLevel=getLevel();

if(curLevel>1)

setLevel(curLevel+1);

}

});

miExit.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventae)

{

System.exit(0);

}

});

miPlay.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventae)

{

playGame();

}

});

miPause.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventae)

{

pauseGame();

}

});

miResume.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventae)

{

resumeGame();

}

});

miStop.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventae)

{

stopGame();

}

});

miCtrlBlock.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventae)

{

reportGameMethod();

}

});

}

publicvoidreset()

{

ctrlPanel.reset();

canvas.reset();

}

publicbooleanisPlaying()

{

returnplaying;

}

publicErsBlockgetCurBlock()

{

returnblock;

}

publicGameCanvasgetCanvas()

{

returncanvas;

}

publicvoidplayGame()

{

play();

ctrlPanel.setPlayButtonEnable(false);

miPlay.setEnabled(false);

ctrlPanel.requestFocus();

}

publicvoidpauseGame()

{

if(block!

=null)

block.pauseMove();

ctrlPanel.setPauseButtonLabel(false);

miPause.setEnabled(false);

miResume.setEnabled(true);

}

publicvoidresumeGame()

{

if(block!

=null)

block.resumeMove();

ctrlPanel.setPauseButtonLabel(true);

miPause.setEnabled(true);

miResume.setEnabled(false);

ctrlPanel.requestFocus();

}

publicvoidstopGame()

{

playing=false;

if(block!

=null)

block.stopMove();

miPlay.setEnabled(true);

miPause.setEnabled(true);

miResume.setEnabled(false);

ctrlPanel.setPlayButtonEnable(true);

ctrlPanel.setPauseButtonLabel(true);

}

publicintgetLevel()

{

returnctrlPanel.getLevel();

}

publicvoidsetLevel(intlevel)

{

if(level<11&&level>0)ctrlPanel.setLevel(level);

}

publicintgetScore()

{

if(canvas!

=null)

returncanvas.getScore();

return0;

}

publicintgetScoreForLevelUpdate()

{

if(canvas!

=null)

returncanvas.getScoreForLevelUpdate();

return0;

}

publicbooleanlevelUpdate()

{

intcurLevel=getLevel();

if(curLevel

{

setLevel(curLevel+1);

canvas.resetScoreForLevelUpdate();

returntrue;

}

returnfalse;

}

privatevoidplay(){

reset();

playing=true;

Threadthread=newThread(newGame());

thread.start();

}

privatevoidreportGameMethod(){

JOptionPane.showMessageDialog(this,"J为向左移动,L为向右移动,K为加速向下,I为翻转变化");

}

privatevoidreportGameOver(){

JOptionPane.showMessageDialog(this,"游戏结束!

");

}

privateclassGameimplementsRunnable

{

publicvoidrun()

{

intcol=(int)(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().sleep(100);

}catch(InterruptedExceptionie)

{

ie.printStackTrace();

}

continue;

}

}

checkFullLine();

if(isGameOver())

{

miPlay.setEnabled(true);

miPause.setEnabled(true);

miResume.setEnabled(false);

ctrlPanel.setPlayButtonEnable(true);

ctrlPanel.setPauseButtonLabel(true);

reportGameOver();

return;

}

block=newErsBlock(style,-1,col,getLevel(),canvas);

block.start();

col=(int)(Math.random()*(canvas.getCols()-3));

style=ErsBlock.STYLES[(int)(Math.random()*7)][(int)

(Math.random()*4)];

ctrlPanel.setShowBeforeStyle(style);

}

}

publicvoidcheckFullLine()

{introw;

for(inti=0;i

{

introw=1;

booleanfullLineColorBox=true;

for(intj=0;j

{

if(!

canvas.getBox(i,j).isColorBox())

{

fullLineColorBox=false;

break;

}

}

if(fullLineColorBox)

{

row=i;

canvas.removeLine(row);

}

}

}

privatebooleanisGameOver()

{

for(inti=0;i

{

ErsBoxbox=canvas.getBox(0,i);

if(box.isColorBox())

returntrue;

}

returnfalse;

}

}

publicstaticvoidmain(String[]args)

{

newErsBlocksGame("俄罗斯方块游戏");

}

}

classControlPanelextendsJPanel

{

privateJTextField

tfLevel=newJTextField(""+ErsBlocksGame.initlevel),

tfScore=newJTextField("0");

privateJButton

btPlay=newJButton("开始"),

btPause=newJButton("暂停"),

btStop=newJButton("停止"),

btTurnLevelUp=newJButton("提高等级"),

btTurnLevelDown=newJButton("降低等级");

privateJPanelshowbefore=newJPanel(newBorderLayout());

privateShowBeforePanelplShowBeforeBlock=newShowBeforePanel();

privateJPanelplInfo=newJPanel(newGridLayout(4,1));

privateJPanelplButton=newJPanel(newGridLayout(5,1));

privateTimertimer;

privateErsBlocksGamegame;

publicControlPanel(finalErsBlocksGamegame){

setLayout(newGridLayout(3,1,0,4));

this.game=game;

showbefore.add(newJLabel("下一个方块"),BorderLayout.NORTH);

showbefore.add(plShowBeforeBlock);

plInfo.add(newJLabel("等级"));

plInfo.add(tfLevel);

plInfo.add(newJLabel("得分"));

plInfo.add(tfScore);

tfLevel.setEditable(false);

tfScore.setEditable(false);

plButton.add(btPlay);

plButton.add(btPause);

plButton.add(btStop);

plButton.add(btTurnLevelUp);

plButton.add(btTurnLevelDown);

add(showbefore);

add(plInfo);

add(plButton);

addKeyListener(newControlKeyListener());

btPlay.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventae){

game.playGame();

}

});

btPause.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventae){

if(btPause.getText().equals(newString("暂停"))){

game.pauseGame();

}

else

{

game.resumeGame();

}

}

});

btStop.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventae)

{

game.stopGame();

}

});

btTurnLevelUp.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventae){

try{

intlevel=Integer.parseInt(tfLevel.getText());

if(level

tfLevel.setText(""+(level+1));

}catch(NumberFormatExceptione){}

requestFocus();

}

});

btTurnLevelDown.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEventae)

{

try{

intlevel=Integer.parseInt(tfLevel.getText());

if(level>1)

tfLevel.setText(""+(level-1));

}catch(NumberFormatExceptione){}

requestFocus();

}

});

addComponentListener(newComponentAdapter(){

publicvoidcomponentResized(ComponentEventce)

{

plShowBeforeBlock.fanning();

}

});

timer=newTimer(500,newActionListener(){

publicvoidactionPerformed(ActionEventae)

{

tfScore.setText(""+game.getScore());

intscoreForLevelUpdate=

game.getScoreForLevelUpdate

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 工学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1