Exemplo n.º 1
0
  /**
   * Updates the state and the change the background music accordingly.
   *
   * @param state
   */
  public void changeState(int state) {
    if (this.state != state) {
      stopPreviousState(state);
      switch (state) {
        case StateManager.STATE_MENU:
          if (!SoundEffect.MENU.isPlaying()) SoundEffect.MENU.play(Clip.LOOP_CONTINUOUSLY);
          break;
        case StateManager.STATE_SELECTION:
          if (!SoundEffect.MENU.isPlaying()) SoundEffect.MENU.play(Clip.LOOP_CONTINUOUSLY);
          break;
        case StateManager.STATE_GAME:
          if (random.nextBoolean()) SoundEffect.GAME1.play(Clip.LOOP_CONTINUOUSLY);
          else SoundEffect.GAME2.play(Clip.LOOP_CONTINUOUSLY);
          break;
        case StateManager.STATE_WIN:
          SoundEffect.WIN.play(Clip.LOOP_CONTINUOUSLY);
          break;

        default:
          break;
      }
    }

    this.state = state;
  }