Hello all,
I am helping a student with a final project that is a matching game she has been making. She has decided to make a matching game that includes images and sounds to help some of her peers in a music theory class match up composers to the compositions that they created. The issue that she is running into is that the image on the cards connected to the mp3s of the compositions will not change until after the music has played even though the command to change the image for the card is before the while statement in the code. Below is an example of the code:
She decided to use a while statement to ensure that only one music card could be clicked on at a time and that the user would not be able to select a different card before the selection from the composition was finished playing.
The first part of the question is why would the loop execute before the image for the card is changed? The second part of the question, and I am sure it is a simple oversight on my part, is why would the image for the card eventually change when the music has stopped playing? The commands are not being executed in the order explicitly stated in the program, but all commands are being run through and successfully completing, just not as expected.
Any help would be appreciated.
Cheers!
Sean
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | if (Greenfoot.mouseClicked( this ) &&isClicked == false && cardOneValue == 0 ) { if (matchingValue.contains( ".png" )) { setImage(matchingValue); } if (matchingValue.contains( ".mp3" )) { setImage(backCard); GreenfootSound sound = new GreenfootSound(matchingValue); sound.play(); while (sound.isPlaying()) { isSoundPlaying = true ; } } isClicked = true ; clickNumber = clickNumber + 1 ; cardOneValue = variableValue; } if (Greenfoot.mouseClicked( this ) && isClicked == false && cardOneValue != 0 && isSoundPlaying == false ) { if (matchingValue.contains( ".png" )) { setImage(matchingValue); } if (matchingValue.contains( ".mp3" )) { setImage(backCard); flip = true ; if (flip == true ) { GreenfootSound sound = new GreenfootSound(matchingValue); sound.play(); while (sound.isPlaying()) { isSoundPlaying = true ; } } } isClicked = true ; clickNumber = clickNumber + 1 ; cardTwoValue = variableValue; } |