19.04.2017 Views

Learn to Program with Small Basic

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

TRY IT OUT 12-4<br />

Write a program <strong>to</strong> ask the user what their favorite animal is. Then search for that<br />

animal using the Flickr object and display the returned image. Next, ask the user,<br />

“Like this one?” and show them two but<strong>to</strong>ns labeled Yes and No. If the user clicks<br />

Yes, display Hooray! in a message box. If they click No, display a different random<br />

picture of that animal and ask, “How about this one?” Continue these steps<br />

until the user clicks Yes. You’ve just turned a simple program in<strong>to</strong> a game!<br />

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

If you get stuck, check out http://nostarch.com/smallbasic/ for the solutions<br />

and for more resources and review questions for teachers and students.<br />

1. In this program, you’ll create a hidden treasure game. Open the file<br />

HiddenTreasure_Incomplete.sb from this chapter’s folder. When you run<br />

the program, you’ll see the following interface.<br />

The purpose of the game is <strong>to</strong> guess the location of a hidden treasure.<br />

The player makes a guess by pressing one of the four but<strong>to</strong>ns. If<br />

they guess correctly, they gain $10. Otherwise, they lose $5. The game<br />

ends after 10 rounds. Follow the comments shown in the program’s<br />

source code <strong>to</strong> write the missing code and complete the program.<br />

178 Chapter 12

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

Saved successfully!

Ooh no, something went wrong!