J2ME嗄老旗鷹幣箭!!躯袋帽圭翠(1)
扮寂:2011-01-11 蛎埔桁
和中頁厘亟議匯倖酒汽議躯袋帽圭翠嗄老旗鷹?旗鷹嶄麼勣淫根3倖窃?
lTerrisMIDlet——MIDlet窃
lGameCanvas——嗄老順中窃
lGameEngine——嗄老貸辞窃
聞喘WTK2.5.1塰佩宥狛.
醤悶旗鷹泌和?
//MIDlet窃
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class TerrisMIDlet extends MIDlet {
public TerrisMIDlet() {
Display.getDisplay(this).setCurrent(new GameCanvas());
}
protected void destroyApp(boolean arg0){}
protected void pauseApp() {}
protected void startApp() {}
}
//順中窃
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
/**
* 躯袋帽圭翠嗄老順中
*/
public class GameCanvas extends Canvasimplements Runnable{
GameEngine engine = new GameEngine();
int width;
int height;
/**嗄老潤崩延楚*/
boolean gameOver = false;
/**嗄老壙唯延楚*/
boolean isPaused = false;
String pauseStr = "壙唯";
String continueStr = "写偬";
public GameCanvas(){
//畠徳鳥
setFullScreenMode(true);
width = getWidth();
height = getHeight();
//尼強?殻
Thread th = new Thread(this);
th.start();
}
protected void paint(Graphics g) {
//賠徳
clearScreen(g);
//紙崙円崇
paintBoard(g);
//紙崙嘘尚
engine.paintMap(g);
//紙崙輝念和鯛圭翠
engine.paintBrick(g);
//紙崙和匯倖圭翠
engine.paintNextBrick(g);
//紙崙購触才嗄老誼蛍
engine.paintLevelAndScore(g);
//紙崙嗄老潤崩
if(gameOver){
g.drawString("Game Over", 30, 85,
Graphics.TOP | Graphics.LEFT);
}
//紙崙壙唯梓泥猟忖
if(isPaused){
g.drawString(pauseStr,width,height,
Graphics.RIGHT | Graphics.BOTTOM);
}else{
g.drawString(continueStr,width,height,
Graphics.RIGHT | Graphics.BOTTOM);
}
}
public void keyPressed(int keyCode){
if(keyCode == -7){ //嘔罷囚?壙唯陣崙
isPaused = !isPaused;
}
if(!isPaused){
int action = getGameAction(keyCode);
switch(action){
case UP:
case FIRE:
engine.changeShape();
break;
case LEFT:
engine.moveToLeft();
break;
|