俄罗斯方块源码(1)

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

package Tetris;

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

/**

* <p>Title: </p>

* <p>Description: </p>

* <p>Copyright: Copyright (c) 2004</p>

* <p>Company: </p>

* @author not attributable

* @version 1.0

*/

public class TetrisMIDlet extends MIDlet implements CommandListener{

Display display;

TetrisGameCanvas tetrisGame;

Command newCommand = new Command("New Game", Command.SCREEN, 1);

Command levelCommand = new Command("Level", Command.SCREEN, 2);

Command changeCommand = new Command("Change", Command.OK, 1);

Command cancelCommand = new Command("Cancel", Command.CANCEL, 2);

Command exitCommand = new Command("Exit", Command.EXIT, 3);

public TetrisMIDlet() {

display = Display.getDisplay(this);

if (tetrisGame == null) {

tetrisGame = new TetrisGameCanvas();

}

tetrisGame.addCommand(newCommand);

tetrisGame.addCommand(levelCommand);

tetrisGame.addCommand(exitCommand);

tetrisGame.setCommandListener(this);

}

/**

* 应用程序开始运行

* @throws javax.microedition.midlet.MIDletStateChangeException

*/

protected void startApp() throws javax.microedition.midlet.MIDletStateChangeException {

/**@todo Implement this javax.microedition.midlet.MIDlet abstract method*/

display.setCurrent(tetrisGame);

try {

Thread thread = new Thread(tetrisGame);

thread.start();

} catch(Error error) {

destroyApp(false);

notifyDestroyed();

}

}

/**

* 开始游戏等菜单命令的处理

* @param command

* @param displayable

*/

public void commandAction(Command command, Displayable displayable) {

if (command == newCommand) {

tetrisGame.newGame();

}

else if (command == levelCommand) {

/* Item [] levelItem = {new Gauge("Level", true, 400, tetrisGame.getLevel())};

Form form = new Form("Change Level", levelItem);

form.addCommand(changeCommand);

form.addCommand(cancelCommand);

form.setCommandListener(this);

display.setCurrent(form);

*/

tetrisGame.pauseGame();

Form form = new Form("Change Level");

ChoiceGroup cg = new ChoiceGroup("Level", Choice.EXCLUSIVE);

for (int i = 1; i <= 10; i++) {

cg.append("Level " + String.valueOf(i), null);

}

cg.setSelectedIndex(10 - tetrisGame.getLevel() / 35, true);

form.append(cg);

form.addCommand(changeCommand);

form.addCommand(cancelCommand);

form.setCommandListener(this);

display.setCurrent(form);

}

else if (command == exitCommand) {

tetrisGame.exit();

destroyApp(false);

notifyDestroyed();

}

else if (command == changeCommand) {

Form form = (Form)displayable;

ChoiceGroup cg = (ChoiceGroup)form.get(0);

tetrisGame.setLevel(350 - cg.getSelectedIndex() * 35);

tetrisGame.resumeGame();

display.setCurrent(tetrisGame);

/* Form form = (Form)displayable;

Gauge gauge = (Gauge)form.get(0);

tetrisGame.setLevel(gauge.getValue());

display.setCurrent(tetrisGame);

*/

}

else if (command == cancelCommand) {

display.setCurrent(tetrisGame);

}

}

protected void pauseApp() {

/**@todo Implement this javax.microedition.midlet.MIDlet abstract method*/

// tetrisGame.pauseGame();

}

protected void destroyApp(boolean parm1) {

/**@todo Implement this javax.microedition.midlet.MIDlet abstract method*/

display.setCurrent(null);

System.gc();

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航