Unformatted text preview:

Alice in Action with JavaObjectivesMethodsWorld Methods for Scenes and ShotsMethods for ScenesPowerPoint PresentationSlide 7Methods for Scenes (continued)Slide 9Slide 10Methods for ShotsMethods for Shots (continued)Slide 13Slide 14Object Methods for Object BehaviorsSlide 16Slide 17Object Methods for Object Behaviors (continued)Slide 19Slide 20Alice Tip: Reusing Your WorkSlide 22Using the ClipboardSlide 24Slide 25Reusing an Object in a Different WorldSlide 27Slide 28Alice Tip: Using DummiesDummiesSlide 31Slide 32Dummies (continued)Slide 34Using setPointOfView() to Control the CameraSlide 36Slide 37Using setPointOfView() to Control the Camera (continued)Slide 39Slide 40Thinking in 3DAn Object’s PositionSlide 43Slide 44An Object's OrientationSlide 46Slide 47Slide 48Point of ViewSummarySummary (continued)Alice in Action with JavaChapter 2MethodsAlice in Action with Java 2Objectives•Build world-level methods to help organize a story into scenes and shots•Build class-level methods to elicit desirable behaviors from objects•Reuse a class-level method in multiple worlds•Use dummies to reposition the camera for different shots within a scene •Understand how an object’s position, orientation, and point of view are determinedAlice in Action with Java 3Methods•Programs consist of a set of statements•Method: behavior-producing message•Objects have predefined methods for basic tasks •Methods may also be created by Alice developers•Two reasons for building your own methods–To organize your story into more manageable pieces–To provide an object with additional behaviorsAlice in Action with Java 4World Methods for Scenes and Shots•Scene: segment of a story •Shot: part of a scene from a given camera position•User stories can be divided into scenes and shots–A convenient technique for completing a project•Divide and conquer approach to building user stories–Break a big problem into smaller problems–Solve each of the smaller problems–Combine the smaller problems into a solutionAlice in Action with Java 5Methods for Scenes•Scenario: develop a user story with three scenes•Convention for naming methods–Name should be a verb or verb phrase–Name should describe what the method does•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 emptyAlice in Action with Java 6Methods for Scenes (continued)Alice in Action with Java 7Methods for Scenes (continued)Alice in Action with Java 8Methods for Scenes (continued)•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 Java 9Methods for Scenes (continued)Alice in Action with Java 10Methods for Scenes (continued)Alice in Action with Java 11Methods for Shots•Scenes can be divided into shots•Shots can be further divided into pieces•Reasons for using scenes, shots, and pieces –To create a program that reflects the user story –To create a program that has a modular design•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 2Alice in Action with Java 12Methods 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•All objects added to world become part of world•Scene and shot messages are stored in the world•World method: affects behavior of multiple objectsAlice in Action with Java 13Methods for Shots (continued)Alice in Action with Java 14Methods for Shots (continued)Alice in Action with Java 15Object Methods for Object Behaviors•Object method: defines behavior for a single object–Illustration: flapWings()should be sent to a dragon•Comments: explanatory remark ignored by Alice•Example 1: Telling a Dragon to Flap its Wings–Add a dragon object to the world –Select dragon from object tree and click methods tab–Click create new method and enter flapWings–Send roll() messages to each of the dragon’s wings–Invoke flapWings() from my_first_method()–Add comments to the flapWings() methodAlice in Action with Java 16Object Methods for Object Behaviors (continued)Alice in Action with Java 17Object Methods for Object Behaviors (continued)Alice in Action with Java 18Object Methods for Object Behaviors (continued)•Example 2: Telling a Toy Soldier to March–Four actions correspond to four steps for march()•1 marchLeft;•2 marchRight;•3 marchRight;•4 marchLeft.–Define marchLeft() and marchRight() methods •These methods produce reverse behaviors –Incorporate new methods into march()–Call march()four times from my_first_method()Alice in Action with Java 19Object Methods for Object Behaviors (continued)Alice in Action with Java 20Object Methods for Object Behaviors (continued)Alice in Action with Java 21Alice Tip: Reusing Your Work•Copy and past techniques speed up development•How to use make copy to duplicate statements–Right-click bar in editing area containing method–Select make copy •Example using make copy –Refer to my_first_method() in Toy Soldier program–Copy three march() statements from first march()Alice in Action with Java 22Alice Tip: Reusing Your Work (continued)Alice in Action with Java 23Using the Clipboard•Alice clipboard–Used to copy and paste all statement types–Located in the events area•Using Alice clipboard in Toy Soldier program–Drag doInOrder in my_first_method() to clipboard–Create scene1() method –Drag statement in clipboard to editing area –Drop statement in the scene1() method •Only one statement may be placed in the clipboard•You can increase the number of available clipboardsAlice in Action with Java 24Using the Clipboard (continued)Alice in Action with Java 25Using the Clipboard (continued)Alice in Action with Java 26Reusing an Object in a Different World•Alice lets you


View Full Document

BOISE STATE CS 120 - Chapter 2 Methods

Documents in this Course
Load more
Download Chapter 2 Methods
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Chapter 2 Methods and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Chapter 2 Methods 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?