📄 uicontroller.java
字号:
package picturepuzzle;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.Image;
import java.io.IOException;
/**
* <p>Title: 拼图游戏</p>
*
* <p>Description: 拼图游戏</p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: Star Group</p>
*
* @author wangyaobsz
* @version 1.0
*/
public class UIController {
//定义各类事件的ID
public static class EventID{
private EventID(){
}
public static final byte EVENT_START = 01;
public static final byte EVENT_GAME_RUN = 02;
public static final byte EVENT_GAME_ABORT = 03;
public static final byte EVENT_EXIT = 04;
public static final byte EVENT_HELP = 05;
}
private PicPuzzleMIDlet gameMIDlet; //主控类对象
private Display display; //设备描述符
private PicPuzzleCanvas gamedisplay; //游戏的主界面类
private SelectForm select; //选择屏幕
private HelpForm help; //帮助信息屏幕
public UIController(PicPuzzleMIDlet gameMIDlet) {
this.gameMIDlet = gameMIDlet;
this.display = Display.getDisplay(this.gameMIDlet);
select = new SelectForm(this);
}
public void handleEvent(byte eventID){
switch(eventID){
case EventID.EVENT_START: //创建游戏,显示选择屏幕
display.setCurrent(select);
break;
case EventID.EVENT_GAME_RUN: //进入游戏
if(gamedisplay == null){
int nIndex = select.getImgIndex();
try {
Image img = Image.createImage("/res/pic" + nIndex + ".png");
gamedisplay = new PicPuzzleCanvas(this, img);
}
catch (IOException e) {
e.printStackTrace();
}
}
select = null;
help = null;
display.setCurrent(gamedisplay);
break;
case EventID.EVENT_GAME_ABORT: //用户中止当前游戏操作
select = new SelectForm(this);
gamedisplay = null;
handleEvent(EventID.EVENT_START);
break;
case EventID.EVENT_EXIT: //退出游戏
this.gameMIDlet.destroyApp(false);
this.gameMIDlet.notifyDestroyed();
break;
case EventID.EVENT_HELP: //获取帮助信息
help = new HelpForm("帮助",this);
display.setCurrent(help);
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -