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.

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

After you set the game’s parameters, you’ll need <strong>to</strong> show them <strong>to</strong> the user.<br />

Add the UpdateUserInterface() subroutine in Listing 10-10.<br />

1 Sub UpdateUserInterface<br />

2 Shapes.SetText(distText, dist)<br />

3 Shapes.SetText(arrowsText, arrows)<br />

4 Shapes.SetText(shieldText, shield)<br />

5 EndSub<br />

Listing 10-10: Subroutine that updates the text<br />

This subroutine is pretty basic (and small!). You just use the SetText()<br />

method of the Shapes object and pass the identifier of the text shape and<br />

the number you want <strong>to</strong> display. Recall that we saved these identifiers<br />

when we created these text shapes in the SetUp() subroutine (lines 19–21<br />

in Listing 10-8).<br />

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

If you run the game now, you should see all the images and numbers in<br />

place, but nothing will happen yet. You need <strong>to</strong> start taking the knight’s<br />

orders, so it’s time <strong>to</strong> add the GetChoice() subroutine in Listing 10-11.<br />

1 Sub GetChoice<br />

2 AskAgain:<br />

3 TextWindow.WriteLine("Select:")<br />

4 TextWindow.WriteLine(" [1] Move 1 step forward")<br />

5 TextWindow.WriteLine(" [2] Shoot an arrow")<br />

6 TextWindow.WriteLine(" [3] Stab the dragon (you have <strong>to</strong> be 1 step away)")<br />

7 TextWindow.Write(" Your choice [1-3]: ")<br />

8<br />

9 choice = TextWindow.ReadNumber()<br />

10 If((choice 1) And (choice 2) And (choice 3)) Then<br />

11 Go<strong>to</strong> AskAgain<br />

12 EndIf<br />

13<br />

14 If ((choice = 2) And (arrows = 0)) Then<br />

15 Shapes.SetText(msgText, "You ran out of arrows! Borrow some from Link.")<br />

16 Go<strong>to</strong> AskAgain<br />

17 EndIf<br />

18<br />

19 If ((choice = 3) And (dist > 1)) Then<br />

20 Shapes.SetText(msgText, "You're <strong>to</strong>o far <strong>to</strong> use your sword. Too bad <br />

you can't train dragons.")<br />

21 Go<strong>to</strong> AskAgain<br />

22 EndIf<br />

23<br />

142 Chapter 10

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

Saved successfully!

Ooh no, something went wrong!