示例#1
0
  @Override
  public void onTimeOut() {
    // Disable any further interactions.
    board.clearSelection();
    board.setColoured(true);
    board.setTouchable(Touchable.disabled);
    timer.setRunning(false);
    game.player.playSound(SoundCode.GAME_OVER);

    // Update the score... and the record.
    int score = game.getState().getScore();
    int time = Math.round(game.getState().getElapsedTime());
    game.getPlatform().score().registerScore(score, time);
    game.getPlatform().score().flushData();

    // Save information about this game in the statistics.
    game.statistics.getTotalData().incrementValue("score", game.getState().getScore());
    game.statistics.getTotalData().incrementValue("games");
    game.statistics
        .getTotalData()
        .incrementValue("time", Math.round(game.getState().getElapsedTime()));
    game.getPlatform().statistics().saveStatistics(game.statistics);

    // Mark a combination that the user could do if he had enough time.
    if (game.getState().getWiggledBounds() == null) {
      CombinationFinder combo = CombinationFinder.create(game.getState().getBoard());
      game.getState().setWiggledBounds(combo.getCombination());
    }
    for (int y = 0; y < game.getState().getBoard().getSize(); y++) {
      for (int x = 0; x < game.getState().getBoard().getSize(); x++) {
        if (game.getState().getWiggledBounds() != null
            && !game.getState().getWiggledBounds().inBounds(x, y)) {
          board.getBall(x, y).addAction(Actions.color(Color.DARK_GRAY, 0.15f));
        }
      }
    }

    // Animate the transition to game over.
    board.addAction(Actions.delay(2f, board.hideBoard()));
    hud.addAction(Actions.delay(2f, Actions.fadeOut(0.25f)));

    // Head to the game over after all these animations have finished.
    getStage()
        .addAction(
            Actions.delay(
                2.5f,
                Actions.run(
                    new Runnable() {
                      @Override
                      public void run() {
                        getStage().getRoot().clearActions();
                        game.pushScreen(Screens.GAME_OVER);
                      }
                    })));

    // Mark the game as finished.
    game.getState().setTimeout(true);
  }