?? controller.java
字號:
package com.zhang.teris.controller;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import com.zhanggang.teris.entities.ShapeFactory;
import com.zhang.teris.listener.ShapeListener;
import com.zhanggang.teris.entities.Ground;
import com.zhanggang.teris.entities.Shape;
import com.zhanggang.teris.view.GamePanel;
public class Controller extends KeyAdapter implements ShapeListener {
private Ground ground;
private Shape shape;
private GamePanel gamePanel;
@Override
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_LEFT:
if(ground.isMovable(shape, Shape.LEFT))
shape.moveLeft();
break;
case KeyEvent.VK_RIGHT:
if(ground.isMovable(shape, Shape.RIGHT))
shape.moveRight();
break;
case KeyEvent.VK_DOWN:
if(ground.isMovable(shape, Shape.DOWN))
shape.moveDown();
break;
case KeyEvent.VK_UP:
if(ground.isMovable(shape, Shape.ROTATE))
shape.rotate();
break;
default:
break;
}
gamePanel.display(ground, shape);
}
public void shpeMoveDown(Shape shape) {
gamePanel.display(ground, shape);
}
public void newGame() {
shape = ShapeFactory.getShape(this);
}
public boolean isGameOver() {
return ground.isFull();
}
public Controller(Ground ground, Shape shape, GamePanel gamePanel) {
this.ground = ground;
this.shape = shape;
this.gamePanel = gamePanel;
}
public boolean isMoveDownable(Shape shape) {
boolean result = ground.isMovable(shape, Shape.DOWN);
if(result == false) {
ground.accept(shape);
if(!isGameOver()) {
this.shape = ShapeFactory.getShape(this);
}
}
return result;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -