⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gameshell.java

📁 J2ME的游戏原代码!希望能帮助有需要帮助的师兄弟们!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            case GATimer2:                timerThread.period[GATimer2] = millis;                break;            case GATimer3:                timerThread.period[GATimer3] = millis;                break;            case GATimerAll:                timerThread.notQuit = false;                timerThread.period[GATimer1] = millis;                timerThread.period[GATimer2] = millis;                timerThread.period[GATimer3] = millis;                break;        }    }    /**     * Returns a pseudo-random number in the interval [0, GA_RAND_MAX].     *     * @returns The pseudo-random number. In C, this was uint16.     *     * @see GASeed     * @see GA_RAND_MAX     *     */    int GARand()    {        int tmp = randomGenerator.nextInt();        if ( tmp >= 0 )            return tmp;        else            return -tmp;    } // GARand    /**     * This method seeds the random number generator.     *     * A seed of zero means that the generator is seeded with the clock.     * This is automatically done when GameShell is instantiated.     *     * @param seed Sets the random seed. In C, this was uint32.     *     * @see GARand     *     */    void GASeed(long seed)    {        if (seed == 0)        {            randomGenerator.setSeed(System.currentTimeMillis());        }        else        {            randomGenerator.setSeed(seed);        }    } // GASeed    /**     * Loads data from a persistent storage (a RecordStore).     * <p>     * Calling GALoadNVData without ever having called GASaveNVData does nothing. This is     * because the record for the game is created in GASaveNVData if needed.     * <p>     * It is assumed that if nothing exists to load, a newly instantiated GameSaveable     * will be such that the games will behave as if they were running for the very     * first time on a new phone. Thus the GameSaveable is left untouched if there is     * nothing to load.     *     * @param gameData The buffer where the data will be placed. In C, this was unsigned char     *          This area shall already be allocated when calling this method     *     * @returns TRUE if succesfull, that is the menu id exist.     *     * @see GAGameID     * @see GASaveNVData     */    boolean GALoadNVData(GameSaveable gameData)    {        RecordStore store;        byte[] data;        ByteArrayInputStream bis;        DataInputStream dis;        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(getGameName(), true);            if (store == null)                return false;            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 GASaveNVData                return false;            }            if (data == null)            {                // If no data exists, return without changing gameData                return false;            }            bis = new ByteArrayInputStream(data);            dis = new DataInputStream(bis);            gameData.unSerialize(dis);            dis.close();            bis.close();            store.closeRecordStore();        }        catch (Exception exc)        {            return false; // exc could be RecordStoreExc or IOExc        }        return true;    }    /**     * Saves the data in a persistent storage.     *     * @returns TRUE if succesfull     *     * @see GAGameID     * @see GALoadNVData     *     */    boolean GASaveNVData(GameSaveable gameData)    {        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(getGameName(), true);            if (store == null)            {                return false;            }            bos = new ByteArrayOutputStream();            dos = new DataOutputStream(bos);            gameData.serialize(dos);            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;    }    /**     * Returns an object containing the menu settings with fields that control which     * menus should be displayed as well as which menus have been selected.     *     * @param gameID <i>Obsolete</i>. Was typedef unsigned int MenuItemId_t     */    GAMenuSelectObject_t GAGetMenuSetting()    {        return mso;    }    /**     * Get the current date. Not Y10k safe.     *     * @param currentDate A pointer to string in where the date will be placed,     *    the date is on the form YYYY:MM:DD     *     * @returns TRUE if everything went OK     *     If it went wrong the parameter CurrentDate is set to 2000:01:01     *     *     */    boolean GAGetCurrentDate(StringBuffer currentDate)    {        Calendar rightNow = Calendar.getInstance();        int year = rightNow.get(Calendar.YEAR);        int month = 0;        int day = rightNow.get(Calendar.DATE);        // In order to convert from Calendar internal encoding        switch (rightNow.get(Calendar.MONTH))        {            case (Calendar.JANUARY):                month = 1;                break;            case (Calendar.FEBRUARY):                month = 2;                break;            case (Calendar.MARCH):                month = 3;                break;            case (Calendar.APRIL):                month = 4;                break;            case (Calendar.MAY):                month = 5;                break;            case (Calendar.JUNE):                month = 6;                break;            case (Calendar.JULY):                month = 7;                break;            case (Calendar.AUGUST):                month = 8;                break;            case (Calendar.SEPTEMBER):                month = 9;                break;            case (Calendar.OCTOBER):                month = 10;                break;            case (Calendar.NOVEMBER):                month = 11;                break;            case (Calendar.DECEMBER):                month = 12;                break;            default:                break;        }        currentDate.delete(0, currentDate.length());        currentDate.append(Integer.toString(year));        if (month < 10)            currentDate.append("0");        currentDate.append(Integer.toString(month));        if (day < 10)            currentDate.append("0");        currentDate.append(Integer.toString(day));        return true;    }    /*     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     Gapisound     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     */    /**     * Create a single tone in the speaker. Sound is not available in MIDP 1.0.     * <p>     * <i>Dummy method. This means it does nothing yet, or is at best partially implemented.</i>     *     * @param Freq The frequence of the tone. It is a discrete scale     *       from G, A, H, C, D, E, F with half tones up and down     *       this is from 396 Hz up to 1991 Hz. All params were uint16 in C.     * @param Duration The time in milliseconds, in span 100 -> 1000 in steps of 100     * @param Pitch The level of the tone, valid values are 0 -> 10. If this is 0     *           then use the predefined setting used by the user. 10 is reserved do not use it.     *     *     */    void GASound(int Freq, int Duration, int Pitch){}    /**     * This method will play a predefined sound effect. Sound is not available in MIDP 1.0.     * <p>     * <i>Dummy method. This means it does nothing yet, or is at best partially implemented.</i>     *     * @param soundEffect the sound effect to play     *		The method will search for files with the name 'game_SoundEffect'. This was const char * in C.     *     * @returns TRUE if the requested sound will be played     *     */    boolean GASoundEffectPlay(String soundEffect)    {        return true;    }    /*     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     Gapisfx     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     */    /**     * Getting the image id from a file name placed in the games directory     * <p>     * <i>Probably not implementable in MIDP. (obsolete)</i>     *     * @param menuId The menu id of the game. <i>Obsolete</i>. (Was MenuItemId_t in c: typedef unsigned int MenuItemId_t)     * @param filename The filename for the operational (was const char *)     *     * @returns 0 if something went wrong, for example the file does not exist     * Otherwise the return value is the image edit used by GACharOut. was uint16.     *     * @see GAfopen     */    int GAGetImageId(String fileName)    {        return 0;    }    /*     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     Gapihighscore     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     */    // This is from the enum GAPI_HighscoreMenuState_e    static final byte ViewHighscoreEntry = 0;    static final byte InputHighscoreEntry = 1;    static final byte DoneHighScoreList = 2;    static final byte ClearHighScoreList = 3;    static final byte SendHighScoreList = 4;    static final int GAPI_HIGHSCORE_NUMBER_OF_ENTRYS = 5;    static final int GAPI_HIGHSCORE_USE_SCORE = 7;    static final int GAPI_HIGHSCORE_USE_NAME = 3;    static final char GAPI_HIGHSCORE_UNSET_CHAR = '?';    //static final int GAPI_high_back_width = 101;    //static final int GAPI_high_back_height = 16;    //static final int GAPI_high_highmask_width = 101;    //static final int GAPI_high_highmask_height = 16;    //static final int GAPI_high_highorig_width = 101;    //static final int GAPI_high_highorig_height = 16;    static final int GAMES_HIGHSCORE_ICON_ID = 256; // Unicode of first icon    static final int GAMES_HIGHSCORE_ICON_COUNT = 19; // The number of different icons    static final int GAPI_HIGHSCORE_UNINIT_DIFF = 65000;

⌨️ 快捷键说明

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