Presentation is loading. Please wait.

Presentation is loading. Please wait.

World-level Classes Chapter 6 Part 2. Programs Grow Program code grows larger over time This makes it more difficult to read and process the code in our.

Similar presentations


Presentation on theme: "World-level Classes Chapter 6 Part 2. Programs Grow Program code grows larger over time This makes it more difficult to read and process the code in our."— Presentation transcript:

1 World-level Classes Chapter 6 Part 2

2 Programs Grow Program code grows larger over time This makes it more difficult to read and process the code in our minds Games and other software can have thousands, even millions of lines of code 2

3 Basic Components Classes, objects, and methods in object-oriented programming help to o Organize a large program into small modules o Design and think about an intricate program o Find and remove errors (bugs) 3

4 World Level Method Method that can reference entire World Has instructions involving more than one object (cleverSkater, penguin) Class-level methods only involve one object 4

5 Why Write World Level Methods? No method does what you need o You need new functionality Saves time o Can call method many times without making your own code to do same thing Reduces code size o Call method instead of rewriting code Allows thinking at a higher level o You think of method names instead of what method does  Ex: sharkSwims, sharkEatsFish, etc. o Allows abstraction – "thinking at a higher level" 5

6 Demo: Starting a new method First associate the new method with the World Select the World tile in the Object Tree Select the methods tab in the details area Click on the "create new method" button 6

7 Edit or Read Method Click on edit button to edit or read method code Can open method by double clicking on it in method editor 7

8 Example: A Beetle Band Create an animation for a bug band as an advertisement for their next concert 8

9 Demo BeetleBand-v1 Concepts illustrated o To play a sound, a sound file must first be imported into Alice  Alice is not a sound editor o This code is only for georgeBeetle o Three more methods (one for each band member) will be needed 9

10 Algorithms: Playing Solo Each bug band member will perform a solo Do together Do in order georgeBeetle move up georgeBeetle move down play sound Do together Do in order ringoBeetle move up ringoBeetle move down play sound Do together Do in order paulBeetle move up paulBeetle move down play sound Do together Do in order lennonBeetle move up lennonBeetle move down play sound 10

11 A Better Solution Creating four versions of similar code is tedious Only things that change are band member and music played Better solution o Write more flexible method using parameters 11

12 Beetles Algorithm One method can be used Use parameters to specify  Which band member will perform  Which music should be played solo Parameters: bandMember, music Do together Do in order bandMember move up bandMember move down play music 12

13 Place bandMember in Method 13 Create bandMember parameter as object Drag bandMember parameter to editor Menu pops up where you can choose method to use

14 Alice Program for Solo Notice that bandMember is an object parameter Music is a sound parameter 14

15 Drag solo to Editor Fill in parameters: 15

16 BeetleBand-v2 New solo method is added for each band member and music to play 16

17 Demo BeetleBand-v2 Concepts illustrated o Enter name and select type for each parameter  bandMember is an Object parameter  music is a Sound parameter o Arguments passed to parameters in called method  bandMember: georgeBeatle, lennonBeatle, paulBeetle, ringoBeatle  What are the arguments passed into music parameter? o Parameters are placeholders  bandMember and music get new values when called from arguments 17

18 Homework Read chapter 6 section 7 Do chapter 6b lab. Due next class. 18


Download ppt "World-level Classes Chapter 6 Part 2. Programs Grow Program code grows larger over time This makes it more difficult to read and process the code in our."

Similar presentations


Ads by Google