gamemidlet.java

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

JAVA
925 行
字号
                optionsMenu.append(str, null);                PLAYER_SIDE_BLACK = i++;            }             */            optionsMenu.addCommand(BACK_CMD);            optionsMenu.setCommandListener(this);        }        // LANGUAGE MENU        if ((mso.AllowOptions & GameShell.GAM_OPT_LANGUAGE) != 0)        {            languageMenu = new List(Lang.labels[lang][Lang.MENU_LANGUAGE_TXT], Choice.EXCLUSIVE);            for (i = 0; i<Lang.nrOfLangs; i++)                languageMenu.append(Lang.labels[i][Lang.LANGUAGE_NAME_TXT], null);            languageMenu.setSelectedIndex(lang, true);            // Outcommented since terminal adds OK command bu itself            // Reinserted because of OK_CMD functionality.            languageMenu.addCommand(OK_CMD);            languageMenu.addCommand(BACK_CMD);            languageMenu.setCommandListener(this);        }        // SOUND MENU        // Sounds not supported - outcommented        /*        if ((mso.AllowOptions & GameShell.GAM_OPT_SOUND) != 0)        {            soundMenu = new List(Lang.labels[lang][Lang.MENU_GAMES_SOUND_TXT], Choice.EXCLUSIVE);            i = 0;            soundMenu.append(Lang.labels[lang][Lang.MENU_GAMES_SOUNDON_TXT], null);            SOUNDON = i++;            soundMenu.append(Lang.labels[lang][Lang.MENU_GAMES_SOUNDOFF_TXT], null);            SOUNDOFF = i++;            if ((mso.SelOptions & GameShell.GAM_OPT_SOUND) == 0)                soundMenu.setSelectedIndex(SOUNDOFF, true);            else                soundMenu.setSelectedIndex(SOUNDON, true);            // Outcommented since terminal adds OK command bu itself            // soundMenu.addCommand(OK_CMD);            soundMenu.addCommand(BACK_CMD);            soundMenu.setCommandListener(this);        }		*/        // FORBIDDEN RULES MENU        if ((mso.AllowOptions & GameShell.GAM_OPT_FORBIDDEN_RULES) != 0)        {            forbiddenMenu = new List(Lang.labels[lang][Lang.MENU_GAMES_FORBIDDEN_RULES_TXT], Choice.EXCLUSIVE);            i = 0;            forbiddenMenu.append("On", null); // Lang.labels[lang][Lang.MENU_GAMES_ON_TXT], null);            FORBIDDENON = i++;            forbiddenMenu.append("Off", null); // Lang.labels[lang][Lang.MENU_GAMES_OFF_TXT], null);            FORBIDDENOFF = i++;            if ((mso.SelOptions & GameShell.GAM_OPT_FORBIDDEN_RULES) == 0)                forbiddenMenu.setSelectedIndex(FORBIDDENOFF, true);            else                forbiddenMenu.setSelectedIndex(FORBIDDENON, true);            // Outcommented since terminal adds OK command bu itself            forbiddenMenu.addCommand(OK_CMD);            forbiddenMenu.addCommand(BACK_CMD);            forbiddenMenu.setCommandListener(this);        }        // SELECT COLOR MENU        if ((mso.AllowOptions & GameShell.GAM_OPT_PLAYER_SIDE_BLACK) != 0 || (mso.AllowOptions & GameShell.GAM_OPT_PLAYER_SIDE_WHITE) != 0)        {            colorMenu = new List(Lang.labels[lang][Lang.MENU_GAMES_RENJU_SELECT_USER_SIDE_TXT], Choice.EXCLUSIVE);            i = 0;            colorMenu.append("Black", null); // Lang.labels[lang][Lang.MENU_GAMES_BLACK_TXT], null);            COLORBLACK = i++;            colorMenu.append("White", null); // Lang.labels[lang][Lang.MENU_GAMES_WHITE_TXT], null);            COLORWHITE = i++;            if ((mso.SelOptions & GameShell.GAM_OPT_PLAYER_SIDE_BLACK) != 0)                colorMenu.setSelectedIndex(COLORBLACK, true);            else if ((mso.SelOptions & GameShell.GAM_OPT_PLAYER_SIDE_WHITE) != 0)                colorMenu.setSelectedIndex(COLORWHITE, true);            // Outcommented since terminal adds OK command bu itself            colorMenu.addCommand(OK_CMD);            colorMenu.addCommand(BACK_CMD);            colorMenu.setCommandListener(this);        }        System.gc();    }    /**     * Locks commandAction input.     *     * @returns FALSE if locked, TRUE if locking was successful.     */    private static synchronized boolean lockCommandAction()    {        if (lock)            return false;        lock = true;        return true;    }    /**     * Unlocks commandAction input.     */    private static synchronized void unLockCommandAction()    {        // System.out.println("unlocking");        lock = false;    }    /**     * Handles incoming action.     *     * @param c The Command issued.     * @param s The Display that was active.     */    public synchronized void commandAction(Command c, Displayable s)    {        if (s instanceof TextBox)        {            TextBox tebo = (TextBox) s;            if (s == tb)            {                if (c == BACK_CMD)                {                    display.setCurrent(mainMenu);                }                else if (c == OK_CMD || c == List.SELECT_COMMAND)                {                    // Do not allow bogus birth dates                    if (tebo.getString().length() == 8 && tebo.getString().charAt(0) != '-' && lockCommandAction())                    {                        mso.birthDate.delete(0, mso.birthDate.length());                        mso.birthDate.append(tebo.getString());                        mso.SelStartMode = GameShell.GAM_START_SETBIRTHDATE;                        display.setCurrent(canvas);                        canvas.launchGame();                    }                }            }            else if (s == he)            {                // Use what the user entered or not                if (c == BACK_CMD || c == OK_CMD)                {                    mso.hsName.delete(0, mso.hsName.length());                    mso.hsName.append(tebo.getString());                    for (int i=mso.hsName.length()-1; i<GameShell.GAPI_HIGHSCORE_USE_NAME; i++)                        mso.hsName.append(' ');                    curEvent.type = GameShell.GAKeyboardEvent;                    display.setCurrent(canvas);                    canvas.gameMain(curEvent);                }            }        }        else if (s instanceof List)        {            List l = (List) s;            if (l == mainMenu)            {                if (c == List.SELECT_COMMAND)                {                    int idx = l.getSelectedIndex();                    if (idx == NEW_GAME )                    {                        mso.SelStartMode = GameShell.GAM_START_NEW;                        if (mso.AllowOpponents == GameShell.GAM_OPP_PHONE)                            display.setCurrent(difficultyMenu);                        else                            display.setCurrent(newGameMenu);                    }                    else if (idx == SET_BIRTH_DATE)                    {                        tb = new TextBox(Lang.labels[lang][Lang.MENU_GAMES_BR_SETBDATE_TXT], mso.birthDate.toString(), 8, TextField.NUMERIC);                        tb.addCommand(OK_CMD);                        tb.addCommand(BACK_CMD);                        tb.setCommandListener(this);                        display.setCurrent(tb);                    }                    else if (idx == OPTIONS)                    {                        display.setCurrent(optionsMenu);                    }                    else if (idx == HIGHSCORE)                    {                        curEvent.ClearHighScore = false;                        curEvent.ViewHighScore = true;                        curEvent.SendHighScore = false;                        curEvent.type = GameShell.GAHighScoreEvent;                        if ((mso.AllowHighScore & GameShell.GAM_HIGHSCORE_CLEAR) != 0 &&                            (mso.AllowHighScore & GameShell.GAM_HIGHSCORE_LIST_EMPTY) == 0)                                canvas.addCommand(HSCLEAR_CMD);                        /* THIS IS USED IF SEND HIGH SCORE FUNCTIONALITY IS ENABLED                        if ((mso.AllowHighScore & GameShell.GAM_HIGHSCORE_SEND) != 0 &&                            (mso.AllowHighScore & GameShell.GAM_HIGHSCORE_LIST_EMPTY) == 0)                                canvas.addCommand(HSSEND_CMD);                         */                        if (canvas.gameMain(curEvent))                            display.setCurrent(canvas);                        else                        {                            curEvent.type = GameShell.GATerminateEvent;                            canvas.gameMain(curEvent);                            doInitMenus();                            display.setCurrent(mainMenu);                        }                    }                    else if (idx == HELP)                    {                        display.setCurrent(canvas.getHelp(), mainMenu);                    }                    else if (idx == QUIT)                    {                        destroyApp(false);                        notifyDestroyed();                    }                    else if (idx == RESUME && lockCommandAction())                    {                        RESUME = -1; // Prevents future identifier conflict                        mso.SelStartMode = GameShell.GAM_START_RESUME;                        display.setCurrent(canvas);                        canvas.launchGame();                    }                }            }            else if (l == difficultyMenu && lockCommandAction())            {                if (c == List.SELECT_COMMAND)                {                    int idx = l.getSelectedIndex();                    if (idx == VERY_EASY)                    {                        mso.SelLevel = GameShell.GAM_LEVEL_VERYEASY;                    }                    else if (idx == EASY)                    {                        mso.SelLevel = GameShell.GAM_LEVEL_EASY;                    }                    else if (idx == MEDIUM)                    {                        mso.SelLevel = GameShell.GAM_LEVEL_MEDIUM;                    }                    else if (idx == HARD)                    {                        mso.SelLevel = GameShell.GAM_LEVEL_HARD;                    }                    else if (idx == VERY_HARD)                    {                        mso.SelLevel = GameShell.GAM_LEVEL_VERYHARD;                    }                    mso.SelStartMode = GameShell.GAM_START_NEW;                    display.setCurrent(canvas);                    canvas.launchGame();                }                else if (c == BACK_CMD)                {                    // will have to modify this, if nr of players menu is available.                    if (newGameMenu != null)                        display.setCurrent(newGameMenu);                    else                        display.setCurrent(mainMenu);                }            }            else if (l == optionsMenu)            {                if (c == List.SELECT_COMMAND)                {                    int idx = l.getSelectedIndex();                    if (idx == LANGUAGE)                    {                        display.setCurrent(languageMenu);                    }                    else if (idx == SOUND)                    {                        display.setCurrent(soundMenu);                    }                    else if (idx == FORBIDDEN)                    {                        display.setCurrent(forbiddenMenu);                    }                    else if (idx == COLOR)                    {                        display.setCurrent(colorMenu);                    }                }                else if (c == BACK_CMD)                {                    display.setCurrent(mainMenu);                }            }

⌨️ 快捷键说明

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