コード例 #1
0
ファイル: Game.java プロジェクト: brunothg/SnakingNumbers
  @Override
  public void onTick(long elapsedTime) {

    if (timer.getElapsedTime() > MAX_TIME) {
      timer.stop();
      timer.setElapsedTime(MAX_TIME);
      finishGame(false);
    }
    updateTimerTime();
  }
コード例 #2
0
ファイル: Game.java プロジェクト: brunothg/SnakingNumbers
  /**
   * 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();
  }
コード例 #3
0
ファイル: Game.java プロジェクト: brunothg/SnakingNumbers
  /** 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);
  }
コード例 #4
0
ファイル: Game.java プロジェクト: brunothg/SnakingNumbers
  @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();
      }
    }
  }
コード例 #5
0
ファイル: Game.java プロジェクト: brunothg/SnakingNumbers
  /**
   * 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());
  }
コード例 #6
0
ファイル: Game.java プロジェクト: brunothg/SnakingNumbers
  /** Start or restart actual game instance. */
  private void startGame() {

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

    updateGridView();
    timer.start();
    paused = false;
  }
コード例 #7
0
ファイル: Game.java プロジェクト: brunothg/SnakingNumbers
  /** 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);
  }
コード例 #8
0
ファイル: Game.java プロジェクト: brunothg/SnakingNumbers
  @Override
  protected void onPause() {

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

    super.onPause();

    timer.stop();
  }
コード例 #9
0
ファイル: Game.java プロジェクト: brunothg/SnakingNumbers
  /** Pause the actual game. */
  private void pauseGame() {

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

    paused = true;

    timer.stop();
    updateTimerTime();
    showPauseDialog();
  }
コード例 #10
0
ファイル: Game.java プロジェクト: brunothg/SnakingNumbers
  /**
   * 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();
  }