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

📄 gameshell.java

📁 J2ME的游戏原代码!希望能帮助有需要帮助的师兄弟们!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    static int HighscoreIconId; // This allows games to use different patterns.    static final int GAPI_HIGHSCORE_INPUT_STEP_BACKWARD1 = KeyLeft;    static final int GAPI_HIGHSCORE_INPUT_STEP_BACKWARD2 = KeyLeftUp;    static final int GAPI_HIGHSCORE_INPUT_STEP_FORWARD1 = KeyRight;    static final int GAPI_HIGHSCORE_INPUT_STEP_FORWARD2 = KeyRightDown;    /**     * Button used to step backward when inputing a name     *     */    static final int GAPI_HIGHSCORE_INPUT_CLEAR = KeyClear;    static final int GAPI_HIGHSCORE_INPUT_ACCEPT = KeyYes;    static final int GAPI_HIGHSCORE_INPUT_NOT_ACCEPT = KeyNo;    static final int GAPI_HSANIM_BACKGR = 5;    static final int GAPI_HSANIM_FOREGR = 0;    Image hsForegroundImage;    Image hsBackgroundImage;    static final int GAPI_HIGHSCORE_SHOW_CURSOR_SPEED = 1;    static final int GAPI_HIGHSCORE_SHOW_ANIM_STEP = 3;    /**     * Internal class for handling High Score saving structure.     */    class GAPI_HighscoreEntry_t implements GameSaveable    {        char[][] Name = new char[GAPI_HIGHSCORE_NUMBER_OF_ENTRYS][GAPI_HIGHSCORE_USE_NAME];        int[] Difficult = new int[GAPI_HIGHSCORE_NUMBER_OF_ENTRYS]; /*uint16*/        char[][] Score = new char[GAPI_HIGHSCORE_NUMBER_OF_ENTRYS][GAPI_HIGHSCORE_USE_SCORE];        boolean HighscoreListHasEntries;        public void serialize( DataOutputStream dos ) throws IOException        {            for (int i = 0; i < GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)                for (int j = 0; j < GAPI_HIGHSCORE_USE_NAME; j++)                    dos.writeChar(Name[i][j]);            for (int i = 0; i < GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)                dos.writeInt(Difficult[i]);            for (int i = 0; i < GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)                for (int j = 0; j < GAPI_HIGHSCORE_USE_SCORE; j++)                    dos.writeChar(Score[i][j]);            dos.writeBoolean(HighscoreListHasEntries);        }        public void unSerialize( DataInputStream dis ) throws IOException        {            for (int i = 0; i < GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)                for (int j = 0; j < GAPI_HIGHSCORE_USE_NAME; j++)                    Name[i][j] = dis.readChar();            for (int i = 0; i < GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)                Difficult[i] = dis.readInt();            for (int i = 0; i < GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)                for (int j = 0; j < GAPI_HIGHSCORE_USE_SCORE; j++)                    Score[i][j] = dis.readChar();            HighscoreListHasEntries = dis.readBoolean();        }    }    /**     * Internal class for handling High Score variables.     */    class GAPI_HighscoreList_t    {        int CurrentTopLine; /*uint8*/        int CursorLine; /*sint16*/        int CursorPosition; /*sint16*/        int CursorBlinkRate; /*sint16*/        char CursorChar;        boolean CursorBlink;        int AnimationRate; /*sint16*/        int AnimationCnt; /*sint16*/        int AnimationX; /*sint16*/        int CursorX; /*sint16*/        int CursorY; /*sint16*/        byte MenuState; /*uint8*/        boolean ShowName;        boolean ShowDifficult;        boolean ShowScore;        boolean ShowMenu;        boolean ShowPlace;        int ShowNrOfEntries; /*uint8*/        boolean DifficultType;    }    /**     * This method assume that Score in the highscore list is a number, this number is checked against Score     * If Score is higher than in the highscore list then it is inserted in the list and if entries is switched     * on then the highscore list is prepared for name input.     *     * @param highList The highscore list. C: was GAPI_HighscoreList_t *     * @param highEntry The entries coming from EEPROM. C: was GAPI_HighscoreEntry_t *     * @param score the Score to compare the highscore list entries. was uint32 = typedef unsigned long!.     * @param difficulty The difficulty level. was uint16.     *     * @return TRUE if the score have been added to the highscore list     */    boolean GAHighScoreAddNum(GAPI_HighscoreList_t HighList, GAPI_HighscoreEntry_t Entries, int Score, int Difficulty)    {        int i, k, StoredScore, factor;        int Hit = -1;        for (i = 0; i < GAPI_HIGHSCORE_NUMBER_OF_ENTRYS && Hit == -1; i++)        {            StoredScore = 0;            factor = 1;            // Convert stored score characters to ingteger value            for (k = GAPI_HIGHSCORE_USE_SCORE - 1; k >= 0; k--)            {                StoredScore += factor * (int)(Entries.Score[i][k] - '0');                factor *= 10;            }            // System.out.println("---> SCORE = " + Score + " STOREDSCORE = " + StoredScore);            // Check if user score is better than old record            if (Score > StoredScore)            {                Hit = i;                // Register that a highscore has been added to the list                Entries.HighscoreListHasEntries = true;            }        }        // Move old values to make room for the new one        if (Hit >= 0)        {            for (k = (GAPI_HIGHSCORE_NUMBER_OF_ENTRYS - 1); k > Hit; k--)            {                for (i = 0; i < GAPI_HIGHSCORE_USE_SCORE; i++)                    Entries.Score[k][i] = Entries.Score[k - 1][i];                for (i = 0; i < GAPI_HIGHSCORE_USE_NAME; i++)                    Entries.Name[k][i] = Entries.Name[k - 1][i];                Entries.Difficult[k] = Entries.Difficult[k - 1];            }            // Add new entry with name unset            GAHighScoreSetScore(Entries, Hit, Score);            Entries.Difficult[Hit] = Difficulty;            for (i = 0; i < GAPI_HIGHSCORE_USE_NAME; i++)                Entries.Name[Hit][i] = GAPI_HIGHSCORE_UNSET_CHAR;            // Set variables for indicating new user name input            HighList.CursorLine = Hit;            HighList.CursorPosition = 0;            HighList.MenuState = InputHighscoreEntry;            return true;        }        else        {            HighList.MenuState = DoneHighScoreList;            return false;        }    }    /**     * This method initilize a highscore list.     * This method should be called first of all.     * <p>     * <i>Dummy method. This means it does nothing yet, or is at best partially implemented.</i>     *     * @param highList The highscore list. C: was GAPI_HighscoreList_t *     * @param highEntry The entries coming from EEPROM. C: was GAPI_HighscoreEntry_t *     */    void GAHighScoreListInit(GAPI_HighscoreList_t HighList, GAPI_HighscoreEntry_t Entries)    {        int i, t;        HighList.ShowName = false;        HighList.ShowDifficult = false;        HighList.ShowScore = false;        HighList.ShowMenu = true;        HighList.ShowPlace = true;        HighList.ShowNrOfEntries = GAPI_HIGHSCORE_NUMBER_OF_ENTRYS;        HighList.CursorLine = -1;        HighList.CurrentTopLine = 0;        HighList.CursorPosition = 0;        HighList.CursorBlinkRate = 1;        HighList.CursorChar = 'A';        HighList.MenuState = DoneHighScoreList;        //HighList.AnimationX = (DISPLAY_WIDTH - GAPI_high_back_width) / 2;        //HighList.AnimationCnt = 0;        for (i = 0; i < GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)        {            GAHighScoreSetScore(Entries, i, 0);            HighList.ShowScore = true;            Entries.Difficult[i] = '-';            HighList.ShowDifficult = true;            HighList.DifficultType = true;            for (t = 0; t < GAPI_HIGHSCORE_USE_NAME; t++)            {                Entries.Name[i][t] = GAPI_HIGHSCORE_UNSET_CHAR;            }            HighList.ShowName = true;        }    }    /**     * This method re-initilize a highscore list     * (clears all previous entries)     *     * @param highList The highscore list. C: was GAPI_HighscoreList_t *     * @param highEntry The entries coming from EEPROM. C: was GAPI_HighscoreEntry_t *     *     */    void GAHighScoreListClear(GAPI_HighscoreList_t HighList, GAPI_HighscoreEntry_t Entries)    {        int i, t;        for (i = 0; i < GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)        {            GAHighScoreSetScore(Entries, i, 0);            Entries.Difficult[i] = GAPI_HIGHSCORE_UNINIT_DIFF;            for (t = 0; t < GAPI_HIGHSCORE_USE_NAME; t++)                Entries.Name[i][t] = GAPI_HIGHSCORE_UNSET_CHAR;        }        // Now the highscore list is empty again        Entries.HighscoreListHasEntries = false;    }    /**     * This method setup a highscore list     * This method is usually called after a game have retrieved informtaion from the EEPROM     *     * @param highList The highscore list. C: was GAPI_HighscoreList_t *     * @param highEntry The entries coming from EEPROM. C: was GAPI_HighscoreEntry_t *     */    void GAHighScoreEntryCheck(GAPI_HighscoreList_t HighList, GAPI_HighscoreEntry_t Entries)    {        int i;        int t;        boolean UnInit = false;        for (i = 0; i < GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)        {            if (Entries.Score[i][0] < ' ')            {                UnInit = true;            }            if (HighList.DifficultType)            {                switch (Entries.Difficult[i])                {                case GAM_LEVEL_VERYEASY:                case GAM_LEVEL_EASY:                case GAM_LEVEL_MEDIUM:                case GAM_LEVEL_HARD:                case GAM_LEVEL_VERYHARD:                    // Entries.Difficult[i] = Entries.Difficult[i];                    break;                default:                    UnInit = true;                }            }            if ((Entries.Name[i][0] < ' ') || (Entries.Name[i][0] > 'Z'))                UnInit = true;            if (UnInit)            {                GAHighScoreSetScore(Entries, i, 0);                for (t = 0; t < GAPI_HIGHSCORE_USE_NAME; t++)                    Entries.Name[i][t] = GAPI_HIGHSCORE_UNSET_CHAR;                if (HighList.DifficultType)                    Entries.Difficult[i] = GAPI_HIGHSCORE_UNINIT_DIFF;                else                    Entries.Difficult[i] = GAPI_HIGHSCORE_UNINIT_DIFF;            }        }    }    /**     * This method sets the flags for the highscore menu options, which are used to     * determine which options are available, visible, shaded etc.     * If highscore isn't enabled, then all flags will default to zero     * using GAM_HIGHSCORE_NONE and no call to this method will be made.     *     * @param    HighScoreListEntries   Pointer to highscore list entries in memory. was pointer.     * @returns                         The byte containing the flags. was uint8.     */    int GAHighScoreCheckMenues(GAPI_HighscoreEntry_t HighScoreListEntries)    {        int Flags = 0;        /*  The flags:        #define GAM_HIGHSCORE_NONE        0        #define GAM_HIGHSCORE_VIEW        1        #define GAM_HIGHSCORE_CLEAR       2        #define GAM_HIGHSCORE_SEND        4        #define GAM_HIGHSCORE_LIST_EMPTY  8        #define GAM_HIGHSCORE_ALL       255        */        // This flag should always be set if there is a highscore list        Flags |= GAM_HIGHSCORE_VIEW;        // This flag is always set        // NOTE: The menu option is disabled by SET_VISIBLE if sending is not supported by the MS        Flags |= GAM_HIGHSCORE_SEND;        Flags |= GAM_HIGHSCORE_CLEAR;        if (!(HighScoreListEntries.HighscoreListHasEntries))        {            Flags |= GAM_HIGHSCORE_LIST_EMPTY; // If this is set, then the list is empty        }        return Flags;    }    /**     * This method shows a highscore list     *     * @param HighList The highscore list     * @param HighEntry The entries coming from EEPROM.     *     */    synchronized void GAHighScoreListShow(GAPI_HighscoreList_t HighList, GAPI_HighscoreEntry_t Entries)    {        int x, y, MenuTextY;        int Cnt = 0;        StringBuffer Str = new StringBuffer(20);        int cfw = GAGetCurrfontWidth();        try        {            // GAImageProgress(0);            hsForegroundImage = Image.createImage("/highscore/Image_8bit_" + Integer.toString(GAPI_HSANIM_FOREGR) + ".png");            // GAImageProgress(3);            hsBackgroundImage = Image.createImage("/highscore/Image_8bit_" + Integer.toString(GAPI_HSANIM_BACKGR) + ".png");            // GAImageProgress(6);        }        catch (IOException exc)        {            System.err.println("GameShell: Could not load High Score back- and foreground images.");            exc.printStackTrace();        }        y = 0;        MenuTextY = DISPLAY_HEIGHT - GAGetCurrfontHeight() - TextPack;        g.setColor(GACOLOR_WHITE);        g.fillRect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);        g.setColor(GACOLOR_BLACK);        // Used to be GAHighSplashAnim        y = hsForegroundImage.getHeight()+HSTMargin;        // HighList.MenuState = DoneHighScoreList;        if (HighList.ShowNrOfEntries > GAPI_HIGHSCORE_NUMBER_OF_ENTRYS)            HighList.ShowNrOfEntries = GAPI_HIGHSCORE_NUMBER_OF_ENTRYS;        Cnt = HighList.CurrentTopLine;        // Fix centering of High Score list        short HSLMargin = 0;        if (HighList.ShowPlace)            HSLMargin += (GAPI_HIGHSCORE_NUMBER_OF_ENTRYS/10+1)*cfw+SpaceW;        if (HighList.ShowName)            HSLMargin += GAPI_HIGHSCORE_USE_NAME*cfw+SpaceW;        if (HighList.ShowDifficult)            HSLMargin += DiffWidth*cfw+SpaceW;        if (HighList.ShowScore)            HSLMargin += GAPI_HIGHSCORE_USE_SCORE*cfw+SpaceW;        HSLMargin -= SpaceW;        HSLMargin = (sh

⌨️ 快捷键说明

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