Presentation is loading. Please wait.

Presentation is loading. Please wait.

As you come in…  DOWNLOADS FOR TODAY:  CarGameTeacherStarter.a2w  Online student textbook.

Similar presentations


Presentation on theme: "As you come in…  DOWNLOADS FOR TODAY:  CarGameTeacherStarter.a2w  Online student textbook."— Presentation transcript:

1 As you come in…  DOWNLOADS FOR TODAY:  http://ce21sandiego.org/2013 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 boolean expressions 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 – OR Car 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: isMagnet Returns: 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 – OR Car 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 – OR Car Driving Game  Two ways if…

10 Compound Boolean Expressions – OR Car Driving Game  Two ways if… nested if

11 Compound Boolean Expressions – AND Spaceship 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 – AND Spaceship takes off  Two ways if…

13 Compound Boolean Expressions – AND Spaceship takes off  Two ways if…

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


Download ppt "As you come in…  DOWNLOADS FOR TODAY:  CarGameTeacherStarter.a2w  Online student textbook."

Similar presentations


Ads by Google