Esempio n. 1
0
  @Override
  public void render(float delta) {
    super.render(delta);

    // If the timer is running, keep incrementing the timer.
    if (timer.isRunning()) {
      game.getState().addTime(delta);
      game.getState().setRemainingTime(timer.getSeconds());
    }

    // The user should be able to leave during the game.
    if (Gdx.input.isKeyJustPressed(Input.Keys.BACK)
        || Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) {
      if (!paused && !game.getState().isTimeout()) {
        pauseGame();
      }
    }
  }
Esempio n. 2
0
  @Override
  public void show() {
    super.show();

    // Reset data
    if (!game.isRestoredState()) {
      game.getState().reset();
    } else {
      game.setRestoredState(false);
      if (game.getState().isTimeout()) {
        game.pushScreen(Screens.GAME_OVER);
      }
    }

    // The player is playing
    game.getState().setPlaying(true);
    score.setValue(game.getState().getScore());
    timer.setSeconds(game.getState().getRemainingTime());

    paused = running = askingLeave = false;

    if (!game.getState().isCountdownFinished()) {
      countdown(
          2,
          new Runnable() {
            @Override
            public void run() {
              game.getState().setCountdownFinished(true);

              // Start the game unless the user is leaving or is paused.
              if (!paused && !askingLeave) {
                running = true;
                board.setColoured(true);
                timer.setRunning(true);
                board.setTouchable(Touchable.enabled);
                game.player.playSound(SoundCode.SUCCESS);
              }
            }
          });
    } else {
      pauseGame();
    }
  }