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

📄 cgameplay.java

📁 一个3D的保龄球的源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    try {
      if (!m_scene.isFinished()) {
        if (m_isSlowAction == true)
        {
          Thread.sleep(100); //09/02 Milo for slow action
          m_scene.step(true);
        }
        m_scene.step(false);
      }
      else {
        /*if (m_roundNumber == 9 && m_isBonusShot == false) {
         for (int i = 0; i < 10; ++i) {
         m_scene.m_tenpin[i].m_tenpinState = CTenpin.TENPIN_STATE_OUTSIDE;
         }
         } // for test 09-08 Milo*/
        for (int i=0; i < 10; ++i)
          System.out.println("Tenpin " + i + " Position is:" +
                             m_scene.m_tenpin[i].m_tenpinPosition[0]/def.DEFAULT_EXTEND
                             + "|||"+m_scene.m_tenpin[i].m_tenpinPosition[1]/def.DEFAULT_EXTEND
                             + "|||"+m_scene.m_tenpin[i].m_tenpinPosition[2]/def.DEFAULT_EXTEND);

        calculateAfterCollision();
        m_staRound = ROUND_FINISH;
      }

      System.out.println("round finish? :     " + m_scene.isFinished());
    }
    catch (Exception ex) {
      System.out.println(ex.toString());
    }
  }

  private void restart() {
    m_scene.m_playerPosition[0] = def.PLAYER_POSITION_X;
    m_scene.m_playerPosition[1] = def.PLAYER_POSITION_Y;
    m_scene.m_playerPosition[2] = 0;
    m_scene.m_playerRotation[0] = def.PLAYER_ROTATION_X;
    m_scene.m_playerRotation[1] = def.PLAYER_ROTATION_Y;
    m_scene.m_playerRotation[2] = def.PLAYER_ROTATION_Z;
    m_aimSpot = 0;
    m_rotationPower = 0;
    m_isScoreBoardChanged = false;
    m_playerPower = 0;
    m_scene.restart();
  }

  private void calculateAfterCollision() {
    try {
      /*if (m_roundNumber == 9)
       m_tenpinState = CScene.ALL_TENPINS_FALL;
       else*/
      m_tenpinState = m_scene.getTenpinState();

      int check = 0x0001;
      byte counter = 0;

      for (int i = 0; i < 10; i++) {
        if ( ( (m_tenpinState & check) >> i == 1)) { //true for the stand tenpin
          counter++;
        }
        check = check << 1;
      }

      if (counter == 0 & m_isSecondBall == false) {
        m_isStrike = true;
      }

      calculateScore(m_scene.m_player.m_scoreInfo,
                     (byte) (CScene.TOTAL_TENPIN_NUMBER - counter)); //???Milo
    }

    catch (Exception ex) {
      System.out.println(ex.toString());
      ex.printStackTrace();
    }

  }

  // ************************************************************
  // ************************************************************
  /** Initialize the Scoreinfo struct.
   * @param scoreInfo
   * The score information.
   * */
  private void iniScoreInfo(ScoreInfo scoreInfo) {
    scoreInfo.iScores = 0;
    scoreInfo.addSpareScore = false;
    scoreInfo.addStrikeScore = false;
    scoreInfo.strikeCount = 0;
    scoreInfo.totalScores[10] = -1;
    scoreInfo.trunPageNum = 0;
    for (int i = 0; i < 10; i++)
      scoreInfo.totalScores[i] = 0;
    for (int i = 0; i < 21; i++)
      scoreInfo.scores[i] = 0;
  }

  private boolean calculateScore(ScoreInfo scoreInfo, byte numFallPin) {
    int iScores = scoreInfo.iScores;
    boolean addSpareScore = scoreInfo.addSpareScore;
    int[] totalScores = scoreInfo.totalScores;
    byte[] scores = scoreInfo.scores;
    int strikeCount = scoreInfo.strikeCount;
    boolean addStrikeScore = scoreInfo.addStrikeScore;
    boolean setAllPinStand = false;

    //Record the score and start next delivery if game not over
    if (iScores < 18) {
      if ( (iScores % 2) == 0) {
        scoreInfo.scores[iScores] = numFallPin;

        //Add append score.
        if (addSpareScore) {
          totalScores[iScores / 2 - 1] += scores[iScores];
          addSpareScore = false;
        }

        if (numFallPin == 10) {
          if (++strikeCount == 3) {
            if (iScores / 2 - 2 == 0)
              totalScores[iScores / 2 - 2] = 30;
            else
              totalScores[iScores / 2 - 2] = totalScores[iScores / 2 - 3] + 30;
            strikeCount--;
          }
          addStrikeScore = true;
          totalScores[iScores / 2] = -1;
          iScores = iScores + 2;
        }
        else {
          if (strikeCount == 2) {
            if (iScores / 2 - 2 == 0)
              totalScores[iScores / 2 - 2] = 30;
            else
              totalScores[iScores / 2 - 2] = totalScores[iScores / 2 - 3] + 20;
            strikeCount--;
          }
          iScores++;
        }
      }
      else {
        scores[iScores] = (byte) (numFallPin - scores[iScores - 1]);

        //Add append score
        if (addStrikeScore) {
          if (strikeCount == 1) {
            if (iScores / 2 - 1 == 0)
              totalScores[iScores / 2 - 1] = 10 + numFallPin;
            else
              totalScores[iScores / 2 - 1] = totalScores[iScores / 2 - 2]
                  + 10 + numFallPin;
          }
          strikeCount = 0;
          addStrikeScore = false;
        }

        if (numFallPin == 10)
          addSpareScore = true;

        if (iScores / 2 == 0)
          totalScores[iScores / 2] = numFallPin;
        else
          totalScores[iScores / 2] = totalScores[iScores / 2 - 1]
              + numFallPin;
        iScores++;
      }

      if (m_scene.getTenpinState() == CScene.ALL_TENPINS_FALL
          || ( (iScores % 2) == 0))
        setAllPinStand = true;
    }
    else if (iScores == 18) {
      scores[iScores] = numFallPin;

      //Add append score.
      if (addSpareScore) {
        totalScores[iScores / 2 - 1] += scores[iScores];
        addSpareScore = false;
      }

      if (numFallPin == 10) {
        if (++strikeCount == 3) {
          totalScores[7] = totalScores[6] + 30;
          strikeCount--;
        }
        addStrikeScore = true;
        setAllPinStand = true;
      }
      else {
        if (strikeCount == 2) {
          totalScores[7] = totalScores[6] + 20;
          strikeCount--;
        }
      }
      totalScores[9] = -1;
      System.out.println("this is 18");
      iScores++;
    }
    else if (iScores == 19) {
      if (scores[18] == 10) {
        scores[iScores] = numFallPin;

        if (numFallPin == 10) {
          if (++strikeCount == 3) {
            totalScores[8] = totalScores[7] + 30;
            strikeCount--;
          }
          addStrikeScore = true;
        }
        else {
          if (strikeCount == 2) {
            totalScores[8] = totalScores[7] + 20;
            strikeCount--;
          }
          iScores++;
        }
      }
      else {
        scores[iScores] = (byte) (numFallPin - scores[iScores - 1]);

        //Add append score
        if (addStrikeScore) {
          if (strikeCount == 1) {
            totalScores[8] = totalScores[7] + 10 + numFallPin;
          }
          strikeCount = 0;
          addStrikeScore = false;
        }

        if (numFallPin != 10) {
          totalScores[9] = totalScores[8] + numFallPin;
          iScores += 2;
          totalScores[10] = totalScores[9];
          setAllPinStand = true;
        }
      }

      if (numFallPin == 10) {
        iScores++;
        setAllPinStand = true;
      }
    }
    else if (iScores == 20) {
      if (scores[18] == 10 && scores[19] != 10) {
        scores[20] = (byte) (numFallPin - scores[19]);
      }
      else
        scores[20] = numFallPin;

      totalScores[9] = totalScores[8] + scores[18] + scores[19]
          + scores[20];

      strikeCount = 0;
      addStrikeScore = false;
      iScores++;
      setAllPinStand = true;
      totalScores[10] = totalScores[9];
    }
    else if (iScores == 21) {
      setAllPinStand = true;
      totalScores[10] = totalScores[9];
    }

    //Record the current score information.
    scoreInfo.iScores = iScores;
    scoreInfo.addSpareScore = addSpareScore;
    scoreInfo.totalScores = totalScores;
    scoreInfo.scores = scores;
    scoreInfo.strikeCount = strikeCount;
    scoreInfo.addStrikeScore = addStrikeScore;

    return setAllPinStand;
  }

  private void render3DModels(Graphics gx, int flag) {
    try {
      /*if (flag ==2){
       m_scene.m_render3D.m_eye[0] = (m_scene.m_currentBallPosition[0] -
       CScene.LANE_WIDTH / 2) /
       def.DEFAULT_EXTEND;
       m_scene.m_render3D.m_eye[1] = m_scene.m_currentBallPosition[1] /
       def.DEFAULT_EXTEND;
       m_scene.m_render3D.m_eye[2] = m_scene.m_currentBallPosition[2] /
       def.DEFAULT_EXTEND;
       m_scene.UpdateCamera();
       }*/

      m_scene.m_render3D.StartRender3D(gx); //Milo;forRender3D
      m_scene.RenderScene(flag); //Milo;forRender3D 3 is for finish stage
    }
    catch (Exception e) {
      //m_error = "MODEL" + e.toString();
      e.printStackTrace();
    }

    m_scene.m_render3D.EndRender3D(gx); //Milo;forRender3D
  }

  private void setInitTenpinState() {
    if (m_isSecondBall)
      m_scene.setInitTenpinsState(m_scene.getTenpinState());
    else
      m_scene.setInitTenpinsState(CScene.ALL_TENPINS_STAND);

  }

  public void loadScoreImage() {

    try {
      m_offImage = Image.createImage("/score.png");
      m_scoreImage = Image.createImage(m_offImage.getWidth(),
                                       m_offImage.getHeight());
      System.gc();
      Thread.yield();
    }
    catch (Exception e) {
      e.printStackTrace();
    }

  }

  private void drawScore(Graphics gfx, boolean isFinalStage) {
    Graphics saved = gfx;
    if (m_scoreImage != null) {
      gfx = m_scoreImage.getGraphics();
    }

    gfx.setColor(255, 128, 128);

    //int width = m_offImage.getWidth();
    int height = m_offImage.getHeight() / 3;
    gfx.drawImage(m_offImage, 0, 0, 0);

    for (int i = 0; i <= m_roundNumber; ++i) {
      if (i < 6) {

        gfx.drawRect(20 + (i * SCORE_BOARD_WIDTH), height, SCORE_BOARD_WIDTH,
                     SCORE_BOARD_HEIGHT);
        gfx.drawRect(20 + SCORE_BOARD_WIDTH / 2 + (i * SCORE_BOARD_WIDTH),
                     height,
                     SCORE_BOARD_WIDTH / 2, SCORE_BOARD_HEIGHT / 2);
        gfx.setColor(255, 255, 255);
        if (i < m_roundNumber) {
          if ( (m_scene.m_player.m_scoreInfo.scores[i * 2] == 10) &&
              (m_scene.m_player.m_scoreInfo.scores[i * 2 + 1] == 0)) {
            //draw strike score board
            gfx.setColor(255, 128, 128);
            gfx.drawLine(20 + (i * SCORE_BOARD_WIDTH), height,
                         20 + (i * SCORE_BOARD_WIDTH) + SCORE_BOARD_WIDTH / 2,
                         height + SCORE_BOARD_HEIGHT / 2);
            gfx.drawLine(20 + (i * SCORE_BOARD_WIDTH) + SCORE_BOARD_WIDTH / 2,
                         height, 20 + (i * SCORE_BOARD_WIDTH),
                         height + SCORE_BOARD_HEIGHT / 2);
            if (m_scene.m_player.m_scoreInfo.totalScores[i] != -1) {
              gfx.setColor(255, 255, 255);
              gfx.drawString(Integer.toString(m_scene.m_player.m_scoreInfo.
                                              totalScores[i]),
                             20 + (i * SCORE_BOARD_WIDTH) +
                             SCORE_BOARD_WIDTH / 2 -
                             6, height + SCORE_BOARD_HEIGHT / 2,
                             Graphics.LEFT | Graphics.TOP);
              gfx.setColor(255, 128, 128);
            }
          }
          else {
            gfx.drawString(Integer.toString(m_scene.m_player.m_scoreInfo.scores[
                                            i *
                                            2]),
                           20 + (i * SCORE_BOARD_WIDTH) + 2, height,
                           Graphics.LEFT | Graphics.TOP);
            drawSecondScore(i, height, gfx, false, 0);
            gfx.setColor(255, 128, 128);
          }

⌨️ 快捷键说明

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