?? controller.java
字號:
package lx.controller;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import lx.entity.Ground;
import lx.entity.Shape;
import lx.entity.ShapeFactory;
import lx.listener.ShapeListener;
import lx.view.GamePanle;
public class Controller extends KeyAdapter implements ShapeListener {
private Shape shape;
private ShapeFactory shapeFactory;
private Ground ground;
private GamePanle gamePanle;
public Controller(ShapeFactory shapeFactory,Ground ground,GamePanle gamePanle) {
this.shapeFactory = shapeFactory;
this.ground = ground;
this.gamePanle = gamePanle;
}
//鍵盤監聽
@Override
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(isShapeMoveDownable(shape)){
shape.moveDown();
}
break;
case KeyEvent.VK_LEFT:
if(ground.isMoveable(shape, Shape.LEFT)){
shape.moveLeft();
}
break;
case KeyEvent.VK_RIGHT:
if(ground.isMoveable(shape, Shape.RIGHT)){
shape.moveRight();
}
break;
}
gamePanle.dispaly(ground, shape);
}
public void shapeMoveDown(Shape shape) {
gamePanle.dispaly(ground, shape);
}
//判斷圖形是否可以繼續下落
public synchronized boolean isShapeMoveDownable(Shape shape) {
if(this.shape != shape){
return false;
}
if(ground.isMoveable(shape,Shape.DOWN)){
return true;
}
ground.accept(this.shape);
//沒有滿行則生成新的圖形
if(!ground.isFull()){
this.shape = shapeFactory.getShape(this);
}
return false;
}
//開始新游戲
public void newGame(){
shape = shapeFactory.getShape(this);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -