Page 173 - Learn To Program With Scratch
P. 173

try it out 6-4

                            Open the application and run it . Drag the two points to different locations on the
                            Stage and check the displayed equation . To enhance this application, try adding
                            a script to move Tutor sprite out of the way if it overlaps with the coordinates dis-
                            played by the Point1 and Point2 sprites .



                          Other Applications

                GuessMy   Now let’s discuss some games you’ll find in the extra resources for this book
              Number .sb2  (download the extra resources from http://nostarch.com/learnscratch/). The
                          supplementary material contains two classic games that you can explore on
                          your own. The first is a “guess my number” game. The application secretly
                          selects an integer at random between 1 and 100 and prompts the player to
                          guess that number. The application then tells the player whether the guess
                          was higher or lower than the secret number by displaying “too high” or “too
                          low,” respectively. The player has six chances to guess the secret number.
                          A correct guess wins the game; otherwise, it’s a loss.
             RockPaper .sb2  The second game allows the user to play Rock, Paper, Scissors against
                          the computer. The player makes a selection by clicking one of three but-
                          tons that represent rock, paper, or scissors. The computer makes a random
                          selection. The winner is selected according to the following rules: Paper
                          beats (wraps) rock, rock beats (breaks) scissors, and scissors beat (cut)
                          paper.



               Summary

                          In this chapter, you learned about the comparison operators in Scratch and
                          used them to compare numbers, characters, and strings. After that, you
                          learned about the if and if/else blocks and used them to make decisions
                          and control actions in several programs. You also learned how to use nested
                          if and if/else blocks for testing multiple conditions and applied this tech-
                          nique to develop a menu-driven application. You also learned about logical
                          operators as an alternative, and more concise, way to test multiple condi-
                          tions. Finally, you explored several complete applications that demonstrated
                          decision-making structures in action.
                             The next chapter will take you deeper into the Control palette, showing
                          you the various repetition structures available in Scratch and teaching you
                          how to use them to write even more powerful programs.











                                                                              Making Decisions   151

                                           www.it-ebooks.info
   168   169   170   171   172   173   174   175   176   177   178