欢迎来到天天文库
浏览记录
ID:36538955
大小:276.41 KB
页数:25页
时间:2019-05-09
《Java俄罗斯方块实现步骤》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、项目实战 --俄罗斯方块主讲:贾宗维程序演示游戏01_功能演示与说明游戏02_面向对象设计游戏03_使用API类组装游戏游戏04_编写各个类主体框架游戏05_编写Controler类实现事件监听游戏06_编写类测试代码游戏07_图形设计与创建游戏08_图形移动与显示游戏09_处理游戏边界问题游戏10_障碍物生成与显示游戏11_消除满行的障碍物游戏12_增加游戏结束游戏13_定时下落编写各个类主体框架-Shape类publicclassShape{//privateShapeListenerlistener;publicvoidmoveLeft(){System.out.prin
2、tln("shape'smoveLeft");}publicvoidmoveRight(){System.out.println("shape'smoveright");}publicvoidmoveDown(){System.out.println("shape'smoveDown");}publicvoidrotate(){System.out.println("shape'srotate");}publicvoiddrawMe(){System.out.println("shape'sdrawme");}privateclassShapeDriverimplementsRu
3、nnable{publicvoidrun(){//TODOAuto-generatedmethodstubwhile(true){moveDown();//listener.shapeMoveDown(Shape.this);try{Thread.sleep(1000);}catch(InterruptedExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();编写各个类主体框架-ShapeFactory类publicclassShapeFactory{publicShapegetShape(ShapeListe
4、nerlistener){System.out.println("ShapeFactory'sgetShape");Shapeshape=newShape();returnshape;}}编写各个类主体框架-Ground类packagecn.tetris.entities;publicclassGround{publicvoidaccept(){System.out.println("Ground'saccept");}publicvoiddrawMe(){System.out.println("Ground'sdrawMe");}}编写各个类主体框架-GamePanel类pub
5、licclassGamePanelextendsJPanel{privateGroundground;privateShapeshape;publicvoiddisplay(Groundground,Shapeshape){System.out.println("GamePanel'sdisplay");this.ground=ground;this.shape=shape;this.repaint();}@OverrideprotectedvoidpaintComponent(Graphicsarg0){//TODOAuto-generatedmethodstub//重新显示i
6、f(ground!=null&&shape!=null){ground.drawMe();shape.drawMe();}}编写各个类主体框架-Controller类publicclassControllerextendsKeyAdapter{privateGroundground;privateShapeshape;privateShapeFactoryshapeFactory;privateGamePanelgamePanel;publicvoidkeyPressed(KeyEvente){switch(e.getKeyCode()){caseKeyEvent.VK_UP:s
7、hape.rotate();break;caseKeyEvent.VK_LEFT:shape.moveLeft();break;caseKeyEvent.VK_RIGHT:shape.moveRight();break;caseKeyEvent.VK_DOWN:shape.moveDown();break;}gamePanel.display(ground,shape);}编写各个类主体框架-ShapeListener接口publicinterfaceShapeListener{
此文档下载收益归作者所有