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

📄 gamemodel.java

📁 J2ME的游戏原代码!希望能帮助有需要帮助的师兄弟们!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            setCharTop(m_pQBert);
        }
        g_bCheck_Falling = true;
    }


    private void continueLevel(CharacterSprite ch) {
        int old_x = ch.charOldX();
        int old_y = ch.charOldY();
        int old_row = ch.charOldRow();
        int old_cube = ch.charOldCube();

        ch.charDir(Globals.DOWNRIGHT);
        ch.setCharX(old_x);
        ch.setCharY(old_y);
        ch.charRow(old_row);
        ch.charCube(old_cube);
        ch.charResetMoves();
        ch.charShowChar(true);
        ch.charOnBoard(true);
        clearEnemies();
    }


    private void clearEnemies() {
        for (int i = 0; i < 10; i++) {
            g_Arr1Enemies[i] = null;
        }

        for (int j = 1; j < 9; j++) {
            m_arrBoardDetails[j] = 0;
        }

        m_numEnemies = 0;
        m_cur_Num_Enemies = 0;
    }


    private void setCharTop(CharacterSprite ch) {
        int x = Globals.QBERT_START_X;
        int y = Globals.QBERT_START_Y;
        int dir = Globals.DOWNRIGHT;
        ch.setCharX(x);
        ch.setCharY(y);
        ch.charDir(dir);
        ch.charRow(1);
        ch.charCube(1);
        ch.charResetMoves();
    }


    private void checkLives(CharacterSprite ch) {
        if (ch.charLives() >= 0) {
            setMode(Globals.MODE_BOARDRESET);
        } else {
            setMode(Globals.MODE_GAMEOVER);
        }
    }


    private void setMode(byte mode) {
        g_Game_Mode = mode;
        switch (mode) {
        case Globals.MODE_NORMAL:
            m_transitionTicks = 10;
            g_bGame_Playing = true;
            m_keyCachedKeyValue = 0;
            m_flashCounter = 0;
            break;
        case Globals.MODE_DEATH:
            g_bGame_Playing = false;
            moveCharOffScreen(m_pQBert);
            m_pModeTimer.startTimer(2000);
            break;
        case Globals.MODE_BOARDRESET:
            break;
        case Globals.MODE_GAMEOVER:
            m_pModeTimer.startTimer(2000);
            g_bGame_Playing = false;
            break;
        case Globals.MODE_LVL_COMPLETE_FLASHING:
            g_bFinished_Lvl = true;
            g_TimeStop = 0;
            m_pModeTimer.startTimer(2500);
            break;

        case Globals.MODE_LVL_COMPLETE_BONUS:

            m_pModeTimer.startTimer(1500);
            m_waveBonus = Math.min(5000, Globals.PT_LEVEL_BASE + ((m_round + (m_level*4)) * 250)+(m_numDiscs * 50));
            incPoints(m_waveBonus);
            break;

        case Globals.MODE_LVLCOMPLETE:
            m_round++;
            if (m_round >= 4) {
                m_round = 0;
                m_level++;
                if (m_level > 8) {
                    m_level = 8; // this is indexed by 0, so this is level 9
                }
                m_maxEnemiesThisRound = Math.max(Globals.MAX_ENEMIES_ON_A_STAGE, Globals.BASE_ENEMIES_PER_STAGE + m_level);
            }
            break;

        case Globals.MODE_INTRO:
            int x = Globals.QBERT_START_X+1;
            int y = Globals.QBERT_START_Y;

            // setup intro qbert
            m_pQBert_Intro = new CharacterSprite(x, y, Globals.DOWNLEFT, Globals.QBERT, 1, 1, 0, 1);
            m_pQBert_Intro.setImageCycle(3);
            m_qbertIntroStep = 0; // starts on first step

            int level = Math.min(3, m_level);

            // cache steps
            m_arrQbert_IntroSteps = Globals.ARR2_QBERT_INTRO_SEQUENCE[level];
            m_maxQbertIntroSteps = m_arrQbert_IntroSteps.length;
            m_qbertIntroStepDelay = Globals.QBERT_DELAY_PER_HOP;

            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < 2; j++) {
                    m_arr2IntroColorGrid[i][j] = m_startColor;
                }
            }

            m_qbertLocX = 0;
            m_qbertLocY = 0;
            break;

        case Globals.MODE_COLLISION :
            g_TimeStop = 0;
            g_bGame_Playing = false;
            m_pModeTimer.startTimer(2000);
            break;
        case Globals.MODE_BLANK_BOARD:
            m_pModeTimer.startTimer(500);
            break;
        }
    }


    private void doEnemiesTurn() {
        if (g_TimeStop <= 0) {
            for (int i = 0; i < 10; i++) {
                if (g_Arr1Enemies[i] != null) {
                    CharacterSprite ch = g_Arr1Enemies[i];

            //if (ch.rowTimerDone()) {
            ch.charColRow(ch.charRow());
            ch.charColCube(ch.charCube());
            //}
            ch.decrementRowTimer();

                    if (!ch.charDelay()) {
                        if (ch.charOnBoard()) { // Pick a direction
                            int type = ch.charType();
                            switch (type) {
                            case Globals.RED :
                                checkNormalMoves(ch);
                                break;
                            case Globals.COILY :
                                checkCoilyMoves(ch);
                                break;
                            case Globals.GREEN :
                                checkNormalMoves(ch);
                                break;
                            case Globals.SLICK :
                                checkNormalMoves(ch);
                                break;
                            case Globals.SAM :
                                checkNormalMoves(ch);
                                break;
                            case Globals.UGG :
                                checkUggMoves(ch);
                                break;
                            case Globals.WRONGWAY :
                                checkWrongwayMoves(ch);
                                break;
                            case Globals.PURPLE :
                                checkCoilyMoves(ch);
                                break;
                            }
                        }
                    }
                }
            }

        } else {
            g_TimeStop--;
        }
    }


    private void checkCoilyMoves(CharacterSprite pCoily) {
        if (pCoily.charType() == Globals.PURPLE) {
            if (pCoily.charRow() < Globals.QBERT_DIMENSIONS) {
                checkNormalMoves(pCoily);
            } else {
                // Turn into coily
                m_arrBoardDetails[Globals.PURPLE] = 0;//false;
                pCoily.charType(Globals.COILY);
                m_arrBoardDetails[Globals.COILY] = 1;//true;
                // set up moves
                //checkCoilyMoves(pCoily);
            }
        } else {
            // Do Coily AI
            //int row_qbert = m_pQBert.charRow();
            //int cube_qbert = m_pQBert.charCube();
            int row_e = pCoily.charRow();
            int cube_e = pCoily.charCube();

            int row_qbert = g_ToDisc_Row;
            int cube_qbert = g_ToDisc_Cube;


             if (row_e == row_qbert && cube_e == cube_qbert) {
                if (cube_qbert <= 1) {
                    moveCharUL(pCoily);
                    pCoily.charDir(Globals.UPLEFT);
                } else {
                    moveCharUR(pCoily);
                    pCoily.charDir(Globals.UPRIGHT);
                }
         } else {
         if (row_e >= row_qbert)
             { // Move enemy up
             if (cube_e > cube_qbert)
             { // Move left (up)
                        moveCharUL(pCoily);
                        pCoily.charDir(Globals.UPLEFT);
                      }
                    else
                    { //    Move right (up)
                        moveCharUR(pCoily);
                        pCoily.charDir(Globals.UPRIGHT);
                    }
                }
                else
                { // Move enemy down
                    if (cube_e >= cube_qbert)
                    { // Move left (down)
                        moveCharDL(pCoily);
                        pCoily.charDir(Globals.DOWNLEFT);
                    }
                    else
                    {
                        //  Move right (down)
                        moveCharDR(pCoily);
                        pCoily.charDir(Globals.DOWNRIGHT);
                    }
                }
            }
        }
    }


    private void checkUggMoves(CharacterSprite ch) {
        if (((m_pRandom.nextInt() >>> 1) % 2) == 1) {
            // move relative LEFT
            // Move UR
            moveCharUR(ch);
            ch.charDir(Globals.UPRIGHT);
            //moveCharDR(ch);
            //ch.charDir(Globals.DOWNRIGHT);
        } else {
            // Move relative RIGHT

            // do special move
            int moves[] = ch.charFutureMoves();

            ch.charCube(ch.charCube() + 1);

            moves[0] = ch.charX() + 9;
            moves[1] = ch.charY() + 4;
            moves[2] = ch.charX() + 13;
            moves[3] = ch.charY() + 4;
            moves[4] = ch.charX() + 16;
            moves[5] = ch.charY();

            //moveCharDL(ch);
            ch.charDir(Globals.DOWNRIGHT);
        }
    }

    private void checkWrongwayMoves(CharacterSprite ch) {
        //int dir = (m_pRandom.nextInt() >>> 1) % 4;
        //int row = ch.charRow();
        //int cube = ch.charCube();

        if (((m_pRandom.nextInt() >>> 1) % 2) == 1) {
            // Move relative LEFT
            // Move UL
            moveCharUL(ch);
            ch.charDir(Globals.UPLEFT); //face up
        } else {
            // move relative RIGHT

            // do special move
            int moves[] = ch.charFutureMoves();

            ch.charCube(ch.charCube() - 1);

            moves[0] = ch.charX() - 4;
            moves[1] = ch.charY() + 7;
            moves[2] = ch.charX() - 12;
            moves[3] = ch.charY() + 5;
            moves[4] = ch.charX() - 16;
            moves[5] = ch.charY();

            //moveCharDL(ch);
            ch.charDir(Globals.DOWNLEFT); // face down
        }
    }


    private void checkNormalMoves(CharacterSprite ch) { // Down either right or left
        int right = m_pRandom.nextInt() % 2;
        if (right == 1) {
            // Move right
            moveCharDR(ch);
            ch.charDir(Globals.DOWNRIGHT);
        } else {
            // Move left
            moveCharDL(ch);
            ch.charDir(Globals.DOWNLEFT);
        }
    }


    private void calcFutureMoves(CharacterSprite chars[], int num) {

        if (g_TimeStop <= 0 || num == 7) {
            for (int i = 0; i < num; i++) {
                if (chars[i] != null) {
                    calcFutureMoves(chars[i]);
                }
            }
        }
    }

    private void calcFutureMoves(CharacterSprite ch) {
        int moves[] = ch.charFutureMoves();
        int next_moves[];
        boolean finish_stage = false;
        if (moves[0] != 0 && moves[1] != 0) {
            int old_x = ch.charX();
            int old_y = ch.charY();
            int x = moves[0];
            int y = moves[1];
            ch.setCharX(x);
            ch.setCharY(y);

            moves[0] = 0;
            moves[1] = 0;

            if (moves[2] != 0 && moves[3] != 0) {
                x = moves[2];
                y = moves[3];
                moves[0] = x;
                moves[1] = y;
                moves[2] = 0;
                moves[3] = 0;
                if (moves[4] != 0 && moves[5] != 0) {
                    x = moves[4];
                    y = moves[5];
                    moves[2] = x;
                    moves[3] = y;
                    moves[4] = 0;
                    moves[5] = 0;
                    // Do we want to go to 4 future moves?
                }
            } else {
        int type = ch.charType();


                if (g_bGame_Playing) {

                    if (type == Globals.QBERT) {
                        //m_pGameScreen.Qbert_Moving(false);
                        // don't set it yet.. have a delay
                        m_qbertHopDelay = Globals.QBERT_DELAY_PER_HOP;
                        checkCubeColor(ch);
            ch.resetRowTimer(0); //allow qbert to do collision

⌨️ 快捷键说明

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