DOC PREVIEW
BOISE STATE CS 120 - Chapter 6

This preview shows page 1-2-3-27-28-29 out of 29 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 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 29 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 29 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 29 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 29 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 29 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Alice in Action with JavaObjectivesEventsSlide 4Handling Mouse Clicks: The Magical DoorsThe Right DoorThe Left DoorThe Right Door RevisitedEvent Handling is SimultaneousCategorizing EventsHandling Key Presses: A Helicopter Flight SimulatorDesignProgramming in AliceProgramming in Alice (continued)Slide 15Alice Tip: Using 3-D TextRepositioning Text that is Off-CameraAdding a BackgroundMaking Text Appear or DisappearSlide 20Alice Tip: Scene Transitional Effects for the CameraSetup for Special EffectsSlide 23The Fade EffectThe Barndoor Edge Wipe EffectThe Box Iris Wipe EffectReusing Transition EffectsSummarySummary (continued)Alice in Action with JavaChapter 6EventsAlice in Action with Java 2Objectives•Create new events in Alice•Create handler methods for Alice events•Use events to build interactive storiesAlice in Action with Java 3Events•An interactive program processes data input by a user•Events are actions generated by a user or a program –Ex: When the world starts caused by Play click•Two steps to making a program respond to an event–Choose (or define) a method to handle the event–Tell Alice to invoke the method when the event occurs•An event handler is a method called in response to an event•An event-driven program is based on events and handlersAlice in Action with Java 4Types of EventsAlice in Action with Java 5Handling Mouse Clicks: The Magical Doors•Goal: add events to world built in Section 5.2.3 –Review: castle door tells random knock-knock jokes•Events that will be added to the original program–Right door opens when the user clicks it –Left door tells knock-knock joke when the user clicks it •First step: stop door from automatically telling jokesAlice in Action with Java 6The Right Door•How to handle a mouse event–Choose or define a method•Define a method when responsive behavior is complex–Create an event that invokes the handler•Enabling the right door to respond to a mouse event–Add When the mouse is clicked on something–Specify castle.door1 as the event source–Use a turn()message to handle the eventAlice in Action with Java 7The Left Door•Enabling the left door to respond to a mouse event–Specify castle.door2 as the source of this event–Drag-and-drop world’s random joke method as handler•Test the program by clicking each doorAlice in Action with Java 8The Right Door Revisited•Two-state behavior–Describes one of two states that an object can occupy–The state is determined by the value of a property–An if statement controls switching between states •Logic error: right door continues to turn with user click•Right door should open if closed, and close if open•Fix: implement two-state behavior for right door–Add Boolean property rightDoorClosed to castle–Replacement handler: openOrCloseRightDoor()–Build turn logic around the value of rightDoorClosedAlice in Action with Java 9Event Handling is Simultaneous•Example: left door tells jokes while right door turns•Alice handles simultaneous events well•Conflicts can arise when coding parallel event logic –Example: two handlers modify the same property•How to avoid conflict–Ensure that handlers modify a property in sequenceAlice in Action with Java 10Categorizing Events•Mouse event: triggered by mouse movement or click•Keyboard event: triggered when user presses a key•Program event: triggered when variable value changesAlice in Action with Java 11Handling Key Presses: A Helicopter Flight Simulator •The problem–The mayor’s cat is lost and city government has halted–You need to use your helicopter to find the cat–Search begins at an airport outside the cityAlice in Action with Java 12Design•Six keys for six types of movement–‘a’ key: ascend–‘d’ key: descend–Up arrow key: move forward –Down arrow key: move backward–Left arrow key: turn left–Right arrow key: turn right•Keys are chosen for two reasons–Convenient position and mnemonic values•Choosing correct keys improves usabilityAlice in Action with Java 13Programming in Alice•Setting up the world for a helicopter simulation–Add airport, helicopter, city terrain, buildings, and a cat–Position the helicopter at the airport–Position camera to be peering out in front of helicopter–Set the camera’s vehicle property to be helicopter•Making the helicopter’s propeller spin–Use heli blade()to handle the press of Play button•Making the helicopter ascend–Define Boolean property inTheAir for helicopter –Define helicopter. ascend()Alice in Action with Java 14Programming in Alice (continued)•Making the helicopter ascend (continued)–Add a When a key is typed event–Change event to While a key is typed event–Associate the ‘A’ key with the event–Enable the handler to perform while ‘A’ key is pressed•Making the helicopter descend–Define descend()method for helicopter•Method logic mirrors the logic of ascend()•Note that the ground provides a floor for the descent–Enable descend()to perform while ‘D’ key is pressedAlice in Action with Java 15Programming in Alice•Let arrow keys move <subject> event–Not appropriate for controlling helicopter movement–helicopter would move while on the ground•Define turnSlightly()to handle left or right turns–turnSlightly()takes a Left or Right argument –helicopter turns only if inTheAir is true–Arrow keys are associated with the method –Depressing arrow key sends a Left or Right argument•Define go()to handle forward or backward movement–Logic is similar to logic for turnSlightly()methodAlice in Action with Java 16Alice Tip: Using 3-D Text•Helicopter simulator should have flight instructions•Solution: add 3-D text that explains the interface•Creating 3-D text for the simulator–Return to the Add Objects screen–Click Create 3D Text (at far end of Local Gallery)–Add flight instructions in the text box–Click OK –Rename the text object, instructionsAlice in Action with Java 17Repositioning Text that is Off-Camera•Right-click instructions to access methods•Three settings for positioning text in front of camera–Choose methods-> setPointOfView(<asSeenBy)->camera–Choose methods->move(<direction>,<amount>) ->FORWARD->10 meters–Choose methods->turn<direction>,<amount>) ->LEFT->1/2 revolution•Linking text to camera and changing text color –Set instructions.vehicle to camera–Set instructions.color to yellowAlice in Action with Java 18Adding


View Full Document

BOISE STATE CS 120 - Chapter 6

Documents in this Course
Load more
Download Chapter 6
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 6 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 6 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?