1

I got a problem, the game only ends after losing the 3 lives, but after destroying all bricks it doesnt... anybody know what is happening? I noticed that the condition was while(lives > 0 && bricks <= 0) and I already tried puting || instead of &&...

1 Answer 1

1

Are you decrementing the bricks value each time you remove a brick?

Also, the distribution code says:

// keep playing until game over
while (lives > 0 && bricks > 0)
{
    // TODO
}

You must have changed the condition to bricks <=0 which is why it's not working.

6
  • there is no other loop inside, mine is written like this: while (lives > 0 || bricks <= 0) and I am decreasing the bricks Jun 23, 2014 at 23:58
  • so you are telling the game to keep running while you still have a life OR while you have no bricks. Can you see why when you run out of bricks, the game keeps going? Shouldn't you only continue the game while you have bricks?
    – curiouskiwi
    Jun 24, 2014 at 0:02
  • So, the && will make me play the game until both happen, i have no brics and no lifes... The || says its good to finish the game when any of this conditions are true I think I found it, i put brics <=0 not > Jun 24, 2014 at 0:28
  • Yes, now it works, thank you Jun 24, 2014 at 0:33
  • The && means that the game will only keep going if both are true, so if either is false (you run out of lives or you run out of bricks), the game will stop. Remember, a while loop isn't "do this until"... it's "keep doing this as long as this is true".
    – curiouskiwi
    Jun 24, 2014 at 0:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .