Page 204 - Learn To Program With Scratch
P. 204

try it out 7-10
                           Open the application and run it to understand how it works . Then try converting this
                           simulation into a game . You could, for example, show an object at a random height
                           at the right edge of the stage and ask the player to try to hit it . If the player misses the
                           target, the game can provide some hints on adjusting the firing angle and velocity .



                         Other Applications
               MatchThat   The extra resources for this book (available at http://nostarch.com/
              Amount .sb2  learnscratch/) contain three more games that you can explore on your
                         own, with full explanations of each script. The first is an educational
                         game that can be used to test the counting skills of elementary students.
                         It shows an amount of money in pennies and asks the player to find the
                         smallest number of coins needed to get that amount.
                Orbit .sb2   The second application is a planetary motion simulation for a simple
               Molecules   solar system that contains a sun and a single planet. The third application
             InMotion .sb2  is also a simulation, this one demonstrating the dynamics of motion as a
                         single gas molecule collides with the walls of a container.
                             Open up these applications, run them, and read through my explana-
                         tions to understand how they work. If you feel inspired to flex your pro-
                         gramming muscles, try modifying the scripts to make them do new things!


              Summary

                         In this chapter, we explored different ways to repeat commands in Scratch.
                         We first examined the various loop blocks and explained the technical
                         terms associated with them. Then, we discussed definite and indefinite loops
                         and the difference between counter-controlled and condition-controlled
                         loops. We explored the repeat until block and the forever if structure and
                         used them in several examples. I also explained Scratch’s stop commands
                         and how you can use them to stop infinite loops and procedures. From there,
                         we went on to discuss using loops to validate data from user input.
                             You then learned how to use counters to keep track of how many
                           iterations of a loop have passed and how to use counters with nested loops
                         to create iterations in two or more dimensions. After that, we looked at
                         recursion—a procedure calling itself—as another way to achieve repetition.
                         In the last section, we developed several applications that tied these new
                         concepts together to create practical programs.
                             The next chapter will expand on the topics you learned here and teach
                         you how to use counters and loops to process strings and create a different
                         class of interesting programs, such as a binary to decimal converter, a hang-
                         man game, and a math tutor for teaching fractions.
                             If you want to further explore the new concepts from this chapter, I
                         suggest trying out some of the following problems.



           182   Chapter 7
                                           www.it-ebooks.info
   199   200   201   202   203   204   205   206   207   208   209