?? controller.java
字號:
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
public class Controller extends Canvas implements ShapeListener
{
private Shape shape;
private Ground ground;
private GamePanel gamePanle;
private ShapeFactory shapeFactory;
private boolean isPress = false;
private Shape isShapeMoveDown = null;
public Controller()
{
shapeFactory = new ShapeFactory();
ground = new Ground();
gamePanle = new GamePanel();
}
public void newGame()
{
shape = shapeFactory.getShape(this);
}
protected void keyPressed(int key)
{
isPress = true;
switch(getGameAction(key))
{
case UP:
if(ground.isMoveable(shape, Shape.ROTATE))
shape.rotate();
break;
case DOWN:
if(isShapeMoveable(shape))
shape.moveDown();
break;
case LEFT:
if(ground.isMoveable(shape, Shape.LEFT))
shape.moveLeft();
break;
case RIGHT:
if(ground.isMoveable(shape, Shape.RIGHT))
shape.moveRight();
break;
default:
isPress = false;
break;
}
if(isPress == true)
{
repaint();
}
}
public void shapeMoveDown(Shape shape)
{
isShapeMoveDown = shape;
repaint();
}
public synchronized boolean isShapeMoveable(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;
}
protected void paint(Graphics g)
{
if(isPress)
{
gamePanle.display(g, this.shape, this.ground);
isPress = false;
}
if(isShapeMoveDown != null)
{
gamePanle.display(g, isShapeMoveDown, this.ground);
isShapeMoveDown = null;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -