欢迎来到天天文库
浏览记录
ID:44811681
大小:375.51 KB
页数:69页
时间:2019-10-29
《java 欧罗斯方块源代码 张孝祥老师》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、packagecn.itcast.tetris.controller;importjava.awt.Font;importjava.awt.event.KeyAdapter;importjava.awt.event.KeyEvent;importjava.util.HashSet;importjava.util.Set;importjavax.swing.JLabel;importcn.itcast.tetris.entities.Ground;importcn.itcast.tetris.entities.Shape;importcn.itcast.tetris.e
2、ntities.ShapeFactory;importcn.itcast.tetris.listener.GameListener;importcn.itcast.tetris.listener.GroundListener;importcn.itcast.tetris.listener.ShapeListener;importcn.itcast.tetris.util.Global;importcn.itcast.tetris.view.GamePanel;/***控制器*控制Ground,Snake,Food*负责游戏的逻辑*处理按键事件<
3、BR>***@version1.0,01/01/08**@author汤阳光**/publicclassControllerextendsKeyAdapterimplementsShapeListener,GroundListener{protectedSetlisteners=newHashSet();/***图形工厂**/protectedShapeFactoryshapeFactory;protectedShapeshape;protectedGroundground;protectedGamePa
4、nelgamePanel;protectedJLabelgameInfoLabel;/***当前的游戏状态*/protectedbooleanplaying;/****@paramshapeFactory*@paramground*@paramgamePanel*/publicController(ShapeFactoryshapeFactory,Groundground,GamePanelgamePanel){super();this.shapeFactory=shapeFactory;this.ground=ground;this.gamePanel=gamePa
5、nel;}/***多接受一个JTextComponent,可以给在这个组件上显示提示信息**@paramshapeFactory*@paramground*@paramgamePanel*@paramgameInfoLabel*/publicController(ShapeFactoryshapeFactory,Groundground,GamePanelgamePanel,JLabelgameInfoLabel){this(shapeFactory,ground,gamePanel);this.setGameInfoLabel(gameInfoLabel);}/**
6、*处理键盘按键*LEFT:向左移动*RIGHT:向右移动*DOWN:向下移动*UP:变形*PAGEUP:加快速度*PAGEDOWN:减慢速度*Y:重新开始游戏*ENTER:暂停/继续*/@OverridepublicvoidkeyPressed(KeyEvente){if(e.getKeyCode()!=KeyEvent.VK_Y&&!playing)return;switch(e.getKeyCode()){/***方向左*/caseKeyEvent.VK_LEFT:if(isPausingGame()
7、){this.continueGame();}shape.setSwift(false);if(isPlaying()&&ground.isMoveable(shape,Shape.LEFT))shape.moveLeft();break;/***方向右*/caseKeyEvent.VK_RIGHT:if(isPausingGame()){this.continueGame();}shape.setSwift(false);if(isPlaying()&&ground.isMoveable(shape,Shape.RIGHT))shape.moveR
此文档下载收益归作者所有