19.04.2017 Views

Learn to Program with Small Basic

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Create a Game: Guess My Coordinates ................................. 122<br />

Step 1: Open the Startup File .................................. 123<br />

Step 2: Set Up the Game ..................................... 123<br />

Step 3: Hide the Star. ....................................... 124<br />

Step 4: Let the User Guess .................................... 126<br />

Try It Out 9-4 .......................................... 127<br />

<strong>Program</strong>ming Challenges ........................................... 127<br />

10<br />

Solving Problems <strong>with</strong> Subroutines 129<br />

Why Use Subroutines? ............................................. 130<br />

Writing Subroutines ............................................... 130<br />

Try It Out 10-1 ......................................... 133<br />

Subroutine Input and Output ......................................... 133<br />

Try It Out 10-2 ......................................... 135<br />

Nesting Subroutines ............................................... 135<br />

Try It Out 10-3 ......................................... 138<br />

Create a Dragon Game ............................................ 138<br />

Step 1: Open the Startup File .................................. 139<br />

Step 2: Write the SetUp() Subroutine ............................. 140<br />

Step 3: Add a Bit of Chance .................................. 141<br />

Step 4: Let the Player Know What’s Going On ...................... 142<br />

Step 5: Get the Player in the Game <strong>with</strong> GetChoice() ................. 142<br />

Step 6: Process the Player’s Choice .............................. 143<br />

Step 7: Add Motion <strong>with</strong> MoveKnight() ........................... 143<br />

Step 8: Shoot Arrows <strong>with</strong> ShootArrow() .......................... 145<br />

Step 9: Swing the Sword <strong>with</strong> StabDragon(). ....................... 146<br />

Step 10: Breathe Fire. ....................................... 146<br />

Try It Out 10-4 ......................................... 147<br />

<strong>Program</strong>ming Challenges ........................................... 147<br />

11<br />

Event-Driven <strong>Program</strong>ming 149<br />

GraphicsWindow Events. ........................................... 151<br />

Create Patterns <strong>with</strong> the MouseDown Event ........................ 151<br />

Try It Out 11-1 ......................................... 152<br />

Fire Missiles <strong>with</strong> the KeyDown Event. ............................ 152<br />

Try It Out 11-2 ......................................... 154<br />

Make a Typewriter Using the TextInput Event ....................... 154<br />

Try It Out 11-3 ......................................... 155<br />

Draw Pictures <strong>with</strong> the MouseMove Event. ......................... 155<br />

Try It Out 11-4 ......................................... 156<br />

Useful Tips ..................................................... 157<br />

Create a Gold Rush Game .......................................... 157<br />

Step 1: Open the Startup File .................................. 158<br />

Step 2: Move the Turtle ...................................... 159<br />

Step 3: Move the Bag of Gold ................................. 160<br />

Step 4: Update the User’s Score ................................ 162<br />

Try It Out 11-5 ......................................... 162<br />

<strong>Program</strong>ming Challenges ........................................... 163<br />

Contents in Detail<br />

xi

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!