1
目前我有一个简单的射击游戏,其中精灵在屏幕上飞行,当他们被按下时,它会增加一个用户的分数。问题是我想拥有它,所以我已经为gameover声明了一个布尔值,当游戏开始时,它将被初始化为false,并在定时器耗尽时声明为true。我目前使用的代码是这样的,当定时器耗尽时gameover被设置为true,但由于某种原因,而不是默认为true,而不是等待定时器耗尽。任何想法为什么这是?游戏结束无法正常工作?
/* Member (state) fields */
private GameLoopThread gameLoopThread;
private Paint paint; //Reference a paint object
/** The drawable to use as the background of the animation canvas */
private Bitmap mBackgroundImage;
private Sprite sprite;
private int hitCount;
/* For the countdown timer */
private long startTime ; //Timer to count down from
private final long interval = 1 * 1000; //1 sec interval
private CountDownTimer countDownTimer; //Reference to class
private boolean timerRunning = false;
private String displayTime; //To display time on the screen
private boolean gameOver;
private int highscore = 0;
/* Countdown Timer - private class */
private class MyCountDownTimer extends CountDownTimer {
public MyCountDownTimer(long startTime, long interval) {
super(startTime, interval);
}
public void onFinish() {
displayTime = "Times Over!";
timerRunning = false;
countDownTimer.cancel();
gameOver = true;
if (hitCount > highscore) {
highscore= hitCount;
}
}
public void update(){
//if (gameOver = true){
sprite.update();
//}
}
没错这个做到了,我会评论说出来,以确保游戏将运行相等验证工作。 – kendrick