DOC PREVIEW
Duke CPS 004 - Chapter 5

This preview shows page 1-2-21-22 out of 22 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CompSci 4 Chap 5 Sec 2 Mar 1, 2005AnnouncementsWhat we will do todayMouse ClicksExampleStoryboardA Better SolutionDemoThree EventsExample 2Slide 11PowerPoint PresentationSlide 13A DriverOne LinkprepareToShootlightningAndThunderspecialEffectsmove toMove to with an object parameterSlide 21Classwork todayCompSci 4Chap 5 Sec 2 Mar 1, 2005Prof. Susan RodgerNote: thanks to Wanda Dann and Steve Cooper for slide ideasAnnouncements•Read Chapter 6.1 for next time•Midterm next Tuesday, Chap 1-2,4-5•Assignment 5 due todayWhat we will do today•Lecture on Chap 5, Sec 2 –Event-handlers with parameters•ClassworkMouse Clicks•Interactive programs – allow user to mouse click an object–Buttons in an interface–Targets in a game–Checklist of items on a form•Will see how to pass information about a mouse clicked object to an event handlerExample•People are trapped in a burning building•Select which person will be rescuedStoryboard•Three people are to be rescued•Could write 3 different methodsEvent: click on guy1Responding Method: Save guy on first floorEvent: click on girl3Responding Method: Save girl on third floorEvent: click on girl2Responding Method: Save girl on second floorA Better Solution•Write one event handler•Send in information needed for actionfiretruck.savePerson:parameters: whichFloor, whichPerson, howFarDo in order point ladder at whichFloor extend ladder howFar meters whichPerson slides down ladder to fire truck pull ladder back howFar metersWhat type are the parameters?Demo•Demonstration of the code for firetruck.savePersonThree Events•The argument sent to parameters depends on which person is mouse clicked•Note - we positioned fire truck so distance from floor X is X meters (to floor 3 is 3 meters)Example 2•Zeus was a powerful god in Greek mythology. When Zeus was angry, he would shoot a thunderbolt out of the heavens to strike anyone who got in the way•The user will choose the philosopher who will be the next target of Zeus’ anger.Storyboard•Possible design – method with Object parameter named who, for object clicked–The actions in storyboard are complex–Break actions into simpler steps using stepwise refinementEvent: an object is mouse-clickedEvent handler: shootBoltParameter: who – object clickedDo in order prepare to strike object that was clicked thunder plays and lightning strikes object clicked lightning is repositioned for next strikeEvent: an object is mouse-clickedEvent handler: shootBoltParameter: who – object clickedDo in order prepare to strike object that was clicked thunder plays and lightning strikes object clicked lightning is repositioned for next strikeprepareToShootParameter: targetDo together turn Zeus to face the target make the lightning bolt visiblelightning and Thunder:Parameter: targetDo together play sound call specialEffects method - send targetspecialEffects:parameter: targetDo in order Do together lightning bolt move to target smoke move to target Do together set smoke to visible set lightning to invisible call smoke cycle – built-in method set target color to black move target up and downA Driver•shootBolt method - top level of our design•It calls other methods and controls the overall action of the program – we call this a driverOne Link•In the fire rescue example, we used three links – one for each person in the burning building.•In this example, we use only one link by selecting “object under mouse cursor” as the argument.prepareToShoot•In setting up initial scene, made lightning bolt invisible by setting its opacity to 0 (0%)•To prepare to shoot lightning bolt, make it visible, set opacity back to 1 (100%)lightningAndThunder•Coordinate the sound of the thunder with lightning and other special effectsspecialEffects•Smoke.cycle is a built-in instruction with a duration of about 2 ½ secondsmove to•Several statements in shootBolt and specialEffects methods use a move to instruction•The move to instruction moves an object to a particular position in the world. In the example above, where is the lightning bolt moved to?Move to with an object parameter•If an object parameter is used to specify a target position, creating a move to statement takes two steps:1) Drag in arbitrary object as parameter2) Substitute the object parameter nameThis is necessary because an object parameter is only a placeholder for an object – not an actual objectDemo•Test run of Zeus world•When parameters are used in interactive programming – especially important to test that all possible parameter values work as expected–What happens if you click on each philosopher, one at a time?•Also try things that shouldn’t work–What happens if you click on a column?–What happens if you click on a philosopher twice?–What happens if you click on Zeus?Classwork


View Full Document

Duke CPS 004 - Chapter 5

Documents in this Course
Lecture

Lecture

18 pages

Chapter 7

Chapter 7

18 pages

Chapter 9

Chapter 9

15 pages

Java 1

Java 1

24 pages

Java 3

Java 3

11 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

28 pages

Chap 2

Chap 2

16 pages

Graphics

Graphics

20 pages

Lecture

Lecture

12 pages

HTML

HTML

16 pages

Java 1

Java 1

6 pages

Chapter 4

Chapter 4

16 pages

The Plan

The Plan

25 pages

Lecture

Lecture

16 pages

Chapter 6

Chapter 6

21 pages

Lecture

Lecture

18 pages

Lecture

Lecture

23 pages

Lecture

Lecture

16 pages

Lecture

Lecture

19 pages

Lecture

Lecture

12 pages

Lecture

Lecture

5 pages

Lecture

Lecture

26 pages

Lecture

Lecture

16 pages

Chapter 7

Chapter 7

23 pages

Lecture

Lecture

21 pages

Lecture

Lecture

4 pages

Lecture

Lecture

4 pages

Lecture

Lecture

8 pages

Lecture

Lecture

4 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

32 pages

Java

Java

4 pages

CompSci 4

CompSci 4

18 pages

Lecture

Lecture

26 pages

CompSci 4

CompSci 4

12 pages

HTML

HTML

17 pages

Lecture

Lecture

16 pages

Lecture

Lecture

4 pages

Chapter 4

Chapter 4

10 pages

Chapter 2

Chapter 2

15 pages

Chapter 8

Chapter 8

14 pages

Lecture

Lecture

15 pages

Load more
Download Chapter 5
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 5 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 5 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?