Из-за многих булевых проверок я немного смущен, позвольте мне представить мне следующий код.Не понимаю, почему эта петля не достигает
} else {
//check whether the player starts again. the first time we lose the player
//will definitely get into this loop
if(!startAgain){
// we only do this to set a timer, we don't want to start a new game so we set this
// to false
newgame = false;
startAgain = true;
deadTime = System.nanoTime();
}
deadTimepassed = (System.nanoTime() - deadTime)/1000000;
if((deadTimepassed < 2000) && (newgame = false)){
newGame();
}
}
}
Это заявление можно рассматривать как первый раз, когда игрок получает удар вражеской ракеты. Сделать взрыв-анимацию. Мне нужно, чтобы экран замерзал в течение 2 секунд, а затем снова начал игру. Я не понимаю, почему второе утверждение никогда не достигается. Вот мои ontouch методы и мой новый метод игры:
@Override
public boolean onTouchEvent(MotionEvent event) {
//What happens when the player touches the screen!
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Boolean check for when player is playing, if he isn't the chopper does nothing.
// we see that the chopper only hangs still if all these booleans are true!
if ((!player.isPlaying()) && (newgame = true) && (startAgain = true)) {
player.setPlaying(true);
} if(player.isPlaying()) {
player.setUp(true);
startAgain = false;
}
return true;
}
if (event.getAction() == MotionEvent.ACTION_UP) {
player.setUp(false);
return true;
}
return super.onTouchEvent(event);
}
public void newGame(){
newgame = true;
missles.clear();
if(player.getScore()>best) {
best = player.getScore();
SharedPreferences.Editor editor = saveBest.edit();
editor.putInt("new best",best);
editor.commit();
}
player.resetScore();
player.setY(HEIGHT/2);
}
Как можно видеть, новая игра просто сбрасывает позиции игроков, единственное, что я хочу сделать, это просто заморозить экран за 2 секунды до того, что происходит , это должно произойти во втором, если заявление, но оно никогда не достигнет ...
Любые предложения?
ps: deadTimepassed вводится как «частный длинный» только под методом открытого класса.
'newgame = false' - это задание. Это должно быть '! Newgame'. –
Могу ли я также использовать newgame == false (просто из любопытства, поэтому я понимаю, почему это не удается) –
@KeesTil да, вы можете – brso05