CompSci 4 Chap 5 Sec 1 and 2 Oct 14, 2010 Prof. Susan Rodger.

Slides:



Advertisements
Similar presentations
Class-level Methods Alice. World / Class Method World method A general method that may refer to multiple objects; not closely associated with any particular.
Advertisements

Review of Chapter 4 Sections 1 and 2 World-level methods involve two or more objects break a large problem into smaller, logical units follow a design.
PIIT Computer Science Summer Camp - Alice July 11, 2012 Brenda Parker Computer Science Department MTSU.
Alice Inheritance and Event Handling. Inheritance Concept Consider this hierarchy; parents describe properties of children Animals Vertebrates MammalsFish.
Events Chapter 7. Interactivity The real world is interactive User determines order of actions instead of programmer.
Events Chapter 7. Interactive Real world is interactive User determines order of actions instead of programmer.
Alice Methods and Classes. Methods and Classes Methods – Coordinated sequence of instructions carried out when requested (e.g. move, turn to, etc.) Class.
Parameters and Event-Handler Methods Alice. Mouse input Interactive programs often allow the user to use a mouse to click buttons in a windows-based interface.
Parameters and Event-Handler Methods Sec 50 Web Design.
Lights Camera Action! Part 3: BDE Events By Deborah Nelson under the direction of Professor Susan Rodger Duke University July 2008.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 5 Interactive Programs.
Exploring Events. Try this Start Alice and create a blank world using the grass template. Add an instance of a BlueBallerina. Add an instance of a PinkBallerina.
Fall 2009ACS-1805 Ron McFadyen1 ACS-1805 Introduction to Programming using Alice.
CS320n –Visual Programming Interactive Programs Mike Scott (Slides 5-1)
Interaction: Events and Event Handling
Functions and Conditionals in Alice 1 Stephen Cooper Wanda Dann Barb Ericson September 2009.
Princess & Dragon Part 4: Breathing Fire—Adding Effects to Alice By Elizabeth Liang under the direction of Professor Susan Rodger Duke University June.
Sequencing Miss Regan. Blood Hound  Does anyone know what the Bloodhound project is?  Video 1 Video 1  Video 2 Video 2  Link to website Link to website.
Execution Control with If/Else and Boolean Functions
CompSci 4 Chap 5 Sec 1 Oct 13, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
Alice: Functions Alice Chapter 6 September 19, 2005.
Interaction: Events and Event Handling
Parameters and Event-Handler Methods Sec 50 Web Design.
Review For Test Chapter 4 & 5 Test is Wednesday, January 27th.
Event Driven Programming Chapter 5. Sequential Programming Computer-Centric Computer-Centric Program Runs as Programmer Intended Program Runs as Programmer.
Events (2) (Alice In Action, Ch 6) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
Today’s Agenda 1.Collect Pre-Lab 5 2.Collect Alice project storyboards 3.Events 4.Dummy Objects 5.Assign pair programming teams and meet upstairs for Lab.
Parameters and Event-Handler Methods Alice. Mouse clicks Interactive programs often allow the user to mouse click an object in the display. buttons in.
Parameters and Event-Handler Methods MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
Interactive Programming Sec 49 Web Design. Objectives The student will: Understand the difference between movie mode and an interactive program Understand.
Microsoft PowerPoint Tutorial Created by L. George 2006.
By Jennifer 2004 Powerpoint presentation Powerpoint presentation An introduction to using powerpoint.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
CompSci 4 Chap 5 Sec 2 Oct 18, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
CS320n – Elements of Visual Programming Sending Parameters to Event Handler Methods (Slides 5-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
The Essentials of Alice Mrs. Jayne Slease SBMS CTE Computer Science and Animation Credit to Duke Students under the direction of Professor Susan Rodger.
Skater World: Part Three By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 2009.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
CompSci 4 Chap 5 Sec 2 Oct 9, 2008 Prof. Susan Rodger.
BDE tutorial By Deborah Nelson Duke University Under the direction of Professor Susan Rodger July 13, 2008.
Interactive Programming MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum redesign project.
CompSci 4 Chap 9 Sec 1 October 28, 2010 Prof. Susan Rodger.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
Headshots in Alice Duke University Professor Susan H. Rodger Gaetjens Lezin July 2008.
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events By Elizabeth Liang under the direction of Professor Susan Rodger Duke University June.
Presenter: Carol Liss Timberlane Regional Middle School 6 th and 7 th grade Tech. Educator Co presenters:
CS320n –Visual Programming Execution Control with If / Else and Boolean Functions (Slides 6-2-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
The Essentials of Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University May 2009.
Making Billboards By Deborah Nelson Duke University, Under the direction of Professor Susan Rodger, July 14, 2008.
Introduction to the course Aug 30, Day 1 Object-oriented Programming thru Video Games TIDE 1840 Harry Howard Tulane University.
Introducing Scratch Learning resources for the implementation of the scenario
Parameters and Event-Handler Methods
Lesson 1: Buttons and Events – 12/18
Introduction to Events
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Class-level Methods Alice.
CS320n –Visual Programming
Parameters and Event-Handler Methods
Parameters and World-level methods
Interactive Programming
Parameters and Event-Handler Methods
Parameters and Event-Handler Methods
Professor Susan Rodger
Headshots in Alice Duke University Professor Susan H. Rodger
Professor Susan Rodger
Event-driven programming
Parameters and Event-Handler Methods
Interactive Programming
Presentation transcript:

CompSci 4 Chap 5 Sec 1 and 2 Oct 14, 2010 Prof. Susan Rodger

Announcements Read Chapter 6 Tips and Techniques for next class Reading quiz due next time New groups today Assignment 5 out –Part 1 due Thurs. Oct 21 and Part 2 due Oct 26 Today –Interactive programming, event handlers –Create billboards

Control of Flow Control of flow – how the sequence of actions in a program is controlled –What action happens first, second, third, …. In movie-style programs (Chaps 1-4) the sequence of actions is determined by the programmer –Creating a storyboard design –Writing program methods to carry out the designed sequence

Interactive Animations In interactive programs, the sequence of actions is determined at runtime, when the user provides input –Clicks the mouse –Presses a key on the keyboard Other sources of input are possible

Interactive Games In a video game where the user is guiding a spaceship, the sequence of actions … –Depends on what direction the user guides the ship –How fast the user presses the controls Each time the program runs, user input may cause a different sequence of actions Control of flow is “in the hands of the user”

Event Handlers An event may –Trigger a response, or –Move objects into positions that create some condition (e.g. a collision) that triggers a response An event handler is a method that is called to carry out the response. When an event is linked to an event handler, a behavior is created.

How does this effect your program? Our goal is to write interactive programs. The approach is the same as before, but the difference is now must be concerned with behaviors. – input from the user (events) –How objects respond to an event (event handler methods)

Example 1 Build an air show flight simulator. The pilot (user) uses the biplane controls to perform acrobatic stunts. Problem: How do we write program code to provide a guidance system that allows the user to be the pilot?

Solution Use keyboard input –“F” key to move the biplane forward –Spacebar to make the biplane do a barrel roll –Note: other keys could be chosen Write event handler methods that respond to each key press Storyboards (next slide) and DEMO building world

Event Storyboards Since two keys are used, two events are possible – so two storyboard scenes Each storyboard outlines an event handler –Responds to a particular event Event: Spacebar press Response: Do together roll biplane a full revolution play biplane engine sound Event: F-key press Response: Do together move biplane forward play biplane engine sound

biplane.flyForward Do not modify the length of the sound –use “as is” Coordinate duration of move and play sound –Match duration of move to duration of sound

Events Editor - Linking Each event handler method must be linked to an event 1) Select “create new event” Then choose the type of event 2) A template linking is created

Events Editor – Linking (cont) 3) Select type of key for event4) Select event handler method Final result:

More Functionality

Add a Billboard with Instructions Add an event “I” to make the instructions hide or show (create with paint, powerpoint or some tool and save as an image)

To drop in a Billboard “Make Billboard, import, picture appears in object tree

Mouse 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 handler

Example 2 Burning Building People are trapped in a burning building Select which person will be rescued See firetruck.savePerson

Storyboard Three people are to be rescued Could write 3 different methods Event: click on guy1 Responding Method: Save guy on first floor Event: click on girl3 Responding Method: Save girl on third floor Event: click on girl2 Responding Method: Save girl on second floor

A Better Solution Write one event handler Send in information needed for action firetruck.savePerson: parameters: whichFloor, whichPerson, howFar Do in order point ladder at whichFloor extend ladder howFar meters whichPerson slides down ladder to fire truck pull ladder back howFar meters What type are the parameters?

Three 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 3 – put events in 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 refinement Event: an object is mouse-clicked Event handler: shootBolt Parameter: who – object clicked Do in order prepare to strike object that was clicked thunder plays and lightning strikes object clicked lightning is repositioned for next strike

A Driver shootBolt method - top level of our design It calls other methods and controls the overall action of the program – we call this a driver

One 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.

Demo Test run of Zeus world – (this version doesn’t have the if statements from Chap 6 added in) 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 today Create 2 worlds (or can combine them in one) –Problem 14, page 163 –Problem 15, page 164 (can use any person) –Include instructions in both…(see handout)