gamemidlet.java

来自「J2ME的游戏原代码!希望能帮助有需要帮助的师兄弟们!」· Java 代码 · 共 925 行 · 第 1/3 页

JAVA
925 行
字号
            else if (l == languageMenu)            {                if (c == OK_CMD || c == List.SELECT_COMMAND)                {                    lang = (short) l.getSelectedIndex();                    canvas.removeCommand(OK_CMD);                    canvas.removeCommand(BACK_CMD);                    setUpMenus();                    SaveLang(lang);                    display.setCurrent(mainMenu);               }                else if (c == BACK_CMD)                {                    display.setCurrent(optionsMenu);                }            }            else if (l == soundMenu)            {                if (c == OK_CMD || c == List.SELECT_COMMAND)                {                    int idx = l.getSelectedIndex();                    if (idx == SOUNDON)                    {                        mso.SelOptions |= GameShell.GAM_OPT_SOUND;                    }                    else if (idx == SOUNDOFF)                    {                        mso.SelOptions &= ~GameShell.GAM_OPT_SOUND;                    }                    display.setCurrent(optionsMenu);                }                else if (c == BACK_CMD)                {                    display.setCurrent(optionsMenu);                }            }            else if (l == forbiddenMenu)            {                if (c == OK_CMD || c == List.SELECT_COMMAND)                {                    int idx = l.getSelectedIndex();                    if (idx == FORBIDDENON)                    {                        mso.SelOptions |= GameShell.GAM_OPT_FORBIDDEN_RULES;                    }                    else if (idx == FORBIDDENOFF)                    {                        mso.SelOptions &= ~GameShell.GAM_OPT_FORBIDDEN_RULES;                    }                    display.setCurrent(optionsMenu);                }                else if (c == BACK_CMD)                {                    display.setCurrent(optionsMenu);                }            }            else if (l == colorMenu)            {                if (c == OK_CMD || c == List.SELECT_COMMAND)                {                    int idx = l.getSelectedIndex();                    if (idx == COLORBLACK)                    {                        mso.SelOptions |= GameShell.GAM_OPT_PLAYER_SIDE_BLACK;                        mso.SelOptions &= ~GameShell.GAM_OPT_PLAYER_SIDE_WHITE;                    }                    else if (idx == COLORWHITE)                    {                        mso.SelOptions |= GameShell.GAM_OPT_PLAYER_SIDE_WHITE;                        mso.SelOptions &= ~GameShell.GAM_OPT_PLAYER_SIDE_BLACK;                    }                    display.setCurrent(optionsMenu);                }                else if (c == BACK_CMD)                {                    display.setCurrent(optionsMenu);                }            }            else if (l == newGameMenu)            {                if (c == List.SELECT_COMMAND)                {                    int idx = l.getSelectedIndex();                    if (idx == SINGLE)                    {                        mso.SelOpponents = GameShell.GAM_OPP_PHONE;                        if (difficultyMenu != null)                            display.setCurrent(difficultyMenu);                    }                    else if (idx == TWO_ON_SAME && lockCommandAction())                    {                        mso.SelOpponents = GameShell.GAM_OPP_SAME_PHONE;                        if (mso.AllowTwoOnSameLevels == GameShell.GAM_LEVEL_NONE)                        {                            mso.SelStartMode = GameShell.GAM_START_NEW;                            display.setCurrent(canvas);                            canvas.launchGame();                        }                    }                }                else if (c == BACK_CMD)                {                    display.setCurrent(mainMenu);                }            }        }        else if (s instanceof GameShell)        {            if (c == BACK_CMD)            {                GameShell gs = (GameShell) s;                gs.handleBackCommand();            }            else if (c == OK_CMD)            {                GameShell gs = (GameShell) s;                gs.handleOkCommand();            }            else if (c == HSCLEAR_CMD)            {                GameShell gs = (GameShell) s;                curEvent.ClearHighScore = true;                curEvent.ViewHighScore = false;                curEvent.SendHighScore = false;                curEvent.type = GameShell.GAHighScoreEvent;                canvas.gameMain(curEvent);                gs.handleBackCommand();            }            /* THIS IS USED IF SEND HIGH SCORE FUNCTIONALITY IS ENABLED            else if (c == HSSEND_CMD)            {                curEvent.ClearHighScore = false;                curEvent.ViewHighScore = false;                curEvent.SendHighScore = true;                curEvent.type = GameShell.GAHighScoreEvent;                canvas.gameMain(curEvent);            }             */        }    }    public void pauseApp()    {}    public void destroyApp(boolean unconditional)    {        curEvent.type = GameShell.GATerminateEvent;        canvas.gameMain(curEvent);        display.setCurrent(null);    }    public void enterHighScore()    {        he = new TextBox(Lang.labels[lang][Lang.MENU_GAMES_HIGHSCORE_TXT], "",                         GameShell.GAPI_HIGHSCORE_USE_NAME, TextField.ANY);        he.addCommand(OK_CMD);        he.addCommand(BACK_CMD);        he.setCommandListener(this);        display.setCurrent(he);    }    public void returnToMenu()    {        canvas = null;        mso = null;        System.gc();        doInitMenus();        display.setCurrent(mainMenu);    }    /**     * Returns user's choice of language. -1 will be returned if no choice has     * been done before.     *     * @returns TRUE if succesfull, that is the menu id exist.     */    short GetLang()    {        RecordStore store;        byte[] data;        ByteArrayInputStream bis;        DataInputStream dis;        short lng;        try        {            /*             * Opens RecordStore. Remember that each openRecordStore must be matched             * with a closeRecordStore as well.             *             * Here openRecordStore is opened with the argument to create a new one             * if there is no existing one; thus, only if things are very bad the method             * will leave with a false.             */            store = RecordStore.openRecordStore("Language", true);            if (store == null)                return -1;            try            {                // As only one record is used, we set this to ID 1                data = store.getRecord(1);            }            catch (InvalidRecordIDException rse)            {                // If no record exists, a new one will be created next time the game                // calls GAGetLang                return -1;            }            if (data == null)            {                // If no data exists, return without changing gameData                return -1;            }            bis = new ByteArrayInputStream(data);            dis = new DataInputStream(bis);            lng = dis.readShort();            dis.close();            bis.close();            store.closeRecordStore();        }        catch (Exception exc)        {            return -1; // exc could be RecordStoreExc or IOExc        }        return lng;    }    /**     * Saves user language choice.     *     * @returns TRUE if succesfull     */    boolean SaveLang(short lng)    {        RecordStore store;        byte[] data;        ByteArrayOutputStream bos;        DataOutputStream dos;        try        {            /*             * Opens RecordStore. Remember that each openRecordStore must be matched             * with a closeRecordStore as well.             *             * Here openRecordStore is opened with the argument to create a new one             * if there is no existing one; thus, only if things are very bad the method             * will leave with a false.             */            store = RecordStore.openRecordStore("Language", true);            if (store == null)            {                return false;            }            bos = new ByteArrayOutputStream();            dos = new DataOutputStream(bos);            dos.writeShort(lng);            dos.flush();            bos.flush();            data = bos.toByteArray();            dos.close();            bos.close();            try            {                // Save data in current record                store.setRecord(1, data, 0, data.length);            }            catch (InvalidRecordIDException rse)            {                // Create record if it doesn't exist yet                store.addRecord(data, 0, data.length);            }            // Important to close the RecordStore            store.closeRecordStore();        }        catch (Exception exc)        {            exc.printStackTrace();            return false; // exc could be RecordStoreExc or IOExc        }        return true;    }}

⌨️ 快捷键说明

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