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

📄 cgameplay.java

📁 一个3D的保龄球的源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        if (m_rotationPower < CPlayer.MAX_PLAYER_ROTATION)//m_scene.m_player.m_rotation) //    MAX_ROTATION_POWER)
          ++m_rotationPower; //increase the rotation power
        break;
        //		case CGameMain.gk_A: //confirm go to PLAYER_POWER_CONFIRM
        //			m_staRound = BALL_RUNNING;
        //			break;
      default:
        break;
    }
    //System.out.println(m_rotationPower);
  }

  /**
   * DEBUG: Control the power that player will use
   */
  private void playerPowerAdjust() {
    switch (m_keyCode) {
      /*case CGameMain.gk_LEFT:
       if ((m_playerPower) > (0)) // - (m_scene.getPlayer().getStrength())))
       --m_playerPower; //decrease the player power
       break;
       case CGameMain.gk_RIGHT:
       if ((m_playerPower) < m_scene.m_player.m_strength) //MAX_PLAYER_POWER)
       ++m_playerPower; //increase the player power
       break;*/
      case CGameMain.gk_A: //confirm go to BALL_RUNNING state

        //calculatePath();  //compute the path that the ball will pass???Milo
        /*if (m_isSecondBall)
         m_scene.setInitTenpinsState(m_scene.getTenpinState());
         else
         m_scene.setInitTenpinsState(CScene.ALL_TENPINS_STAND);*/

        if (m_playerPower > 96)
          m_playerPower = 192 - m_playerPower;
        m_scene.setInitBallState( (m_playerPower / 10),
                                 m_aimSpot, m_scene.m_playerPosition[0]);

        m_staRound = PLAYER_ACCURACY_CONFIRM;

        break;
      default:
        break;
    }
    //System.out.println(m_playerPower);
  }

  /**
   * DEBUG: Deciding which the next state in this gameplay lifecycle is
   */
  private void getNextStop() {
    if (m_keyCode == CGameMain.gk_LEFT_SOFT) { //take "recall"
      //go to Running State (without calculatePath(); ???)
      m_staRound = BALL_RUNNING;
    }
    else {
      if (m_keyCode == CGameMain.gk_A) { //take "continue"
        if (m_roundNumber < MAX_ROUND_NUMBER) { //go to Player Position
          //(there 2 possibilities: a. new rounds ++m_roundNumber, b.the 2 ball in this round)
          if (m_isStrike) {
            ++m_roundNumber;
            m_isStrike = false;
            m_isSecondBall = false;
          }
          else {
            if (m_isSecondBall) {
              ++m_roundNumber;
            }
            m_isSecondBall = !m_isSecondBall;
          }
          setInitTenpinState();
          m_staRound = PLAYER_POSITION_CONFIRM;
          System.out.println("continue");
          restart();
        }
        else { //deal with last round in one match
          if (!m_isBonusShot) {
            if (m_isStrike) {
              m_isStrike = false;
              m_isSecondBall = false;
              m_isBonusShot = true;
            }
            else {
              if (m_isSecondBall) {
                calculateAfterCollision(); //Milo8/24
                m_staRound = MATCH_FINISH;
                System.out.println("Match FINISH");
                return;
              }
              m_isSecondBall = !m_isSecondBall;
            }
            setInitTenpinState();
            m_staRound = PLAYER_POSITION_CONFIRM;
            System.out.println("continue");
            restart();
          }
          else {
            if (m_isStrike) {
              calculateAfterCollision(); //Milo8/24
              m_staRound = MATCH_FINISH;
              System.out.println("Match FINISH"); // the first ball in last round is strike??
              return;
            }
            else {
              if (m_isSecondBall) {
                calculateAfterCollision(); //Milo8/24
                m_staRound = MATCH_FINISH;
                System.out.println("Match FINISH");
                return;
              }
              else {
                m_isSecondBall = !m_isSecondBall;
                setInitTenpinState();
                m_staRound = PLAYER_POSITION_CONFIRM;
                System.out.println("continue");
                restart();
              }
            }
          }
        }
      }
    }

    if (m_keyCode == CGameMain.gk_LEFT && m_offSet < m_roundNumber - 5) {
      m_offSet += 1;
      m_isScoreBoardChanged = true;
    }

    if (m_keyCode == CGameMain.gk_RIGHT && m_offSet > 0) {
      m_offSet -= 1;
      m_isScoreBoardChanged = true;
    }

  }

  private void dealWithFinish() {
    if (m_keyCode == CGameMain.gk_LEFT && m_offSet < m_roundNumber - 5) {
      m_offSet += 1;
      m_isScoreBoardChanged = true;
    }

    if (m_keyCode == CGameMain.gk_RIGHT && m_offSet > 0) {
      m_offSet -= 1;
      m_isScoreBoardChanged = true;
    }

    if (m_keyCode == CGameMain.gk_RIGHT_SOFT) { //take "RESTART NEW ROUND"
      //do init
      m_staRound = ROUND_INIT;
      restart();
      System.out.println("ROUND NUMBER IS ||||||++++++" + m_roundNumber);
      iniScoreInfo(m_scene.m_player.m_scoreInfo);

      m_tenpinState = 0;
      m_isSecondBall = false;
      m_roundNumber = 0;
      m_isBonusShot = false;
      initRound();

    }
  }

  /**
   * DEBUG: Draw the scene when user selects the player position.
   */
  private void showPlayerPositionStage(Graphics g) {
    //System.out.println(m_playerPositionX);
    g.setColor(0, 255, 0);
    g.drawString("selecting player position!", 50, 50, Graphics.LEFT
                 | Graphics.TOP);
  }

  /**
   * DEBUG: Draw the scene when user selects aim spot.
   */
  private void showAimSpotStage(Graphics g) {
    //System.out.println("selecting aim spot!");
    g.setColor(0, 255, 0);
    g.drawString("selecting aim spot!", 20, 200, Graphics.LEFT
                 | Graphics.TOP);
  }

  /**
   * Draw the scene when user selects rotation power.
   */
  private void showRotationPowerStage(Graphics g) {
    //System.out.println("selecting rotation power!");
    g.setColor(0, 255, 0);
    g.drawString("selecting rotation power!", 20, 200, Graphics.LEFT
                 | Graphics.TOP);
  }

  /**
   * Draw the scene when user selects player power.
   */
  private void showPlayerPowerStage(Graphics g) {
    //System.out.println("selecting player power!");
    g.setColor(0, 255, 0);
    g.drawString("selecting player power!", 20, 200, Graphics.LEFT
                 | Graphics.TOP);
  }

  /**
   * Draw the scene after the ball was thrown until the ball knocks the tenpin (Skittle).
   */
  private void showRunningStage(Graphics g) {

    //g.drawString("Running!" + "Press 0 to finish!", 50, 90,
    //Graphics.LEFT | Graphics.TOP);

    g.setColor(0, 255, 0);
    for (int i = 0; i < 10; ++i) {
      if (m_scene.m_tenpin[i].m_tenpinState == CTenpin.TENPIN_STATE_STAND) {
        //int m = m_scene.m_tenpin()[i].m_tenpinPosition()[1];
        g
            .drawString(
            "P" + i,
            m_scene.m_tenpin[i].m_tenpinPosition[0]
            / def.DEFAULT_EXTEND,
            ( - (m_scene.m_tenpin[i].m_tenpinPosition[1] - def.LANE_LENGTH) /
             def.DEFAULT_EXTEND)
            + CScene.ZERO_POSITION_Y, Graphics.LEFT
            | Graphics.TOP); // - CScene.LANE_LENGTH) / def.DEFAULT_EXTEND

      }
    }
    g.setColor(0, 0, 255);
    //int m = m_scene.getCurrentBallPosition()[0];
    //int n = m_scene.getCurrentBallPosition()[1];
    //System.out.println(m+"        "+n);
    if (!m_scene.isFinished()) {
      g.drawString("B", m_scene.getCurrentBallPosition()[0]
                   / def.DEFAULT_EXTEND, (def.LANE_LENGTH - m_scene
                                          .getCurrentBallPosition()[1])
                   / def.DEFAULT_EXTEND + CScene.ZERO_POSITION_Y,
                   Graphics.LEFT | Graphics.TOP);
    }
  }

  /**
   *
   */
  private void showCollisionFinish(Graphics g) {
    //System.out.println("Round Finish!");
    /*int oldColor;
     oldColor = g.getColor();

     g.drawString("Collision Finish!", 50, 100, Graphics.LEFT | Graphics.TOP);
     g.setColor(0, 255, 0);

     int check = 0x0001;
     for (int i = 0; i < 10; i++) {
     if ( ( (m_tenpinState & check) >> i == 1)) { //true for the stand tenpin
     g.drawString("P" + i,
     m_scene.m_tenpin[i].m_tenpinPosition[0] /
     def.DEFAULT_EXTEND,
     ( - (m_scene.m_tenpin[i].m_tenpinPosition[1] -
     CScene.LANE_LENGTH) / def.DEFAULT_EXTEND) +
     CScene.ZERO_POSITION_Y, Graphics.LEFT | Graphics.TOP); // - CScene.LANE_LENGTH) / def.DEFAULT_EXTEND

     }
     check = check << 1;
     }
     g.setColor(oldColor);
     displayButton(g, "CONTINUE");
     displayButton(g, "RECALL");
     g.drawString("round is:" + (m_roundNumber+1), 40,60, Graphics.LEFT | Graphics.TOP);*/
    g.setColor(0, 255, 0);
    g.drawString("score is:"
                 + m_scene.m_player.m_scoreInfo.totalScores[m_roundNumber], 20,
                 200, Graphics.LEFT | Graphics.TOP);
  }

  private void showMatchFinish(Graphics g) {
    g.setColor(255, 255, 255);
    g.drawString("Match Finish!", 50, 160, Graphics.LEFT | Graphics.TOP);

    g.drawString("PRESS RIGHT SOFT KEY & Then PRESS * ", 20, 180,
                 Graphics.LEFT | Graphics.TOP);
    g.drawString("KEY TO RESTART GAME AGAIN!!!", 20, 200, Graphics.LEFT
                 | Graphics.TOP);

    g.drawString("total score is:"
                 + m_scene.m_player.m_scoreInfo.totalScores[10], 40, 140,
                 Graphics.LEFT | Graphics.TOP);
    /*for (int i = 0; i < 10; ++i) {
      g.drawString("total score on " + i + "  is:"
                   + m_scene.m_player.m_scoreInfo.totalScores[i], 0, 10 * i,
                   Graphics.LEFT | Graphics.TOP);
         }*/

  }

  private void initRound() {

    if (m_keyCode == CGameMain.gk_D) {
      setInitTenpinState();
      m_staRound = PLAYER_POSITION_CONFIRM;
    }
  }

  public void setRoundState(byte sta) {
    this.m_staRound = sta;
  }

  ////about display soft button
  /**
   *
   * @param g Graphics
   * @param menu String - menu name
   */
  protected void displayButton(Graphics g, String menu) {
    int x;
    if (menu == "CONTINUE" || menu == "MENU" || menu == "OK"
        || menu == "GREEN") { //at right
      x = def.DISPLAY_WIDTH - stringWidth(menu) - 4;
    }
    else { //at left
      x = 2;
    }

    g.setColor(0, 0, 0);
    g.drawString(menu, x, def.DISPLAY_HEIGHT - 60, Graphics.LEFT
                 | Graphics.TOP);
    //x1 +(0- stringWidth(menu)) / 2 g.drawString("CONTINUE",0,, Graphics.LEFT | Graphics.TOP );
  }

  /**
   * get the string width in pixel
   * @param str string
   * @return the string width in pixel
   */
  private int stringWidth(String str) {
    // get the string width in pixel
    int nRet = 0;
    // add every character width together
    for (int i = 0; i < str.length(); i++) {
      //nRet += charWidth(str.charAt(i));  //modified by Milo
      nRet += 5;
    }
    // add characters space
    nRet += str.length() - 1;
    //
    return nRet;
  }

  private int charWidth(char c) {
    // get the character width in pixel
    // default character width
    int iRet = def.iCharWidth;
    //
    if (def.s1WidthChars.indexOf(c) >= 0) {
      // 1 pixel width character
      iRet = 1;
    }
    else if (def.s2WidthChars.indexOf(c) >= 0) {
      // 2 pixel width character
      iRet = 2;
    }
    else if (def.s4WidthChars.indexOf(c) >= 0) {
      // 4 pixel width character
      iRet = 4;
    }
    else if (def.s5WidthChars.indexOf(c) >= 0) {
      // 5 pixel width character
      iRet = 5;
    }
    //
    return iRet;
  }

  private void step() {
    //according to state of ball, deciding the whole state...

⌨️ 快捷键说明

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