私はAndroidゲームを書いています。メインゲーム画面にはカウントダウンタイマーがあり、ゼロになるとゲームオーバーです。以下のコードは、ユーザーがレベルを初めてプレイするときに機能します。ただし、ユーザーが 2 番目のレベルをプレイする約 5 回ごとに、生成される数字はランダムになります。たとえば、30 から始まり、その後 -15 になりました。誰でもこれを行う理由を提案できますか?
public class Timer1 {
int time = 120;
int counter = 0;
int startTime = 30; // Change to 2 minutes
Timer timer;
boolean end = false;
World world = new World();
public Timer1() {
}
public void subtractTime() {
startTime = startTime - 15; // Knock off 15 seconds for hint
}
public int getTime() {
return time;
}
public void startTimer() {
timer = new Timer();
time = 120;
startTime = 30;
end = false;
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
counter++;
time = startTime - counter;
if (time == 0) {
world.gameOver = true;
end = true;
timerCancel();
}
}
}, 0, 1000);
}
public void timerCancel() {
timer.cancel();
}
}