1 / 14

As you come in…

As you come in…. DOWNLOADS FOR TODAY : http://ce21sandiego.org/2013 CarGameTeacherStarter.a2w Online student textbook (at bottom of each page below ) Module 9.4 SpaceShipGame.a2w . Today’s plan. Functions

wenda
Download Presentation

As you come in…

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. As you come in… • DOWNLOADS FOR TODAY: • http://ce21sandiego.org/2013 • CarGameTeacherStarter.a2w • Online student textbook (at bottom of each page below) • Module 9.4 SpaceShipGame.a2w

  2. Today’s plan • Functions • Compound booleanexpressions and if statements – can solve same problem multiple ways • Or – car magnet • And – space ship take off • Methods and Parameters

  3. Functions: Calculate a Value and “Return” it. • Hides away complex calculation • When program executes that line/tile: change of control flow! • Jump to code/function that does the calculation • It “returns” the calculated value, which replaces the function call tile • Finally, that line/tile is executed

  4. Examples you know (but can’t see/edit the code for) Object functions • Some calculate numbers • Distance To • Height • Some calculate boolean values • Is within X of Y • Is above

  5. Examples you know (but can’t see/edit the code for) World functions • Some calculate numbers • Random number • Some calculate boolean values • Both a and b • Either a or b or both • a == b • a > b

  6. Compound Boolean Expressions – ORCar Driving Game (watch video 9.2) • Modify: Car should only turn to head towards MAGNETS • One of the 4 magnets • Download from ce21sandiego.org/2013 • CarGameTeacherStater.a2w • Let’s create a function to hide away complex boolean expression

  7. Create function: isMagnetReturns: boolean value • Create new World function • Choose returns boolean • Call it isMagnet (we often use “is” for boolean returning functions – Yes or No, true or false) • Drag boolean expression in if to clipboard • Go to isMagnet function definition replace “true” with expression from clipboard • BACK in my first method • Drag complex expression to trash • Replace (default) true with new isMagnet function (look under World, functions – it’s at top)

  8. Compound Boolean Expressions – ORCar Driving Game (watch video 9.2) • In online text – used to show • Two ways you could make this if… • Compound boolean expression

  9. Compound Boolean Expressions – ORCar Driving Game • Two ways if…

  10. Compound Boolean Expressions – ORCar Driving Game • Two ways if… nested if

  11. Compound Boolean Expressions – ANDSpaceship takes off • Space ship only takes off if all spheres are blue • Download from online textbook module 9.4 • SpaceShipGame.a2w (bottom of page) • Click on World object • Methods – edit Flip Switch • Build this if statement • When true – make dropShip object move up 30 meters

  12. Compound Boolean Expressions – ANDSpaceship takes off • Two ways if…

  13. Compound Boolean Expressions – ANDSpaceship takes off • Two ways if…

  14. Coming Up… • Week 7: Methods, parameters, and events • Week 8: Lists

More Related