samedi 8 août 2020

How can I do something at 9 and 109 and 209 etc, something else at 99 and 199 and 299 etc, and a sequence of other actions at all others ending in 9?

I have 1 sound that plays each time the score hits a number ending in 09.

I also have 4 sounds that play in sequence each time the score hits a number ending in 19, 29, 39, 49, 59, 69, 79, and 89.

I then I have 1 sound that plays each time the score hits a number ending in 99.

My code works but I feel like there should be a way to do this more elegantly.

          if (score == 9 || score == 109 || score == 209 ...) {
            play('sound1.mp3');
          }
          if (score == 19 || score == 59 || score == 119 || score == 159 ...) {
            play('sound2.mp3');
          }
          if (score == 29 || score == 69 || score == 129 || score == 169 ...) {
           play('sound3.mp3');
          }
          if (score == 39 || score == 79 || score == 139 || score == 179 ...) {
            play('sound4.mp3');
          }
          if (score == 49 || score == 89 || score == 149 || score == 189 ...) {
            play('sound5.mp3');
          }
          if (score == 99 || score == 199 ...) {
            play('sound6.mp3');
          }

Ideas? Please help me think about this like a programmer. :D

Aucun commentaire:

Enregistrer un commentaire