私の新しいゲームでは、ポイントを得るためにボタンを押す必要があります。プレーヤーは5秒以内にボタンを押す必要があります。時間がかかると、GameOverScreenが開きます。それ以外の場合は、カウントダウンが再開されます。私はgameover();
メソッドをカウントダウンのfinish()
メソッドに入れようとしましたが、finishメソッドが常に開始され、キャンセルされない可能性があります。それを行うためにカウントダウンを停止するにはどうすればよいですか?このようなカウントダウン後のアンドロイドオープン活動
public class GameScreen extends Activity {
public int score = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
Button count = (Button) findViewById(R.id.button1);
text = (TextView) this.findViewById(R.id.textView3);
tvscore = (TextView) findViewById(R.id.score);
timer();
}
public void gameover() {
Intent intent = new Intent(this, GameOverScreen.class);
startActivity(intent);
}
public void onClick (View view) {
score++;
tvscore.setText(String.valueOf(score));
timer();
}
public void timer(){
new CountDownTimer(5000, 10) {
public void onTick(long millisUntilFinished) {
text.setText(""+String.format("%02d:%03d",
TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished)),
TimeUnit.MILLISECONDS.toMillis(millisUntilFinished) - TimeUnit.SECONDS.toMillis(TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished))
));
if(animationRunning) {
cancel();
}
}
public void onFinish() {
text.setText("Too slow.");
gameover();
}
}.start();
}
}
私はあなたのカウントダウンタイマー – Anjali