20.03.2013 Views

Introduction to Computer Science with Scratch and App Inventor

Introduction to Computer Science with Scratch and App Inventor

Introduction to Computer Science with Scratch and App Inventor

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Does your code look a little bit like this?<br />

Now give your game a try. You should be able <strong>to</strong> run up the score by clicking (this is how you simulate a<br />

<strong>to</strong>uch) on the mole as it pops up on the screen. Is your game <strong>to</strong>o hard or <strong>to</strong>o easy? You can modify the<br />

difficulty by changing the value on the timer.<br />

Let’s add a reset but<strong>to</strong>n that starts the user over at a score of zero. What are the steps <strong>to</strong> add a new<br />

element <strong>to</strong> our game?<br />

1) Add the interface element in <strong>App</strong> Builder<br />

2) Use Blocks Edi<strong>to</strong>r <strong>to</strong> write code <strong>to</strong> implement the behavior of the element.<br />

Here is what my interface looks like after I add a RESET but<strong>to</strong>n.<br />

Above you can see the code that sets the score back <strong>to</strong> zero<br />

when the user clicks the but<strong>to</strong>n. A but<strong>to</strong>n click, is h<strong>and</strong>led just<br />

like a screen <strong>to</strong>uch – you can capture the event using a green<br />

block.<br />

Now you should see the pattern for adding new elements <strong>to</strong> your game. Right now the game is very<br />

basic. What kinds of things could we add <strong>to</strong> make the game more fun? More challenging? Could you<br />

change the game so that it gets harder as the user scores more points? How about changing it so that<br />

the user loses points if they click <strong>and</strong> miss the mole? Think about how you might make some of these<br />

changes. Pick one change (it can be one of the ones listed here, or you can come up <strong>with</strong> your own) <strong>and</strong><br />

add it <strong>to</strong> the game.<br />

Think about how you might figure out how <strong>to</strong> use new blocks or <strong>to</strong> accomplish tasks that we haven’t<br />

covered.<br />

mbrace Game Development Workbook Page 46

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

Saved successfully!

Ooh no, something went wrong!