⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 controller.java

📁 培训老师写的nb代码,midp1.0画出来的游戏
💻 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 + -