Beispiel #1
0
  @Override
  public void onTick(long elapsedTime) {

    if (timer.getElapsedTime() > MAX_TIME) {
      timer.stop();
      timer.setElapsedTime(MAX_TIME);
      finishGame(false);
    }
    updateTimerTime();
  }
Beispiel #2
0
  /**
   * Restore elapsed time
   *
   * @param load Bundle where the elapsed time can be found
   */
  private void restoreElapsedTime(Bundle load) {

    if (timer == null) {
      return;
    }

    timer.stop();
    timer.resetTime();
    timer.setElapsedTime(load.getLong(BUNDLE_ELAPSED_TIME, 0));
    updateTimerTime();
  }
Beispiel #3
0
  /** Create a new game depending on the current difficulty. */
  private void createGame() {

    Log.d(Game.class.getName(), "Create Game");

    creating = true;

    clickCount = 0;
    timer.stop();
    timer.resetTime();
    updateTimerTime();

    fieldCreationFragment.createNewZahlenschlange(difficulty);
  }
Beispiel #4
0
  @Override
  protected void onResume() {

    super.onResume();

    Log.d(
        Game.class.getName(),
        "Resume [creating, paused, finished, timerTime] "
            + creating
            + " "
            + paused
            + " "
            + finished
            + " "
            + timer.getElapsedTime());

    if (!creating) {
      if (fieldCreationFragment.getZahlenschlange() == null) {

        createGame();
      } else if (!paused && finished == GAME_FINISHED_NOT_YET) {

        startGame();
      } else {

        updateGridView();
      }
    }
  }
Beispiel #5
0
  /**
   * Store elapsed time
   *
   * @param save Bundle where the elapsed time will be stored
   */
  private void saveElapsedTime(Bundle save) {

    if (timer == null) {
      return;
    }

    save.putLong(BUNDLE_ELAPSED_TIME, timer.getElapsedTime());
  }
Beispiel #6
0
  /** Start or restart actual game instance. */
  private void startGame() {

    Log.d(Game.class.getName(), "Start Game");

    updateGridView();
    timer.start();
    paused = false;
  }
Beispiel #7
0
  /** Setting the result depending on finishing state and the elapsed time. Use before finish(). */
  private void updateResult() {

    Intent result = new Intent();
    result.putExtra(EXTRA_ELAPSED_TIME, (long) timer.getElapsedTime());
    result.putExtra(EXTRA_DIFFICULTY, (int) difficulty);
    result.putExtra(EXTRA_CLICK_COUNT, (int) clickCount);
    result.putExtra(EXTRA_MAX_NUMBER, (int) getMaxNumber());
    setResult((finished == GAME_FINISHED_SUCCESSFUL) ? RESULT_OK : RESULT_CANCELED, result);
  }
Beispiel #8
0
  @Override
  protected void onPause() {

    Log.d(
        Game.class.getName(),
        "Pause [creating, paused, finished, timerTime] "
            + creating
            + " "
            + paused
            + " "
            + finished
            + " "
            + timer.getElapsedTime());

    super.onPause();

    timer.stop();
  }
Beispiel #9
0
  /** Pause the actual game. */
  private void pauseGame() {

    Log.d(Game.class.getName(), "Pause Game");

    paused = true;

    timer.stop();
    updateTimerTime();
    showPauseDialog();
  }
Beispiel #10
0
  /**
   * Finish the actual game.
   *
   * @param successful True if the user successfully found a solution. False otherwise.
   */
  private void finishGame(boolean successful) {

    Log.d(Game.class.getName(), "Finish Game " + successful);

    finished = (successful) ? GAME_FINISHED_SUCCESSFUL : GAME_FINISHED_FAILED;

    timer.stop();
    updateTimerTime();

    timerPauseButton.setVisibility(ImageButton.INVISIBLE);
    finishButton.setVisibility(Button.VISIBLE);

    updateFinishButtonText();
  }