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

📄 gameshell.java

📁 J2ME的游戏原代码!希望能帮助有需要帮助的师兄弟们!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    public byte[] keyArray = new byte[8];    int keyPos = -1;    // public boolean[] keyPressedArray = new boolean[8];    /**     * Nothing happens when keys are pressed; we'return only interested in     * what choice the user has made when releasing a button.     *     * @param keyCode   Code for the pressed key.     */    protected void keyPressed(int keyCode)    {    }    /**     * Get the command from the user and send it to the gameMain.     *     * @param keyCode   Code for the released key.     */    protected void keyReleased(int keyCode)    {        // System.err.println("Fick tangentslag!!");        GAEvent curEvent = new GAEvent();        curEvent.type = GameShell.GAKeyboardEvent;        // curEvent.press = true;        switch (keyCode)        {            case Canvas.KEY_NUM0:                curEvent.key = KeyZero;                break;            case Canvas.KEY_NUM1:                curEvent.key = KeyOne;                break;            case Canvas.KEY_NUM2:                curEvent.key = KeyTwo;                break;            case Canvas.KEY_NUM3:                curEvent.key = KeyThree;                break;            case Canvas.KEY_NUM4:                curEvent.key = KeyFour;                break;            case Canvas.KEY_NUM5:                curEvent.key = KeyFive;                break;            case Canvas.KEY_NUM6:                curEvent.key = KeySix;                break;            case Canvas.KEY_NUM7:                curEvent.key = KeySeven;                break;            case Canvas.KEY_NUM8:                curEvent.key = KeyEight;                break;            case Canvas.KEY_NUM9:                curEvent.key = KeyNine;                break;            case Canvas.KEY_STAR:                curEvent.key = KeyStar;                break;            case Canvas.KEY_POUND:                curEvent.key = KeyHash;                break;            default:                switch (getGameAction(keyCode))                {                    case Canvas.UP:                        curEvent.key = KeyUp;                        break;                    case Canvas.DOWN:                        curEvent.key = KeyDown;                        break;                    case Canvas.LEFT:                        curEvent.key = KeyLeft;                        break;                    case Canvas.RIGHT:                        curEvent.key = KeyRight;                        break;                    case Canvas.FIRE:                        curEvent.key = KeyYes;                        break;                    default:                        curEvent.key = Byte.MIN_VALUE;                        break;                }                break;        }        if (!(gameMain(curEvent)))        {            timerThread.notQuit = false;            System.gc();        }    }    /**     * When the command BACK is detected by GameMIDlet, this method should     * be called to send a KeyNo to the game.     */    protected void handleBackCommand()    {        GAEvent curEvent = new GAEvent();        curEvent.type = GameShell.GAKeyboardEvent;        curEvent.key = KeyNo;        if (!(gameMain(curEvent)))            timerThread.notQuit = false;    }    /**     * When the command OK is detected by GameMIDlet, this method should     * be called to send a KeyYes to the game.     */    protected void handleOkCommand()    {        GAEvent curEvent = new GAEvent();        curEvent.type = GameShell.GAKeyboardEvent;        curEvent.key = KeyYes;        if (!(gameMain(curEvent)))            timerThread.notQuit = false;    }    /**     * The main event handler. Since GameShell is only an empty shell, and not     * an actual game, this is abstract and must be implemented in a subclass of     * GameShell. Some events (key press events) are created by the GameShell,     * and some, like timer and menu events, are generated by the GameMIDlet object.     * <p>     * This could be made protected if it turns out that all events can be generated     * from within this class. Probably they cannot - game start, end couldn't     * be generated from here.     * <p>     * This means the converted game's main method, whatever it might     * have been called in the C code, must be renamed gameMain.     */    public abstract boolean gameMain(GAEvent event);    /**     * Loads the images for this game. This is abstract, since GameShell does not know     * the names of the images in the resource file, nor the variables to store them in.     * Whoever creates an instance of a subclass of GameShell is responsible for calling     * loadImages on it before sending the first GAEvent.     *     * @param s Interval (0-6) to load; needed due to the progress bar.     * @returns true if all images were read successfully, false otherwise.     */    abstract boolean loadImages(short s);    public void startThread()    {        timerThread.setMIDlet(midlet);        timerThread.start();    }    public abstract String getGameName();    public abstract Alert getHelp();    static final byte GAMenuDataBirthdate = 0;    static final byte GAMenuDataBackgroundPic = 1;    static final byte GAMenuDataForegroundPic = 2;    static final byte GAMenuDataPhoneNumber = 3;    static final byte GAMenuDataLast = 4;    /**     * This method sets the menu data number 1, this is special data retrieved     * during the menus and can be fetched by the games.     *     * @param Type Which data is to consider     * @param d The data     * @param l The length of the data     *     * @returns TRUE if everything went OK     */    boolean Game_SetMenuData(byte type, StringBuffer d, short l)    {        mso.birthDate.delete(0, mso.birthDate.length());        mso.birthDate.append(d);        return true;    }    /**     * This method get the menu data number 1, this is special data retrieved     * during the menus.     *     * @param Type Which data is to consider     * @param l l[0] is set to the length of the data.     *     * @returns A pointer to the menu data     *     */    String Game_GetMenuData(byte Type, short[] l)    {        l[0] = 10;        return mso.birthDate.toString();    }    /**     * Creates a color in 0x00RRGGBB format from the three supplied ints.     *     * @param r Red component. Must be in the interval 0x00 ... 0xFF.     * @param g Green component. Must be in the interval 0x00 ... 0xFF.     * @param b Blue component. Must be in the interval 0x00 ... 0xFF.     *     * @returns A color in 0x00RRGGBB format. If the input     *          ints are not in the specified range, the return value is not specified.     */    protected static int RGB(int r, int g, int b)    {        return ( r << 16 | g << 8 | b );    }    /**     * Sets the color used for outlined drawing operations, lines and pixels.     *     * @param c a color in 0x00RRGGBB format. In C, this was a uint32.     * <i>Dummy method. This means it does nothing yet, or is at best partially implemented.</i>     */    protected void GASetCurrColour(int c)    {        lineColor = c;    }    protected int GAGetCurrColour()    {        return lineColor;    }    /**     * Sets the color to be used for filled drawing operations     * <p>     * <i>Dummy method. This means it does nothing yet, or is at best partially implemented.</i>     *     * @param c a color in 0x00RRGGBB format. In C, this was a uint32.     */    protected void GASetFillColour(int c)    {        fillColor = c;    }    /**     * Returns the color used for filled drawing operations     * <p>     * <i>Dummy method. This means it does nothing yet, or is at best partially implemented.</i>     */    protected int GAGetFillColour()    {        return fillColor;    }    /**     * Sets the color to be used when clearing the display.     * <p>     * <i>Dummy method. This means it does nothing yet, or is at best partially implemented.</i>     * @param c a color in 0x00RRGGBB format. In C, this was a uint32.     */    protected void GASetBackgroundColour(int c)    {        clearColor = c;    }    /**     * Returns width of M (the widest character) in current font.     *     * @returns Font width. In the C implementation, it returned a sint16.     */    protected int GAGetCurrfontWidth()    {        return g.getFont().charWidth('M');    }    /**     * Returns height of current font.     *     * @returns Font width. In the C implementation, it returned a sint16.     */    protected int GAGetCurrfontHeight()    {        return g.getFont().getBaselinePosition();    }    /**     * Returns the width of an image specified by an id.     *     * @param id An identifier for the image. In C, this was WCHAR_t (typedef uint16 WCHAR_t).     *     * @returns The width. in C, this was sint16.     *     * @see GACharOut     */    abstract int GAGetCharWidth(int id);    /**     * Returns the height of an image specified by an id.     *     * @param id An identifier for the image. In C, this was WCHAR_t (typedef uint16 WCHAR_t).     *     * @returns The width. in C, this was sint16.     *     * @see GACharOut     */    abstract int GAGetCharHeight(int id);    /**     * There are two ways to write an image to the screen. This is one of them - it is     * an artifact from the original C Game API. The other way is of course g.drawImage().     * The image is specified by an id. This id was the entry in the font     * table in the old C implementation. Since GameShell knows nothing about those id:s this     * is abstract. The implementation must translate the ID number into an actual image     * and draw that image to the screen.     * <p>     * In the original C Game API this was used to     * write a character from the current selected font. However it     * was more often used to draw the images in the game. Those     * images were stored in a font file. They must now be converted     * to PNG format.     * <p>     * Comparison with original C function. This routine no longer returns the actual image     * width, nor does it take the image width and height as arguments.     *     * @param id     The number that was formerly the id in the font table. In C this was WCHAR_t (uint16).     * @param x      The x cordinate to place the image. In C this was sint16.     * @param y      The y cordinate to place the image. In C this was sint16.     */    abstract void GACharOut(int id, short x, short y);    /**     * Does a repaint()     *     */    void GACheckForRefresh()    {        repaint();    }    /**     * Show a information box, it is a window containing of several textlabels     * and strings, its kind of window     * Every text id's and strings except for the Title will can be scrolled     * with the upp/down arrow keys     *     * If a TextId is set to TEXTID_NONE, the textlabel will not be included     * If a String is set to NULL it will not be used     *     * @param Title The title of the box, this title is placed at top of the     *     box and will not be scolled.     *     * @param RowId1 The first line consist of this text id line     *     * @param RowId2 The second line consist of this text id line     * @param RowId3 The third line consist of this string     *     * @param RowId4 The fourth line consist of this text id line     * @param RowId5 The fifth line consist of this string     *     * @param RowId6 The sext line consist of this text id line     * @param RowId7 The sevent line consist of this string     *     * @param RowId8 The eight line consist of this text id line     *     * @returns None     */    void GAInfoBox(int Title,                   int RowId1,                   int RowId2,                   String RowId3,                   int RowId4,                   String RowId5,                   int RowId6,                   String RowId7,                   int RowId8)    {        int w = g.getFont().stringWidth(RowId3) + 10;        int w5 = g.getFont().stringWidth(RowId5) + 10;        if (w5 > w)            w = w5;        int w7 = g.getFont().stringWidth(RowId7) + 10;

⌨️ 快捷键说明

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