Presentation is loading. Please wait.

Presentation is loading. Please wait.

Methods (part 1) Alice In Action, Ch 2 Slides Credit: Joel Adams, Alice in Action CS120 Lecture 02 31 August 2012.

Similar presentations


Presentation on theme: "Methods (part 1) Alice In Action, Ch 2 Slides Credit: Joel Adams, Alice in Action CS120 Lecture 02 31 August 2012."— Presentation transcript:

1 Methods (part 1) Alice In Action, Ch 2 Slides Credit: Joel Adams, Alice in Action CS120 Lecture 02 31 August 2012

2 Objectives Build world-level methods to help organize a story into scenes and shots Use dummies to reposition the camera for different points of views within a scene Understand how an object’s position, orientation, and point of view are described, changed and determined Documenting your code with comments. Understand Flow of Control with methods. 2

3 Methods – behavior-producing messages (from the sender’s view) – behaviors/actions in response to requests, messages (from the recipient’s view) – E.g. in world.my_first_method: whiteRabbit.pointat(camera) Convention for naming methods – Name should be a verb or verb phrase – Name should describe what the method does A method is a way to name a block of code. 3

4 Methods Objects have predefined methods for common tasks Methods may also be created by Alice developers – Two main reasons for building your own methods To provide an object with additional behaviors (Next week) To organize your story and program into more manageable pieces (Today) Divide and conquer methodology – Break a big problem into smaller problems – Solve each of the smaller problems – Combine the solutions of smaller problems into a solution for the original, big problem Hiding complex details with abstraction. Alice in Action with Java4

5 World Methods for Scenes and Shots User stories can be divided into scenes and shots – Scene: segment of a story, usually set in one location – Shot: part of a scene, normally from one fixed camera view Use multiple scenes and shots to create a program that reflects the user story and has a modular design 5 Two shots of one scene

6 Methods for Scenes Example: develop a user story with three scenes Creating the first new method – Select the world object – Click the create new method in the details area – Enter playScene1 in the New Method dialog box Check new method by sending say() to ground – First test fails because my_first_method() is empty 6

7 Alice in Action with Java7 Methods for Scenes (continued)

8 Alice in Action with Java8 Methods for Scenes (continued)

9 How to fix the first bug – Click on the tab for my_first_method – Drag a doInOrder control to the top of the pane – Click on world in the object tree – Drag playScene1() into the doInOrder statement Extend technique used to build playScene1() – Add two methods: playScene2(), playScene3() – New method sends a say() message to the ground – New Methods are called in my_first_method() Alice in Action with Java9

10 10 Methods for Scenes (continued)

11 11 Methods for Scenes (continued)

12 Methods for Shots Example of a scheme using scenes and shots – Level 1: my_first_method() – Level 2: three methods for three scenes – Level 3: four methods for four shots in Scene 2 12

13 Methods for Shots (continued) Implementing the scheme – Test each shot in Scene 2 using a say() method – Call the four shot methods from playScene2() – Call three scene methods from my_first_method() Structure diagram reflects organization of user story Scene and shot messages are stored in the world Alice in Action with Java13

14 Alice in Action with Java14 Methods for Shots (continued)

15 World and Object Methods World method: affects behavior of all objects in a world Object method: defines behavior for a single object (that may have multiple parts) – examples : flapWings() for dragon, hop() for a rabbit… Alice in Action with Java15

16 Program Documentation Standalone readme, manual… Comments: explanatory remark ignored by Alice – an integral part of code – Used to describe what code does at various levels the overall program, individual methods, blocks of statements…. – Useful for collaborators and developers themselves – Important part of programming Also a component evaluated for your program grades Alice in Action with Java16

17 Alice Tip: Using Dummies Review – Scenes comprise shots – Shots are filmed with the camera in a given position – Alice places a camera object in every world Two techniques for shifting position of camera – Use set of motion-related messages, such as move() – Use an invisible marker called a dummy 17

18 Dummies Dummy: invisible marker with a point of view Dummies are used to change a camera’s position Description of a scene that will use dummies – Wizard intervenes to prevent trolls from taking a castle – Camera changes position for each of three shots – Story conforms to structure in Figure 2-11 (less Shot 4) Setting up the first shot of Scene 2 – Add castle, wizard, and trolls to build the scene – Click more controls button and then drop a dummy – Go to object tree and rename dummy scene2Shot1 18

19 19 Dummies (continued)

20 20 Dummies (continued)

21 Setting up the second shot of Scene 2 – Using camera controls, zoom in on the wizard – Press the drop dummy at camera button – Rename the second dummy, scene2Shot2 Setting up the third shot of Scene 3 – First dummy will be reused for this shot After dummies are inserted they will be programmed 21

22 Alice in Action with Java22 Dummies (continued)

23 Using setPointOfView() to Control the Camera obj.setPointOfView(obj2) – Changes the position of obj to obj2 – Example: camera.setPointOfView(aDummy) Adding code to the first shot of Scene 2 – Drag a doInOrder statement to the editing area – Click on camera object in the object tree – Drag setPointOfView() to the editing area Select scene2Shot1 dummy as target and 0 duration – Add say() statements for each of the trolls – Add a comment to explain the purpose of the method Alice in Action with Java23

24 Alice in Action with Java24 Using setPointOfView() to Control the Camera (continued)

25 Alice in Action with Java25 Using setPointOfView() to Control the Camera (continued)

26 Adding code to the second shot of Scene 2 – Set the opacity of the wizard to 0 in properties pane – Drag wizard ’s opacity property to editing area Set the opacity to 1 in the set() method – Set the camera ’s point of view to scene2Shot2 – Add a say() statement for the wizard Adding code to the third shot of Scene 2 – Reset camera’s point of view to scene2Shot1 – Point the three trolls at the wizard Set message’s onlyAffectYaw attribute to true 26

27 27 Using setPointOfView() to Control the Camera (continued)

28 28 Using setPointOfView() to Control the Camera (continued)

29 Summary Divide and conquer approach: decomposing a user story into scenes and shots Define methods to support modular design and provide advanced operations World methods: messages sent to the world Comments: remarks that explain program statements Flow of Control: How methods modify sequential execution. Dummy: invisible marker with position and orientation (a point of view) 29

30 Student To-Do No lab on Monday (Holiday) Hopefully we’ll do a lab on Tuesday First homework will go out on Tuesday. – For now, practice on your own with Alice Readings: – Ch 1, Ch 2 Alice in Action with Java30


Download ppt "Methods (part 1) Alice In Action, Ch 2 Slides Credit: Joel Adams, Alice in Action CS120 Lecture 02 31 August 2012."

Similar presentations


Ads by Google