Exemplo n.º 1
0
 @Override
 public void onGameFinished() {
   Debug.c();
   stopTimer();
   Debug.showLong("Game Finished", this);
   showScoreActivity();
 }
Exemplo n.º 2
0
  private void startTimer() {
    Debug.c();
    if (mGameManager != null && !mGameManager.isGameFinished()) {
      // Game holds the timer
      // so need to start Game timer via GameManager
      mGameManager.startTimer();

      TimerTask timerTask =
          new TimerTask() {
            @Override
            public void run() {
              runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      updateTimeElapsed(mGameManager.getElapsedTime());
                    }
                  });
            }
          };

      mTimer = new Timer();

      mTimer.schedule(timerTask, 0, 1000);
    }
  }
Exemplo n.º 3
0
 @Override
 protected void onResume() {
   super.onResume();
   Debug.c();
   if (mGameManager != null) {
     startTimer();
   }
 }
Exemplo n.º 4
0
 private void stopTimer() {
   Debug.c();
   if (mGameManager != null && mTimer != null) {
     mGameManager.stopTimer();
     mTimer.cancel();
     mTimer = null;
   }
 }
Exemplo n.º 5
0
 @Override
 public void updateTimeElapsed(long elapsedTime) {
   int elapsedTimeInSeconds = (int) elapsedTime / 1000;
   int remainingTime = (GameConstants.GAME_DURATION - elapsedTimeInSeconds);
   String toShow;
   if (remainingTime > 0) {
     toShow = getResources().getString(R.string.time) + " " + remainingTime;
   } else {
     toShow = "Time's Up";
     mGameManager.finishGame();
   }
   Debug.i(String.valueOf(elapsedTimeInSeconds), false);
   timeTextView.setText(toShow);
 }
Exemplo n.º 6
0
 private void setupGame() {
   Debug.c();
   mGameManager = new GameManager(mBoardLayoutView, this);
 }