I want to program a game for Android.
Principle of the game: the user must have a short time to select the correct answer.
My problem is the combination between input (choice of answer) and time (countdown). I tried to start the stream, but the stream does not stop. Thus, the user gives an answer, the next action will be shown and after a while (when the "timer" becomes 0), the activity will be shown again.
Thread, Handler, CountDownTimer
You can save the timer start using this during initialization:
Timer updateTimer = new Timer("update"); updateTimer.scheduleAtFixedRate(new TimerTask() { public void run() { updateGUI(); } }, 0, 1000); long startTime = System.currentTimeMillis();
Then in the stream:
//Clock update currentTime = System.currentTimeMillis() - startTime; SimpleDateFormat sdf = new SimpleDateFormat("mm:ss"); clock.setText(sdf.format(currentTime)); clock.invalidate();
, ?
, , , , . , :/
boolean userHasAnswered = false.
boolean userHasAnswered = false
(, ) . , userHasAnswered = true.
userHasAnswered = true
, , .
ans, , loadNextQuestion().
loadNextQuestion()
, , userHasAnswered == true, , updateScore() loadNextQuestion().
userHasAnswered == true
updateScore()
You can see the alarm manager