java俄罗斯方块开发文档Word格式文档下载.docx

上传人:b****5 文档编号:19867538 上传时间:2023-01-11 格式:DOCX 页数:26 大小:177.72KB
下载 相关 举报
java俄罗斯方块开发文档Word格式文档下载.docx_第1页
第1页 / 共26页
java俄罗斯方块开发文档Word格式文档下载.docx_第2页
第2页 / 共26页
java俄罗斯方块开发文档Word格式文档下载.docx_第3页
第3页 / 共26页
java俄罗斯方块开发文档Word格式文档下载.docx_第4页
第4页 / 共26页
java俄罗斯方块开发文档Word格式文档下载.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

java俄罗斯方块开发文档Word格式文档下载.docx

《java俄罗斯方块开发文档Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《java俄罗斯方块开发文档Word格式文档下载.docx(26页珍藏版)》请在冰豆网上搜索。

java俄罗斯方块开发文档Word格式文档下载.docx

其他的改版中出现更多特别的造型。

方块会从区域上方开始缓慢继续落下。

(2)玩家可以做的操作有:

以90度为单位旋转方块,以格子为单位左右移动方块,让方块加速落下。

(3)方块移到区域最下方或是着地到其他方块上无法移动时,就会固定在该处,而新的方块出现在区域上方开始落下。

(4)当区域中某一列横向格子全部由方块填满,则该列会消失并成为玩家的得分。

同时删除的列数越多,得分指数上升。

(5)当固定的方块堆到区域最上方而无法消除层数时,则游戏结束。

(6)一般来说,游戏还会提示下一个要落下的方块,熟练的玩家会计算到下一个方块,评估要如何进行。

由于游戏能不断进行下去对商业用游戏不太理想,所以一般还会随着游戏的进行而加速提高难度。

(7)通过设计者预先设置的随机发生器不断地输出单个方块到场地顶部,以一定的规则进行移动、旋转、下落和摆放,锁定并填充到场地中。

每次摆放如果将场地的一行或多行完全填满,则组成这些行的所有小正方形将被消除,并且以此来换取一定的积分或者其他形式的奖励。

而未被消除的方块会一直累积,并对后来的方块摆放造成各种影响。

(8)如果未被消除的方块堆放的高度超过场地所规定的最大高度(并不一定是20或者玩家所能见到的高度),则游戏结束。

建立对象模型

根据需求分析,游戏需要一个虚拟场地,场地由多个小方格组成,一般是高度大于宽度。

该场地主要作用是显示方块所在的位置,设置GamePanel类。

该类中有display()方法显示方块。

七种不同类型的方块使用Shape类表示,方块可以完成显示、自动落下、向左移、向右移、向下移、旋转等动作,使用drawMe()方法、autoDown()方法、moveLeft()、moveRight()方法、moveDown()方法、rotate()方法表示。

根据DAO模式,产生不同方块的工作交给工厂类ShapeFactory类,由它来产生不同的方法,

该方法命名为getShape()方法。

方块落下后会变成障碍物,设置障碍物类Ground,它可以将方块变成障碍物,使用accept()方法,然后将其显示出来,使用drawMe()方法。

这样确定的类有四个,这四个类是相对独立的。

方块工厂ShapeFactory类产生Shape类的对象。

游戏面板GamePanel类可以接受用户的按键控制方块的各种动作,需要处理按键事件的代码。

根据MVC模式的设计思想,需要将处理逻辑的代码独立出来。

因此可以将按键事件的处理代码和处理逻辑的代码合为中央控制器类Controller类,该游戏的模型关系如图

划分功能模块

根据游戏的需求,将功能分为方块产生与自动下落、方块的移动与显示、障碍物的生成与消除以及游戏结束等几部分。

方块产生与自动下落模块主要完成七种不同方块及方块旋转90度后的状态表示,使用工厂类创建方块,产生后能够自动下落。

方块的移动与显示模块主要完成方块的左移、向右移、向下移、旋转、显示等功能。

障碍物的生成与消除模块主要完成下落的方块变成障碍物并显示,将障碍物填满一行后消除。

任务二

(1)遵循MVC模式,创建com.teteris.test包,com.teteris.view包,com.teteris.entities包,com.teteris.controller包。

(2)创建Shape类,该类有向左移,向右移,下降,旋转,绘制自身等方法。

publicclassShape{

publicvoidmoveLeft(){

System.out.println("

Shape'

smoveLeft"

);

}

publicvoidmoveRight(){

smoveRight"

publicvoidmoveDown(){

smoveDown"

publicvoidrotate(){

System.out.println("

srotate"

publicvoiddrawMe(Graphicsg){

sdrawMe"

}

(3)创建ShapeFactory类,该类负责产生各种方块。

publicclassShapeFactory{

publicShapegetShape(ShapeListenerlistener){

ShapeFactory'

sgetShape"

returnShape();

(4)创建Ground类,该类将方块变成障碍物,以及将障碍物重绘。

publicclassGround{

publicvoidaccept(Shapeshape){

System.out.println("

Ground'

saccept"

publicvoiddrawMe(Graphicsg){

(5)创建GamePanel类,该类作为游戏界面,显示方块和障碍物,由于方块和障碍物会发生变化,因此需要方法对方块和障碍物进行重绘。

publicclassGamePanelextendsJPanel{

privateGroundground;

privateShapeshape;

publicvoiddisplay(Groundground,Shapeshape){

GamePanl'

sdisplay"

this.ground=ground;

this.shape=shape;

this.repaint();

protectedvoidpaintComponent(Graphicsg){

if(shape!

=null&

&

ground!

=null){

shape.drawMe(g);

ground.drawMe(g);

}

publicGamePanel(){

this.setSize(300,300)

(6)创建Controller类,该类继承按键适配器,实现用户对方块的各种操作。

publicclassControllerextendsKeyAdapterimplementsShapeListener{

privateShapeFactoryshapeFactory;

privateGamePanelgamePanel;

publicvoidkeyPressed(KeyEvente){

switch(e.getKeyCode()){

caseKeyEvent.VK_UP:

if(ground.isMoveable(shape,Shape.ROTATE))

shape.rotate();

break;

caseKeyEvent.VK_DOWN:

if(ground.isMoveable(shape,Shape.DOWN))

shape.moveDown();

caseKeyEvent.VK_LEFT:

if(ground.isMoveable(shape,Shape.LEFT))

shape.moveLeft();

caseKeyEvent.VK_RIGHT:

if(ground.isMoveable(shape,Shape.RIGHT))

shape.moveRight();

gamePanel.display(ground,shape);

publicvoidnewGame(){

shape=shapeFactory.getShape(this);

publicController(ShapeFactoryshapeFactory,Groundground,GamePanelgamePanel){

this.shapeFactory=shapeFactory;

this.gamePanel=gamePanel;

@Override

publicvoidshapeMoveDown(Shapeshape){

publicsynchronizedbooleanisShapeMoveDownable(Shapeshape){

if(ground.isMoveable(shape,Shape.DOWN)){

returntrue;

ground.accept(this.shape);

if(!

ground.isFull()){

this.shape=shapeFactory.getShape(this);

returnfalse;

任务三

俄罗斯方块游戏中有七种不同形状的方块,每种方块还可以进行旋转变形产生不同的状态,这些都需要在程序中描述它们。

同时,方块的自动下落功能也需要实现

(1)定义图形及其不同状态

游戏中是不同形状的方块在游戏面板的不同位置移动,可以将游戏面板看为由20*10的小方格组成。

面板的原点坐标在左上角,水平向右为X轴正反向,垂直向下为Y轴正方向。

在下方的小方格代表障碍物,不同的小方格可以表示不同的方块以及它们的不同状态。

1)修改Shape类,添加方块的定义。

privateint[][]body;

privateintstatus;

publicvoidsetBody(int[][]body){

this.body=body;

publicvoidsetStatus(intstatus){

this.status=status;

2)修改ShapeFactory类,添加方块的状态。

privateintshapes[][][]=newint[][][]{

//I

{

{0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0},

{0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0},

{0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0}

},

//s

{0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0},

{1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0},

{1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0}

//z

{1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0},

{0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0},

{0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0}

//j

{0,1,0,0,0,1,0,0,1,1,0,0,0,0,0,0},

{1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0},

{1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0},

{1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0}

//o

{1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0},

{1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0},

{1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0}

//l

{1,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0},

{1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0},

{1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0},

{0,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0}

//t

{0,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0},

{0,1,0,0,1,1,0,0,0,1,0,0,0,0,0,0},

{1,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0},

{0,1,0,0,0,1,1,0,0,1,0,0,0,0,0,0}

}

};

publicShapegetShape(ShapeListenerlistener){

Shapeshape=newShape();

shape.addShapeListener(listener);

inttype=newRandom().nextInt(shapes.length);

shape.setBody(shapes[type]);

shape.setStatus(0);

returnshape;

(2)创建ShapeListener接口,该接口对方块自动下落方法进行定义。

publicinterfaceShapeListener{

voidshapeMoveDown(Shapeshape);

(3)修改Shape类,定义ShapeListener监听器,定义多线程,实现方块自动下降。

privateShapeListen{

privateclassShapeDriverimplementsRunnable{

@Override

publicvoidrun(){

while(listener.isShapeMoveDownable(Shape.this)){

moveDown();

listener.shapeMoveDown(Shape.this);

try{

Thread.sleep(1000);

}catch(Exceptione){

e.printStackTrace();

}

}

publicShape(){

newThread(newShapeDriver()).start();

publicvoidaddShapeListener(ShapeListenerl){

if(l!

this.listener=l;

(4)修改Controller类,实现ShapeListener接口。

 

booleanresult=ground.isMoveable(shape,Shape.DOWN);

returnfalse;

(5)修改ShapeFactory类,给方块添加ShapeListener监听器

(6)新建一个Test类,完成游戏中各个类的组装。

publicclassTest{

publicstaticvoidmain(String[]args){

ShapeFactoryshapeFactory=newShapeFactory();

Groundground=newGround();

GamePanelgamePanel=newGamePanel();

Controllercontroller=newController(shapeFactory,ground,gamePanel);

JFrameframe=newJFrame();

frame.setSize(gamePanel.getSize().width+10,gamePanel.getSize().height+10);

frame.add(gamePanel);

gamePanel.addKeyListener(controller);

frame.addKeyListener(controller);

frame.setVisible(true);

controller.newGame();

任务四

用户单击键盘上得方向键,可以控制方块左移,右移或向下移。

需要注意游戏的界面是有边界的,当图形到达游戏界面边界时,应不能继续移动。

图形类里面要保存自己的位置信息,

用left表示图形到左边界的距离,top表示图形到上边界的距离

图形移动就是改变left和top的值

1)创建Global类,存储项目中所需常亮

publicclassGlobal{

publicstaticfinalintCELL_SIZE=20;

publicstaticfinalintWIDTH=15;

publicstaticfinalintHEIGHT=15;

2)修改Shape类,完成方块绘制

g.setColor(Color.GREEN);

for(intx=0;

x<

4;

x++){

for(inty=0;

y<

y++){

if(getFlagByPoint(x,y)){

g.fill3DRect((left+x)*Global.CELL_SIZE,(top+y)*Global.CELL_SIZE,Global.CELL_SIZE,

Global.CELL_SIZE,true);

privatebooleangetFlagByPoint(intx,inty){

returnbody[status][y*4+x]==1;

3)修改GamePanel类,修改绘制方法

g.setColor(newColor(0x0c));

g.fillRect(0,0,300,300);

if(shape!

gro

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

当前位置:首页 > 法律文书 > 调解书

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

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