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

📄 gameshell.java

📁 J2ME的游戏原代码!希望能帮助有需要帮助的师兄弟们!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        if (w7 > w)            w = w7;        int h = g.getFont().getHeight() + 10;        int x = (DISPLAY_WIDTH - w) / 2;        int y = (DISPLAY_HEIGHT - h) / 2;        g.setColor(GACOLOR_BLACK);        g.fillRect(x + 2, y + 2, w, h*3);        g.setColor(GACOLOR_WHITE);        g.fillRect(x, y, w, h*3);        g.setColor(GACOLOR_BLACK);        g.drawRect(x, y, w, h*3);        g.drawString(RowId3, x + 5, y + 5, ALIGN_TOP_LEFT);        g.drawString(RowId5, x + 5, y + 5 + h, ALIGN_TOP_LEFT);        g.drawString(RowId7, x + 5, y + 5 + 2*h, ALIGN_TOP_LEFT);        repaint();    } // GAInfoBox    /**     * Progress bar for loading images.     *     * @param progress Value between 0 and 6.     */    void GAImageProgress(int progress)    {		//OutCommented! Progress bar isn't needed, loading of images are done at startup.        /*else        if (progress > 6 || progress <0)        {            System.err.println("Image loading progres must have a value between 0 and 6.");            System.err.println("Now it was: " + progress);            return;        }        {            g.setColor(GACOLOR_DARK_GRAY);            g.drawRect(PBSMargin+1, PBTMargin+1, DISPLAY_WIDTH-2*PBSMargin, DISPLAY_HEIGHT-2*PBTMargin);            g.setColor(GACOLOR_BLACK);            g.drawRect(PBSMargin, PBTMargin, DISPLAY_WIDTH-2*PBSMargin, DISPLAY_HEIGHT-2*PBTMargin);            g.setColor(GACOLOR_WHITE);            g.fillRect(PBSMargin+1, PBTMargin+1, DISPLAY_WIDTH-2*(PBSMargin+1), DISPLAY_HEIGHT-2*(PBTMargin+1));            g.setColor(GACOLOR_BLACK);            g.fillRect(PBSMargin+PBBMargin,                       (DISPLAY_HEIGHT-PBHeight)/2,                       DISPLAY_WIDTH-2*(PBSMargin+PBBMargin),                       PBHeight);            g.setColor(GACOLOR_GRAY);            g.fillRect(PBSMargin+PBBMargin+PBFMargin,                       (DISPLAY_HEIGHT-PBHeight)/2+PBFMargin,                       (progress*(DISPLAY_WIDTH-2*(PBSMargin+PBBMargin+PBFMargin)))/6,                       PBHeight-2*PBFMargin);            repaint();        }*/    }    /**     * Show a message box, like a splash box     * This message box shows any internal textlabel in a message box.     * <p>     * <i>This is only partially implemented. Does not print the</i>     * <i>text label specified by msg, but instead prints "Message"</i>     *     * @param Msg The text id to be shown. C: was typedef uint32 TextId.     */    synchronized void GAMsgBox(int msg)    {        GAMsgBox(Integer.toString(msg));    }    synchronized void GAMsgBox(String msg)    {        int w, h, curr, next;        int rows = 1;        int maxrows = (DISPLAY_HEIGHT-10)/g.getFont().getHeight();        // If msg does not fit into one line it has to be wrapped.        // First, check for the height needed for the box.        if (g.getFont().stringWidth(msg)+10 > DISPLAY_WIDTH)        {            w = 0;            curr = 0;            next = msg.indexOf(' ');            while (rows < maxrows)            {                if (g.getFont().stringWidth(msg.substring(curr, next))+10 > DISPLAY_WIDTH)                {                    rows++;                    if (g.getFont().stringWidth(msg.substring(curr, msg.lastIndexOf(' ', next-1))) > w)                        w = g.getFont().stringWidth(msg.substring(curr, msg.lastIndexOf(' ', next-1)));                    curr = msg.lastIndexOf(' ', next-1)+1;                    next = curr;                }                if (next == msg.length())                    break;                else                {                    next = msg.indexOf(' ', next+1);                    if (next == -1)                        next = msg.length();                }            }            w += 10;        }        else        {            w = g.getFont().stringWidth(msg)+10;        }        h = rows*g.getFont().getHeight()+10;        // Draw the box        g.setColor(GACOLOR_DARK_GRAY);        g.fillRect((DISPLAY_WIDTH-w)/2+1, (DISPLAY_HEIGHT-h)/2+1, w+2, h+2);        g.setColor(GACOLOR_BLACK);        g.fillRect((DISPLAY_WIDTH-w)/2, (DISPLAY_HEIGHT-h)/2, w+2, h+2);        g.setColor(GACOLOR_WHITE);        g.fillRect((DISPLAY_WIDTH-w)/2+1, (DISPLAY_HEIGHT-h)/2+1, w, h);        // Draw text in box        g.setColor(GACOLOR_BLACK);        if (rows == 1)            g.drawString(msg, (DISPLAY_WIDTH-w)/2+5, (DISPLAY_HEIGHT-h)/2+5, ALIGN_TOP_LEFT);        else        {            short i = 0;            curr = 0;            next = msg.indexOf(' ');            for (;;)            {                if (g.getFont().stringWidth(msg.substring(curr, next))+10 > DISPLAY_WIDTH)                {                    g.drawString(msg.substring(curr, msg.lastIndexOf(' ', next-1)), (DISPLAY_WIDTH-w)/2+5, (DISPLAY_HEIGHT-h)/2+5+i*g.getFont().getHeight(), ALIGN_TOP_LEFT);                    curr = msg.lastIndexOf(' ', next-1)+1;                    next = curr;                    i++;                }                if (next == msg.length())                    break;                else                {                    next = msg.indexOf(' ', next+1);                    if (next == -1)                        next = msg.length();                }            }            g.drawString(msg.substring(curr, msg.length()), (DISPLAY_WIDTH-w)/2+5, (DISPLAY_HEIGHT-h)/2+5+i*g.getFont().getHeight(), ALIGN_TOP_LEFT);        }        repaint();    }    /**     * Prints a textlabel on the screen     *     * <p>     * <i>This is only partially implemented. Does not print the</i>     * <i>text label specified by msg, but instead prints "TextLabel"</i>     *     * @param msg The text id to be shown     * @param alignment The alignment of the text     * @param x The upper left corner of the area     * @param y The upper left corner of the area     *     * @returns None     */    void GAPrintTextLabel(int msg, byte alignment, int x, int y)    {        switch (alignment)        {        case alignCenter:            x = (x + DISPLAY_WIDTH) / 2;            g.drawString("TextLabel", x, y, Graphics.TOP | Graphics.HCENTER);            break;        }    }    // enum TextAlignment    public static final byte alignCenter = 0;    /**     * This is the maximum number that can be returned by GARand.     *     * @see GARand     * @see GASeed     *     */    protected static final int GA_RAND_MAX = Integer.MAX_VALUE;    /**     * Emulate a simple sprintf(s, "Level %019ld", tt);     * <p>     * If Text is null, chString remains unchanged.     * <p>     * <i> Dummy. Just returns input string. </i>     *     * @param chString the space where the result shall be placed. In C, this was char *chString.     * @param Text The formatting text. In C, this was const char *Text.     * @param lNr The number to be converted. In C, this was sint32 lNr.     *     * @returns The number of converted parameters     *     */    int GAsprintf(StringBuffer chString, String Text, int lNr)    {        if (Text == null || chString == null)            return 0;        //System.out.println("GASprintf: the number to format is "+lNr);        int i;        int t;        int o;        int p;        int State;        int ChL;        int tl1;        int tl2;        char ChFill;        char CurrCh;        StringBuffer s = new StringBuffer();        //        // sprint(s, "Level %019d", tt);        //        chString.delete(0, chString.length());        ChFill = '\0';        t = Text.length();        //System.out.println("t = "+t);        ChL = 0;        State = 0;        for (i = 0; i < t; i++)        {            CurrCh = Text.charAt(i);            if (CurrCh == '%')                State = 1;            switch (State)            {                case 0:                    chString.append(CurrCh);                    break;                case 1:     // Skip the %                    State = 2;                    break;                case 2:     // Fill character                    State = 3;                    if (CurrCh == '0')                    {                        ChFill = '0';                        break;                    }                case 3:     // Check the rest                    if (CurrCh == 'i')                    {                        State = 5; // Ok, the %xxx is analysed                    }                    else if (CurrCh == 'd')                    {                        State = 5; // Ok, the %xxx is analysed                    }                    else if (CurrCh == 'l')                    {                        State = 3; // Just skip it, this method uses sint32 in its method                    }                    else if ((CurrCh >= '0') && (CurrCh <= '9'))                    {                        if (ChFill != '0') // this part take care of the 'width' in %5d experssion                        {                            ChFill = ' ';                        }                        ChL = 10 * ChL;                        ChL = ChL + ((int)CurrCh - (int)'0');                    }                    break;            } // switch (State)            if (State == 5)            {                // Fix the number, we now know the width and the fill character.                if (lNr < 0)                {                    ChL--; // Since minus sign will occupy one character                    tl2 = -lNr;                }                else                {                    tl2 = lNr;                }                //                // Create the string backwards                //                if (tl2 > 0)                {                    while (tl2 > 0)                    {                        tl1 = tl2 % 10; // Do modulo and create the string "backwards"                        //         ts = (sint16) (tl1 + 48);                        s.insert(0, (char) (tl1 + 48));                        tl2 = tl2 / 10;                    }                }                p = ChL - s.length();                if (ChFill != '\0')                {                    if ((ChFill == '0') && (lNr < 0))                    {                        chString.append('-'); // Add the minus sign                    }                    for (o = 0; o < p; o++) // Add the fill character.                    {                        chString.append(ChFill);                    }                    if ((ChFill == ' ') && (lNr < 0))                    {                        chString.append('-'); // Add the minus sign                    }                }                else                {                    if (lNr < 0)                    {                        chString.append('-'); // Add the minus sign                    }                }                chString.append(s);                State = 0; // Continue to add charachers, if any            } // if (State == 5)        } // for(i = 0; i < t; i++)        return 1;    } //GASprintf(..., String, ...)    /**     * This method start a timer to generate periodic event     *     * @param timerId The id of the timer. This was enum GATimerId in C.     * @param millis This was uint16 in C.     *     * @returns TRUE if successfull.     */    void GASetTimer(byte id, long millis)    {        //System.out.println("GameShell.GASetTimer("+timerId+", "+millis+")");        if (id < 3)        {            timerThread.period[id] = millis;            timerThread.periodUpdated[id] = true;        }        /*else        {            for (int i = 0; i < 3; i++)            {                timerThread.period = millis;                timerThread.periodUpdated = true;            }        }*/        //System.out.println("   RETURNING");    }    /**     * This method stops a timer to generate events     *     * @param timerId The id of the timer. This was enum GATimerId in C.     *     * @returns TRUE if successfull.     */    void GAKillTimer(int timerId)    {        //System.out.println("GameShell.GAKillTimer("+timerId+")");        long millis = Long.MAX_VALUE;        switch (timerId)        {            case GATimer1:                timerThread.period[GATimer1] = millis;                break;

⌨️ 快捷键说明

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