Page 259 - Learn To Program With Scratch
P. 259

Wizard sprite

                                                                 OK sprite

                                                                 New sprite

                          Figure 9-32: The user interface for the Math Wizard application


                             The application contains three sprites: the Wizard sprite, which gives
                          the instructions to the player, and the OK and New sprites, for the OK and
                          New Game buttons, respectively. It also uses the two lists illustrated in
                          Figure 9-33.



                                                                   Answer of first puzzle



                                                                   Instructions for first puzzle




                                                                   End of first puzzle
                                                                   Answer of second puzzle
                                                                   ...






                          Figure 9-33: The two lists used by the Wizard sprite

                             The instr list (right) contains 11 puzzle records. Each record includes
                          (a) the answer of the puzzle, (b) the instructions, and (c) an empty ele-
                          ment to mark the end of that record. The entries in the list on the left
                          (named index) identify the starting index of each puzzle in the instr list.
                          For  example, the second element in the index list is 9, which means the
                          record of the second puzzle starts at the ninth position in the instr list, as
                          illustrated in Figure 9-33. Let’s outline a strategy for developing this game:
                          1.  When the user starts a new game, select a random number between 1
                             and 11 (because our game currently contains 11 puzzles).




                                                                                      Lists   237

                                           www.it-ebooks.info
   254   255   256   257   258   259   260   261   262   263   264