@Override public void onTick(long elapsedTime) { if (timer.getElapsedTime() > MAX_TIME) { timer.stop(); timer.setElapsedTime(MAX_TIME); finishGame(false); } updateTimerTime(); }
/** * 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(); }
/** 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); }
@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(); } } }
/** * 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()); }
/** Start or restart actual game instance. */ private void startGame() { Log.d(Game.class.getName(), "Start Game"); updateGridView(); timer.start(); paused = false; }
/** 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); }
@Override protected void onPause() { Log.d( Game.class.getName(), "Pause [creating, paused, finished, timerTime] " + creating + " " + paused + " " + finished + " " + timer.getElapsedTime()); super.onPause(); timer.stop(); }
/** Pause the actual game. */ private void pauseGame() { Log.d(Game.class.getName(), "Pause Game"); paused = true; timer.stop(); updateTimerTime(); showPauseDialog(); }
/** * 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(); }