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

📄 gamemodel.java

📁 J2ME的游戏原代码!希望能帮助有需要帮助的师兄弟们!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                        m_qbertHopDelay--;
                        if (m_keyCachedKeyValue != 0) {
                            resetColTimer(m_pQBert);
                        }
                    } else {
                        if (m_pQBert.charFutureMoves()[0] == 0) {
                            if (m_keyCachedKeyValue != 0) {
                                if (m_keyCachedKeyValue == Globals.KEY_1_UL) {
                                    moveQbert(Globals.UPLEFT);
                                } else if (m_keyCachedKeyValue == Globals.KEY_1_UR) {
                                    moveQbert(Globals.UPRIGHT);
                                /* Start	Modified	14-05-2003		for 4 and 6 key func. */
                                } else if (m_keyCachedKeyValue == Globals.KEY_1_LL
                                			|| m_keyCachedKeyValue == Globals.KEY_1_DDL) {
                                    moveQbert(Globals.DOWNLEFT);
                                } else if (m_keyCachedKeyValue == Globals.KEY_1_LR
                                		|| m_keyCachedKeyValue == Globals.KEY_1_DDR) {
                                    moveQbert(Globals.DOWNRIGHT);
                                /* End		Modified	14-05-2003	*/
                                } else if (m_keyCachedKeyValue == Canvas.KEY_NUM5) {
                                    //doLevelCompletion();
                                }
                                m_keyCachedKeyValue = 0;
                            } else {
                                for (int i=0; i < 4; i++) {
                                    if (m_arrKeysDown[i]) {
                                        moveQbert((byte)i);
                                    }
                                }
                            }
                        }
                    }
                    calcFutureMoves(m_pQBert);

                    // handle qbert row, cube transfer to coll row, cube
                    if (m_pQBert.rowTimerDone()) {
                        m_pQBert.charColRow(m_pQBert.charRow());
                        m_pQBert.charColCube(m_pQBert.charCube());
                    }
                    m_pQBert.decrementRowTimer();


                    // ----- end qbert actions -----
                    calcFutureMoves(g_Arr1Enemies, 10);

                    doCollisionChecking();

                    doEnemiesTurn();
                break;

                case Globals.MODE_DEATH :
                    // Qbert Died - check lives
                    if (m_pModeTimer.isOver()) {
                        checkLives(m_pQBert);
                    }
                break;

                case Globals.MODE_BOARDRESET :
                    // Put Qbert back on board minus enemies
                    //m_ModeSpeed = 450;
                    continueLevel();
                    setMode(Globals.MODE_NORMAL);
                break;

                case Globals.MODE_GAMEOVER :
                    // GameOver
                break;

                case Globals.MODE_LVL_COMPLETE_FLASHING:
                    //m_pBackGroundSprite.toggleBoardColor();
                    if (m_pModeTimer.isOver()) {
                        setMode(Globals.MODE_LVL_COMPLETE_BONUS);
                    }
                break;

                case Globals.MODE_LVL_COMPLETE_BONUS:
                    // make sure we're back to normal colors
                    //if (m_pBackGroundSprite.getFlippedColor() != m_endColor) {
                                        //m_pBackGroundSprite.toggleBoardColor();
                                        //}

                    if (m_pModeTimer.isOver()) {
                        setLevelComplete();
                    }
                break;

                case Globals.MODE_LVLCOMPLETE :
                    doLevelCompletion();
                break;

                case Globals.MODE_INTRO :
                    handleIntro();
                    //VALLI MR2
                    //Thread.sleep(50);
                break;

                case Globals.MODE_COLLISION :
                    if (m_pModeTimer.isOver()) {
                        checkLives(m_pQBert); // this sets a new mode
                    }
                break;
                }
                updateGameScreen();
                //VALLI MR2
				l1 = System.currentTimeMillis() - l1;
               	if(l1 < 80){
					Thread.sleep(80 - l1);
				}else {
            	    Thread.yield();
				}
            }
        } catch (Exception ex) {
            System.err.println("GameModel.run: " + ex); // SD
            ex.printStackTrace(); // SD
        }
    }


    private void setLevelComplete() {
        setMode(Globals.MODE_LVLCOMPLETE);
    }


    private void handleIntro() {
        int[] arrMoves = m_pQBert_Intro.charFutureMoves();
        if (arrMoves[0] == 0) {

            if (m_qbertIntroStepDelay-- < 1) {
                if (m_qbertIntroStep >= m_maxQbertIntroSteps) {
                    setMode(Globals.MODE_BLANK_BOARD);
                    return;
                }

                m_qbertIntroStepDelay = Globals.QBERT_DELAY_PER_HOP;
                m_pQBert_Intro.charDir(m_arrQbert_IntroSteps[m_qbertIntroStep]);

                switch (m_arrQbert_IntroSteps[m_qbertIntroStep]) {
                case Globals.UPRIGHT:
                    moveCharUR(m_pQBert_Intro);
                    m_qbertLocY--;
                    m_demoKey = Globals.KEY_1_UR - Canvas.KEY_NUM0;
                break;
                case Globals.UPLEFT:
                    moveCharUL(m_pQBert_Intro);
                    m_qbertLocX--;
                    m_demoKey = Globals.KEY_1_UL - Canvas.KEY_NUM0;
                break;
                case Globals.DOWNLEFT:
                    moveCharDL(m_pQBert_Intro);
                    m_qbertLocY++;
                    m_demoKey = Globals.KEY_1_LL - Canvas.KEY_NUM0;
                break;
                case Globals.DOWNRIGHT:
                    moveCharDR(m_pQBert_Intro);
                    m_qbertLocX++;
                    m_demoKey = Globals.KEY_1_LR - Canvas.KEY_NUM0;
                break;
                }

                m_qbertIntroStep++;

                //if (m_qbertIntroStep != -1) {
                //int row = m_pQBert_Intro.charRow();
                //int cube = m_pQBert_Intro.charCube();
                // if first step
                //m_arr2IntroColorGrid[m_qbertLocX][m_qbertLocY] =
                //m_arr2IntroColorGrid[m_qbertLocX][m_qbertLocY] = next_color;
                //}
            }
        } else {
            m_pQBert_Intro.setCharX(arrMoves[0]);
            m_pQBert_Intro.setCharY(arrMoves[1]);
            arrMoves[0] = arrMoves[2];
            arrMoves[1] = arrMoves[3];
            arrMoves[2] = arrMoves[4];
            arrMoves[3] = arrMoves[5];
            arrMoves[4] = 0;
            arrMoves[5] = 0;

            if (arrMoves[0] == 0) {
				/* Start	Commented		21-03-2003	no audio for qbert move */
                //doSoundAction(QbertSound.SOUND_QBERT);
                /* End		Commented		21-03-2003	*/

                int currColor = m_arr2IntroColorGrid[m_qbertLocX][m_qbertLocY];
                int next_color = currColor;
                if (currColor != m_endColor) {
                    if (m_numCubeColors == 3) {
                        if (currColor == m_interColor1) {
                            next_color = m_endColor;
                        } else {
                            next_color = m_interColor1;
                        }
                    } else {
                        next_color = m_endColor;
                    }

                } else {
                    // it is the end color... we need to see how we handle this

                    switch (m_cubeTurnBackType) {
                    case Globals.LVL_CUBE_TBT_TOGGLE_TOP:
                        if (m_numCubeColors == 3) {
                            next_color = m_interColor1;
                        } else {
                            next_color = m_startColor;
                        }
                        break;
                    case Globals.LVL_CUBE_TBT_CYCLE_TO_BEGINNING:
                        next_color = m_startColor;
                        break;
                    default:
                        next_color = m_endColor;
                        break;
                    }
                }
                m_arr2IntroColorGrid[m_qbertLocX][m_qbertLocY] = next_color;
            }
        }
    }



    private void doSoundAction(byte soundType) {
        if (m_pGameMidlet.m_bSoundOn) {
            QbertSound.playSound(soundType);
        }
    }


    private void doLevelCompletion() {
        m_pBackGroundSprite.updateLvl(m_level);
        m_pBackGroundSprite.updateRound(m_round);

        clearStage(false);
    }


    private void moveQbertOnDisc() {
        int moves[] = m_pQBert.charFutureMoves();
        if (moves[0] == 0) {
            moveCharOnDisc(m_pQBert);
        }
    }


    private void newGameAction() {
        // Randomly pick something to do out of the list of actions
        // for this m_level
        if (g_TimeStop > 0) return;

        m_tick_For_Enemy_Creation++;
        if (m_tick_For_Enemy_Creation > m_spawnTimerDuration) {
            if (m_cur_Num_Enemies < m_maxEnemiesThisRound) {


                int chance = (m_pRandom.nextInt() >>> 1) % 10;
                if (chance <= 5) return; // return on random chance of no creation
                int lvl = Math.min(m_level, 5);

                int row = 2;
                int cube = 1;

                int x = Globals.ENEMY_START_XL;
                int y = Globals.ENEMY_START_Y - 16;

                // randomize chance of left/right side
                if ((m_pRandom.nextInt() >>> 1) % 2 == 1) {
                    x = Globals.ENEMY_START_XR;
                    cube = 2;
                }

                int enemy_type = Globals.getEnemyTypeFromRandomNumber(m_pRandom.nextInt() >>> 1);

                // Check stage data to see if they enemy can be here
                while (Globals.LEVEL_DATA[lvl][m_round][enemy_type] == 0) {
                    enemy_type = Globals.getEnemyTypeFromRandomNumber(m_pRandom.nextInt() >>> 1);
                }

                // balance ugg+wrongway ratios
                switch (enemy_type) {
                case Globals.WRONGWAY:
                    if (m_arrBoardDetails[Globals.UGG] < m_arrBoardDetails[Globals.WRONGWAY]) {
                        enemy_type = Globals.UGG;
                    }
                    break;
                case Globals.UGG:
                    if (m_arrBoardDetails[Globals.WRONGWAY] < m_arrBoardDetails[Globals.UGG]) {
                        enemy_type = Globals.WRONGWAY;
                    }
                    break;
                }

                // Check current board to see if one exists
                //if (!m_arrBoardDetails[enemy_type] || enemy_type == Globals.RED) {
                m_tick_For_Enemy_Creation = 0;

                int dir = (int) Globals.DOWNRIGHT;


                switch (enemy_type) {
                case Globals.PURPLE:
                    // return if coily is already on board
                    if (m_arrBoardDetails[Globals.COILY] > 0 || m_arrBoardDetails[Globals.PURPLE] > 0) return;
                    break;
                case Globals.WRONGWAY:
                    x = Globals.ENEMY_BOTTOM_RIGHT_X + 8 - 4;
                    y = Globals.ENEMY_BOTTOM_RIGHT_Y + 14 - 4 + 2;// 2;
                    row = Globals.QBERT_DIMENSIONS;
                    cube = Globals.QBERT_DIMENSIONS;
                    dir = Globals.UPLEFT; // face up
                    break;
                case Globals.UGG:
                    x = Globals.ENEMY_BOTTOM_LEFT_X;
                    y = Globals.ENEMY_BOTTOM_RIGHT_Y + 11;
                    row = Globals.QBERT_DIMENSIONS;
                    cube = 0;
                    dir = Globals.DOWNRIGHT;
                    break;
                }

                // We can load this char onto the board
                CharacterSprite enemy = new CharacterSprite(x, y, dir, enemy_type, row, cube, 0, 1);
                enemy.setCharSpeed(m_monsterSpeedDelay);

                int[] moves = enemy.charFutureMoves();

                switch (enemy_type) {
                case Globals.WRONGWAY:
                    moves[0] = x + 8;
                    moves[1] = y;
                    moves[2] = x + 4;
                    moves[3] = y;
                    moves[4] = x;
                    moves[5] = y;
                    break;
                case Globals.UGG:
                    moves[0] = x - 8;
                    moves[1] = y;
                    moves[2] = x - 4;
                    moves[3] = y;
                    moves[4] = x;
                    moves[5] = y;
                    break;
                default:
                    moves[0] = x;
                    moves[1] = y + 4;
                    moves[2] = x;
                    moves[3] = y + 8;
                    moves[4] = x;
                    moves[5] = y + 16;
                    break;
                }

                enemy.charDelay();


                while (g_Arr1Enemies[m_numEnemies] != null) {
                    m_numEnemies++;
                    if (m_numEnemies >= 10)
                        m_numEnemies = 0;
                }

                g_Arr1Enemies[m_numEnemies] = enemy;
                enemy.charIndex(m_numEnemies);

                m_numEnemies++;
                if (m_numEnemies >= 10)
                    m_numEnemies = 0;

                m_cur_Num_Enemies++;

                m_arrBoardDetails[enemy_type]++;
            }

            //}
        }
    }


    private void continueLevel() {
        g_bGame_Playing = true;
        g_bEnd_Stage = false;
        // Setup Qbert and remove enemies
        continueLevel(m_pQBert);
        if (!g_bCheck_Falling) {

⌨️ 快捷键说明

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