uicontroller.java~21~

来自「利用Java 开发的一个手机版的潜艇游戏。游戏实现的重点就是屏幕的绘制滚动技术和」· JAVA~21~ 代码 · 共 99 行

JAVA~21~
99
字号
package mysubmarine;

import javax.microedition.lcdui.Display;

/**
 * <p>Title: 俄罗斯方块</p>
 *
 * <p>Description: 俄罗斯方块游戏</p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: Star Group</p>
 *
 * @author not attributable
 * @version 1.0
 */
public class UIController {
    //定义各类事件的ID
    public static class EventID {
        private EventID() {

        }

        public static final byte EVENT_START_SPLASH = 01;
        public static final byte EVENT_GAME_RUN = 02;
        public static final byte EVENT_GAME_PAUSE = 03;
        public static final byte EVENT_EXIT = 04;

        public static final byte EVENT_NEXTROUND = 101;
    }


    private MysubmarineMIDlet gameMIDlet;
    private Display display;

    private Splash splash;
    private MySubmarineCanvas gamedisplay;
    private Splash nextRound;

    public UIController(MysubmarineMIDlet gameMIDlet) {
        this.gameMIDlet = gameMIDlet;
        this.display = Display.getDisplay(this.gameMIDlet);
    }

    public void handleEvent(byte eventID) {
        switch (eventID) {
        case EventID.EVENT_START_SPLASH:
            if (splash == null) {
                StringBuffer str = new StringBuffer("Starting...");
                splash = new Splash(this, str);
            }
            display.setCurrent(splash);
            Thread st = new Thread(this.splash);
            try {
                st.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            st.start();
            break;
        case EventID.EVENT_GAME_RUN:
            if (gamedisplay == null) {
                gamedisplay = new MySubmarineCanvas(this);
            }
            display.setCurrent(gamedisplay);
            gamedisplay.setActive();
            splash = null;
            nextRound = null;
            break;
        case EventID.EVENT_NEXTROUND:
            if (nextRound == null) {
                StringBuffer str = new StringBuffer("Next Round...");
                nextRound = new Splash(this, str);
            }
            display.setCurrent(nextRound);
            Thread nr = new Thread(this.nextRound);
            try {
                nr.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            nr.start();
            break;
        case EventID.EVENT_EXIT:
            this.gameMIDlet.destroyApp(false);
            this.gameMIDlet.notifyDestroyed();
            break;
        }
    }

    public void setSplash(Splash sp) {
        this.splash = sp;
    }

    public void setNextRoundSplash(Splash nr) {
        this.nextRound = nr;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?