Page 227 - Learn To Program With Scratch
P. 227

Tell the Hangman sprite to show its next costume.
                                                       Reduce the number of remaining trials by 1.
                                                       If the user has exhausted all trials.

                                                       Tell the Helper sprite to show the correct answer.
                                                       Then display an image that tells the user that he or
                                                       she has lost the game.
                                                       End the game.

                                                       If the user still has more trials, tell the Helper
                                                       sprite to show the remaining number of trials.

                          Figure 8-28: The ProcessWrongGuess procedure

                             If the player’s letter was correct, the ProcessCorrectGuess shown in
                          Figure 8-29 should be called instead of ProcessWrongGuess.





                                                             Tell the Helper sprite to show the
                                                             correctly guessed letter.
                                                             If there are no more letters to guess,
                                                             show the win costume and end the
                                                             game.



                          Figure 8-29: The ProcessCorrectGuess procedure

                             ProcessCorrectGuess broadcasts Update to show the letter the player
                          guessed correctly. It then checks the value of qmarkCount. If qmarkCount is 0,
                          the player has guessed all of the letters correctly, so the Driver sprite shows
                          its win costume and ends the game.




                                                    try it out 8-7
                            The Hangman program doesn’t validate the user input; you could enter a non-
                            alphabetic character or even an entire word . Modify the program so that it rejects
                            any invalid input by the user .







                                                                               String Processing   205

                                           www.it-ebooks.info
   222   223   224   225   226   227   228   229   230   231   232