ImageVerifierCode 换一换
格式:DOCX , 页数:26 ,大小:177.72KB ,
资源ID:19867538      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/19867538.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(java俄罗斯方块开发文档Word格式文档下载.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

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

1、其他的改版中出现更多特别的造型。方块会从区域上方开始缓慢继续落下。(2)玩家可以做的操作有:以90度为单位旋转方块,以格子为单位左右移动方块,让方块加速落下。(3)方块移到区域最下方或是着地到其他方块上无法移动时,就会固定在该处,而新的方块出现在区域上方开始落下。(4)当区域中某一列横向格子全部由方块填满,则该列会消失并成为玩家的得分。同时删除的列数越多,得分指数上升。(5)当固定的方块堆到区域最上方而无法消除层数时,则游戏结束。(6)一般来说,游戏还会提示下一个要落下的方块,熟练的玩家会计算到下一个方块,评估要如何进行。由于游戏能不断进行下去对商业用游戏不太理想,所以一般还会随着游戏的进行而

2、加速提高难度。(7)通过设计者预先设置的随机发生器不断地输出单个方块到场地顶部,以一定的规则进行移动、旋转、下落和摆放,锁定并填充到场地中。每次摆放如果将场地的一行或多行完全填满,则组成这些行的所有小正方形将被消除,并且以此来换取一定的积分或者其他形式的奖励。而未被消除的方块会一直累积,并对后来的方块摆放造成各种影响。(8)如果未被消除的方块堆放的高度超过场地所规定的最大高度(并不一定是20或者玩家所能见到的高度),则游戏结束。建立对象模型根据需求分析,游戏需要一个虚拟场地,场地由多个小方格组成,一般是高度大于宽度。该场地主要作用是显示方块所在的位置,设置GamePanel类。该类中有disp

3、lay()方法显示方块。七种不同类型的方块使用Shape类表示,方块可以完成显示、自动落下、向左移、向右移、向下移、旋转等动作,使用drawMe()方法、autoDown()方法、moveLeft()、moveRight()方法、moveDown()方法、rotate()方法表示。根据DAO模式,产生不同方块的工作交给工厂类ShapeFactory类,由它来产生不同的方法,该方法命名为getShape()方法。方块落下后会变成障碍物,设置障碍物类Ground,它可以将方块变成障碍物,使用accept()方法,然后将其显示出来,使用drawMe()方法。这样确定的类有四个,这四个类是相对独立的。

4、方块工厂ShapeFactory类产生Shape类的对象。游戏面板GamePanel类可以接受用户的按键控制方块的各种动作,需要处理按键事件的代码。根据MVC模式的设计思想,需要将处理逻辑的代码独立出来。因此可以将按键事件的处理代码和处理逻辑的代码合为中央控制器类Controller类,该游戏的模型关系如图划分功能模块根据游戏的需求,将功能分为方块产生与自动下落、方块的移动与显示、障碍物的生成与消除以及游戏结束等几部分。方块产生与自动下落模块主要完成七种不同方块及方块旋转90度后的状态表示,使用工厂类创建方块,产生后能够自动下落。方块的移动与显示模块主要完成方块的左移、向右移、向下移、旋转、显

5、示等功能。障碍物的生成与消除模块主要完成下落的方块变成障碍物并显示,将障碍物填满一行后消除。任务二(1)遵循MVC模式,创建com.teteris.test包,com.teteris.view包,com.teteris.entities包,com.teteris.controller包。(2)创建Shape类,该类有向左移,向右移,下降,旋转,绘制自身等方法。public class Shape public void moveLeft() System.out.println(Shapes moveLeft); public void moveRight() s moveRight publ

6、ic void moveDown() s moveDown public void rotate() System.out.println(s rotate public void drawMe(Graphics g) s drawMe(3)创建ShapeFactory类,该类负责产生各种方块。public class ShapeFactory public Shape getShape(ShapeListener listener) ShapeFactorys getShape return Shape();(4)创建Ground类,该类将方块变成障碍物,以及将障碍物重绘。public cl

7、ass Ground public void accept(Shape shape) System.out.println(Grounds acceptpublic void drawMe(Graphics g) (5)创建GamePanel类,该类作为游戏界面,显示方块和障碍物,由于方块和障碍物会发生变化,因此需要方法对方块和障碍物进行重绘。public class GamePanel extends JPanel private Ground ground; private Shape shape; public void display(Ground ground, Shape shap

8、e) GamePanls display this.ground = ground; this.shape = shape; this.repaint(); protected void paintComponent(Graphics g) if (shape != null & ground != null) shape.drawMe(g); ground.drawMe(g); public GamePanel() this.setSize(300,300)(6)创建Controller类,该类继承按键适配器,实现用户对方块的各种操作。public class Controller exte

9、nds KeyAdapter implements ShapeListener private ShapeFactory shapeFactory; private GamePanel gamePanel; public void keyPressed(KeyEvent e) switch (e.getKeyCode() case KeyEvent.VK_UP: if (ground.isMoveable(shape, Shape.ROTATE) shape.rotate(); break; case KeyEvent.VK_DOWN: if (ground.isMoveable(shape,

10、 Shape.DOWN) shape.moveDown(); case KeyEvent.VK_LEFT: if (ground.isMoveable(shape, Shape.LEFT) shape.moveLeft(); case KeyEvent.VK_RIGHT: if (ground.isMoveable(shape, Shape.RIGHT) shape.moveRight(); gamePanel.display(ground, shape); public void newGame() shape = shapeFactory.getShape(this); public Co

11、ntroller(ShapeFactory shapeFactory, Ground ground, GamePanel gamePanel) this.shapeFactory = shapeFactory; this.gamePanel = gamePanel; Override public void shapeMoveDown(Shape shape) public synchronized boolean isShapeMoveDownable(Shape shape) if (ground.isMoveable(shape, Shape.DOWN) return true; gro

12、und.accept(this.shape); if (!ground.isFull() this.shape = shapeFactory.getShape(this); return false;任务三俄罗斯方块游戏中有七种不同形状的方块,每种方块还可以进行旋转变形产生不同的状态,这些都需要在程序中描述它们。同时,方块的自动下落功能也需要实现(1)定义图形及其不同状态游戏中是不同形状的方块在游戏面板的不同位置移动,可以将游戏面板看为由20*10的小方格组成。面板的原点坐标在左上角,水平向右为X轴正反向,垂直向下为Y轴正方向。在下方的小方格代表障碍物,不同的小方格可以表示不同的方块以及它们的

13、不同状态。1)修改Shape类,添加方块的定义。 private int body; private int status; public void setBody(int body) this.body = body; public void setStatus(int status) this.status = status;2)修改ShapeFactory类,添加方块的状态。 private int shapes =new int /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,

14、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,

15、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,

16、 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,

17、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 ; public Shape getShape(ShapeListener listener) Shape shape = new Shape(); shape.addShap

18、eListener(listener); int type = new Random().nextInt(shapes.length); shape.setBody(shapestype); shape.setStatus(0); return shape;(2)创建ShapeListener接口,该接口对方块自动下落方法进行定义。public interface ShapeListener void shapeMoveDown(Shape shape);(3)修改Shape类,定义ShapeListener监听器,定义多线程,实现方块自动下降。 private ShapeListen pri

19、vate class ShapeDriver implements Runnable Override public void run() while (listener.isShapeMoveDownable(Shape.this) moveDown(); listener.shapeMoveDown(Shape.this); try Thread.sleep(1000); catch (Exception e) e.printStackTrace(); public Shape() new Thread(new ShapeDriver().start(); public void addS

20、hapeListener(ShapeListener l) if (l ! this.listener = l;(4)修改Controller类,实现ShapeListener接口。 boolean result=ground.isMoveable(shape,Shape.DOWN); return false;(5)修改ShapeFactory类,给方块添加ShapeListener监听器(6)新建一个Test类,完成游戏中各个类的组装。public class Test public static void main(String args) ShapeFactory shapeFacto

21、ry=new ShapeFactory(); Ground ground=new Ground(); GamePanel gamePanel=new GamePanel(); Controller controller=new Controller(shapeFactory, ground, gamePanel); JFrame frame=new JFrame(); frame.setSize(gamePanel.getSize().width+10, gamePanel.getSize().height+10); frame.add(gamePanel); gamePanel.addKey

22、Listener(controller); frame.addKeyListener(controller); frame.setVisible(true); controller.newGame();任务四用户单击键盘上得方向键,可以控制方块左移,右移或向下移。需要注意游戏的界面是有边界的,当图形到达游戏界面边界时,应不能继续移动。图形类里面要保存自己的位置信息,用left 表示图形到左边界的距离,top 表示图形到上边界的距离图形移动就是改变left 和 top 的值1)创建Global类,存储项目中所需常亮public class Global public static final i

23、nt CELL_SIZE = 20; public static final int WIDTH = 15; public static final int HEIGHT = 15;2)修改Shape类,完成方块绘制 g.setColor(Color.GREEN); for (int x = 0; x 4; x+) for (int y = 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); private boolean getFlagByPoint(int x, int y) return bodystatusy * 4 + x = 1;3)修改GamePanel类,修改绘制方法 g.setColor(new Color(0x0c); g.fillRect(0, 0,300,300); if (shape ! gro

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

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