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

📄 gamemodel.java

📁 J2ME的游戏原代码!希望能帮助有需要帮助的师兄弟们!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        resetColTimer(ch);
        // Set the row and row's cube#'s and calc the future moves
        int moves[] = ch.charFutureMoves();

        switch (ch.charType()) {
        case Globals.UGG:
            // Ends up on same row/other side of board
            ch.charRow(ch.charRow() - 1);

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

        default:
            ch.charRow(ch.charRow() - 1);
            //ch.charCube(ch.charCube());
            moves[0] = ch.charX() + 1;
            moves[1] = ch.charY() - 5;
            moves[2] = moves[0] + 5;
            moves[3] = moves[1] - 9;
            moves[4] = moves[2] + 2; // 1 5 2 = 8
            moves[5] = moves[3] + 2; // -5, -9, 2 = -12

            break;
        }
    }


    private void moveCharUL(CharacterSprite ch) {
        resetColTimer(ch);

        // Set the row and row's cube#'s and calc the future moves
        int moves[] = ch.charFutureMoves();

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

        switch (ch.charType()) {
        case Globals.WRONGWAY:

            moves[0] = ch.charX() + 1;
            moves[1] = ch.charY() - 3;
            moves[2] = ch.charX() - 4;//moves[0] - 5;
            moves[3] = ch.charY() - 9;//moves[1] - 9;
            moves[4] = ch.charX() - 8; //moves[2] - 2; //1,5,2
            moves[5] = ch.charY() - 12;//moves[3] + 2; // 5, 9, +2
            break;
        default:
            moves[0] = ch.charX() - 1;
            moves[1] = ch.charY() - 5;
            moves[2] = ch.charX() - 6;//moves[0] - 5;
            moves[3] = ch.charY() - 14;//moves[1] - 9;
            moves[4] = ch.charX() - 8; //moves[2] - 2; //1,5,2
            moves[5] = ch.charY() - 12;//moves[3] + 2; // 5, 9, +2
            break;
        }
    }


    private void moveCharDR(CharacterSprite ch) {
        resetColTimer(ch);

        // Set the row and row's cube#'s and calc the future moves
        int moves[] = ch.charFutureMoves();

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

        moves[0] = ch.charX() + 3;
        moves[1] = ch.charY() - 3;
        moves[2] = moves[0] + 4;
        moves[3] = moves[1] + 9;
        moves[4] = moves[2] + 1;
        moves[5] = moves[3] + 6;
    }


    private void moveCharDL(CharacterSprite ch) {
        resetColTimer(ch);

        // Set the row and row's cube#'s and calc the future moves
        int moves[] = ch.charFutureMoves();
        ch.charRow(ch.charRow() + 1);
        //ch.charCube(ch.charCube());
        moves[0] = ch.charX() - 3;
        moves[1] = ch.charY() - 3;
        moves[2] = moves[0] - 4;
        moves[3] = moves[1] + 9;
        moves[4] = moves[2] - 1;
        moves[5] = moves[3] + 6;
    } // Variables for doing disc movement with qbert on them


    private void moveCharOnDisc(CharacterSprite ch) {
        // Set the row and row's cube#'s and calc the future moves
        // character is qbert obviously

        int moves[] = ch.charFutureMoves();

        // the disc
        CharacterSprite d = g_Arr1Discs[g_Disc_Num_In_Use];

        int row = ch.charRow();
        int cube = ch.charCube();
        int x = ch.charX();
        //int y = ch.charY();

        int d_x = d.charX();
        int d_y = d.charY();

        boolean bStillMoving = false;
        if (d_y > Globals.QBERT_START_Y - 8) {
            // Qbert calc's
            int newY = Math.max(d_y-5, Globals.QBERT_START_Y-8);
            d.setCharY(newY);
            ch.setCharY(newY-10);

            bStillMoving = true;
        }

        int newX = d_x;

        if (d_x > Globals.QBERT_START_X) {

            int movementDistY = 3;
            // moderate movement on discs > row 4 so that they don't
            // overlap the edges
//             if (d_y > Globals.QBERT_START_Y + Globals.CUBE_HEIGHT * 4) {
//                 movementDistY = 3;
//             }
            d_x = Math.max(Globals.QBERT_START_X, d_x-movementDistY);
            bStillMoving = true;
            // move disc and qbert
            d.setCharX(d_x);
            ch.setCharX(d_x);

        } else if (d_x < Globals.QBERT_START_X) {
            int movementDistY = 3;
//             if (d_y > Globals.QBERT_START_Y + Globals.CUBE_HEIGHT * 4) {
//                 movementDistY = 3;
//             }

            d_x = Math.min(Globals.QBERT_START_X, d_x+movementDistY);
            bStillMoving = true;
            // move disc and qbert
            d.setCharX(d_x);
            ch.setCharX(d_x);
        }


        if (m_bDrop_Back_On_Board) {
            m_bCoilyWaiting = false;
            m_bQbertOnDisc = false;
            m_bDrop_Back_On_Board = false;
            ch.charOnBoard(true);
            //m_pGameScreen.Qbert_Moving(false);
            g_bGame_Playing = true;
            ch.charRow(1); // qbert goes to 1,1
            ch.charCube(1);
            g_Arr1Discs[g_Disc_Num_In_Use] = null;
            m_numDiscs--;
            g_ToDisc_Cube = 1;
            g_ToDisc_Row = 1;

            int x_final = Globals.QBERT_START_X;

            moves[0] = x;
            moves[1] = Globals.QBERT_START_Y - 6;
            moves[2] = x_final;
            moves[3] = Globals.QBERT_START_Y - 4;
            moves[4] = x_final;
            moves[5] = Globals.QBERT_START_Y;

        //@@@checkCubeColor(ch);

        } else if (!bStillMoving) {
            m_keyCachedKeyValue = 0;

            if (!m_bCoilyWaiting) {
                m_bDrop_Back_On_Board = true;
            } else if (coilyRow() < 0 || coilyRow() > 3) {
                m_bCoilyWaiting = false;
            }
        }
    }

    // returns row that coily is on, returns -1 if no coily on board
    private int coilyRow() {
        for (int i = 0; i < 10; i++) {
            if (g_Arr1Enemies[i] != null) {
                CharacterSprite ch = g_Arr1Enemies[i];
                if (ch.charOnBoard()) { // Pick a direction
                    if (ch.charType() == Globals.COILY) {
                        return (ch.charRow());
                    }
                }
            }
        }
        return -1;
    }


    private void doCollisionChecking() {
        int q_x = m_pQBert.charX();
        int q_y = m_pQBert.charY();
        int e_type;
        boolean isPassingBy;
        boolean isCollision;

        CharacterSprite e;

        if (m_pQBert.charOnBoard()) {
            for (int i = 0; i < g_Arr1Enemies.length; i++) {
                if (g_Arr1Enemies[i] != null) {
                    isPassingBy = false;
                    isCollision = false;

                    e = g_Arr1Enemies[i];

                    if (e.charType() == Globals.UGG || e.charType() == Globals.WRONGWAY) {
                        int x_val = 4;
                        int y_val = 4;
                        if (m_pQBert.charFutureMoves()[3] > 0) {
                            x_val = 6;
                            y_val = 6;
                        }
                        int e_x = e.charX();
                        int e_y = e.charY();

                        if ((e_x >= (q_x - x_val)) && (e_x <= (q_x + x_val)) && (e_y >= (q_y - y_val)) && (e_y <= (q_y + y_val))) {
                            isCollision = true;
                        }
                    } else {
                        int qColRow = m_pQBert.charColRow();
                        int qColCube = m_pQBert.charColCube();
                        int qRow = m_pQBert.charRow();
                        int qCube = m_pQBert.charCube();
                        int eOldRow = e.charOldRow();
                        int eOldCube = e.charOldCube();

                        if (!m_pQBert.rowTimerExpired()) {
                            if (qRow == eOldRow && qCube == eOldCube &&
                                    m_pQBert.charOldRow() == e.charRow() && m_pQBert.charOldCube() == e.charCube()) {
                                isPassingBy = true;
                            } else if (qRow == eOldRow && qCube == eOldCube &&
                                        m_pQBert.charOldRow() == e.charRow() && m_pQBert.charOldCube() == e.charCube()) {
                                isPassingBy = true;
                            }
                        } else {
                            if (e.rowTimerDone() || g_TimeStop > 0) {
                                if (qColRow == e.charColRow() && qColCube == e.charColCube()) {
                                    isCollision = true;
                                }
                            } else {
                                if (qRow == eOldRow && qCube == eOldCube &&
                                        m_pQBert.charOldRow() == e.charRow() &&
                                        m_pQBert.charOldCube() == e.charCube()) {
                                    isCollision = true;
                                } else if (e.rowTimer() == Globals.ENEMY_COLROW_DELAY &&
                       qRow == eOldRow &&
                       qCube == eOldCube) {
                    isCollision = true;
                }
                }
            }

            }

            if (isPassingBy || isCollision) {
            // He is within the boundary
            e_type = e.charType();

            if (g_TimeStop > 0 &&
                e_type != Globals.GREEN &&
                e_type != Globals.SLICK &&
                e_type != Globals.SAM) {
                return;
            }

            if (e_type == Globals.GREEN
                || e_type == Globals.SLICK
                || e_type == Globals.SAM) {

                // Remove enemy and give Qbert points
                if (e_type == Globals.GREEN) {
                incPoints(Globals.PT_GREEN_BALL);
                g_TimeStop = 40;
                } else {
                incPoints(Globals.PT_SAM_SLICK);
                }

                g_Arr1Enemies[i] = null;
                e.charShowChar(false);

                m_cur_Num_Enemies--;
                g_Arr1Enemies[e.charIndex()] = null;
                m_arrBoardDetails[e.charType()] = 0;
            } else {
                if (checkForEndCondition()) {
                return;
                }

                //  Qbert loses a life
                doSoundAction(QbertSound.SOUND_DEATH);
                setMode(Globals.MODE_COLLISION);

                int lives = m_pQBert.charLives() - 1;
                m_pQBert.charLives(lives);
                m_pBackGroundSprite.updateLivesLeft(lives);
                break;
            }
            }
        }
        }
    }
    }


    private void doGroundChecking(CharacterSprite ch) {
        if (ch.charOnBoard()) {

            int row = ch.charRow();
            int cube = ch.charCube();
            boolean bFall = false;

            switch (ch.charType()) {
            case Globals.QBERT:
                // Check for disc now for Qbert only
                {
                    if (row > Globals.QBERT_DIMENSIONS || row <= 0 || cube > row || cube <= 0) {
                        g_bGame_Playing = false;
                        //m_pGameScreen.Qbert_Moving(true);
                        ch.charOnBoard(false);
                        bFall = !checkForDiscs(ch);
                    }
                }
                break;
            case Globals.WRONGWAY:
                if (ch.charCube() <= 0) {
                    bFall = true;
                }
                break;
            case Globals.UGG:
                 if (ch.charCube() >= ch.charRow()) {
                     bFall = true;
                 }
                break;

            default:
                bFall = (row > Globals.QBERT_DIMENSIONS || row <= 0 || cube > row || cube <= 0);
                break;
            }


            if (bFall) {
                // Fall off - do animation to fall off screen
                g_bGame_Playing = true;
                fallOff(ch);
                ch.charOnBoard(false);
            }
        }
    }


    private boolean checkForDiscs(CharacterSprite ch) {
        int row = ch.charRow();
        int cube = ch.charCube();
        int side = 0;

        if (row >= 0 && row < Globals.QBERT_DIMENSIONS) {
            if (cube > 0) {
                side = 1; // right side
            } else {
                side = 0;
            }
            if (m_arr2AvailableDiscs[row][side]) {
                // We have a disc to use - do lots of stuff here
                //m_pGameScreen.Qbert_Moving(true);
                ch.charOnBoard(f

⌨️ 快捷键说明

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