Page 214 - Learn To Program With Scratch
P. 214

Now that we have our Insert procedure, let’s look at the main script of
                         the game, shown in Figure 8-9.



                                                                        
                                                                        
                                                                        

                                                                        
                                                                        
                                                                        
                                                                     




                                                                






                         Figure 8-9: The main script for the Fix My Spelling game

                             The alpha string contains all the letters of the alphabet. It will provide
                         the random letter to insert into the word we want to misspell u. The script
                         randomly picks a word from a premade list and saves that word as inWord v.
                         You’ll learn more about lists in the next chapter; for now, just think of this
                         list as a word bank. The script then selects a random letter (randChar) from
                         alpha w and a random position (randPos) to place this letter into inWord x.
                         The script then calls our Insert procedure to create the misspelled word
                         (strOut) y. After that, the script starts a loop to get the player’s answer z.
                         Inside the loop, the script asks the player to enter the correct spelling {,
                         and it uses an if/else block to check the answer |. If the player’s answer
                         matches the original word (inWord), the game ends; otherwise, the player
                         has to try again.



                                                   try it out 8-3

            FixMySpelling   Load FixMySpelling.sb2 and play it several times to understand how it works .
                     .sb2   Can you modify the game such that the corrupt word contains two additional
                              letters instead of just one?









           192   Chapter 8
                                           www.it-ebooks.info
   209   210   211   212   213   214   215   216   217   218   219