Parameters and Event-Handler Methods MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.

Slides:



Advertisements
Similar presentations
Example: Multiple Conditions Execution Control with If Else and Boolean Questions Alice.
Advertisements

Alice.
Class-level Methods Alice. World / Class Method World method A general method that may refer to multiple objects; not closely associated with any particular.
Class-level Methods Chapter 6. Class-level Method Is specific to a class of objects We can give a class new abilities/methods Only involves this one class.
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.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Class-level Methods and Inheritance MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
Alice Inheritance and Event Handling. Inheritance Concept Consider this hierarchy; parents describe properties of children Animals Vertebrates MammalsFish.
Parameters and World-level methods Alice. Our Dragon world The dragon must to take off and fly, to carry the princess.
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.
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.
While: Indefinite Loops Alice. Repetition In some situations, we don’t know exactly how many times a block of instructions should be repeated. All we.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 5 Interactive Programs.
CS320n –Visual Programming Functions Mike Scott (Slides 6-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CS320n –Visual Programming Interactive Programs Mike Scott (Slides 5-1)
Copyright 2011 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Implementation Algorithm  Code World.my first method Control blocks Statements (methods,
Interaction: Events and Event Handling
Functions and Conditionals in Alice 1 Stephen Cooper Wanda Dann Barb Ericson September 2009.
Recursion1 Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Jan 2010 Recursion in Alice.
Execution Control with If/Else and Boolean Functions Sec 52 Web Design.
CompSci 4 Chap 5 Sec 1 Oct 13, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
Alice: Functions Alice Chapter 6 September 19, 2005.
Class-level Methods Chapter 6 part 1. Classes and Objects Classes o In Alice, classes are predefined as 3D models Objects o An object is an instance of.
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.
An Innovative Approach with Alice for Attracting K-12 Students to Computing Susan H. Rodger Duke University IBM University Days May 7, 2007 Supported by.
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.
Interactive Programming Sec 49 Web Design. Objectives The student will: Understand the difference between movie mode and an interactive program Understand.
Execution Control with If/Else and Boolean Functions Alice.
ActionScript: Functions, Parameters, Functions that return a value, Variables, setInterval Functions MMP 220 Multimedia Programming This material was prepared.
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.
ActionScript: For Loops, While Loops, Concatenation and Arrays MMP 220 Multimedia Programming This material was prepared for students in MMP220 Multimedia.
Classes, Objects, and World-level Methods MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
ActionScript: Classes, Properties, EventHandler Methods, Datatypes & Control Structures MMP 220 Multimedia Programming This material was prepared for students.
Copyright 2008 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Functions, Loops, and Parameters.
Programming: Simple Control Structures MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
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.
Interactive Programming MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum redesign project.
List Search Alice. Common Uses of Lists Iterating through a list of several like items to accomplish the same task with each item. As in the previous.
Parameters MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum redesign project funded.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
CompSci 4 Chap 5 Sec 1 and 2 Oct 14, 2010 Prof. Susan Rodger.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
CS320n – Elements of Visual Programming List Search Mike Scott (Slides 9-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Parameters and Event-Handler Methods
Execution Control with If/Else and Boolean Functions
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
Animation Programs: Scenarios and Storyboards
Parameters and Event-Handler Methods
Parameters and Event-Handler Methods
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Class-level Methods and Inheritance
Parameters and Event-Handler Methods
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Presentation transcript:

Parameters and Event-Handler Methods MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum redesign project funded by National Science Foundation grant # Co PI’s Christopher Stein and Jody Culkin BMCC CUNY The material in this handout is taken from “Learning to Program with Alice” a project supported by the National Science Foundation under Grant NSF , NSF , and NSF Contact Wanda Dann: Stephen Cooper: Randy Pausch: and Don Slater:

Mouse Input Interactive programs often allow the user to use a mouse to click – buttons in a windows-based interface – targets in a game – a checklist of items on a business form In this session, we look at how to use mouse input.

Example People are trapped in a burning building and the user will click the mouse cursor on the person to be rescued next. In setting up this demo world, we positioned the fire truck so the distance of the ladder from the 1st floor is 1 meter, 2nd floor is 2 meters, and 3rd floor is 3 meters.

Storyboard Three people are to be rescued. So, we could write three different methods.

A Better Solution A better solution is to write one event handler method and send in the information needed to perform the action. firetruck.savePerson: parameters: whichFloor, whichPerson, howFar Do in order point ladder at whichFloor extend the ladder howFar meters whichPerson slide down the ladder to the fire truck pull the ladder back howFar meters whichFloor and whichPerson are Object parameters howFar is a Number parameter

Demo Ch05Lec2SavePeople Concepts illustrated: – Parameters allow one event handling method to handle three different events. – The fireAnim object has a built-in event and event handling method.

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’s anger.

Storyboard A possible design is a method with an Object parameter, named who, for the object that was clicked. –The actions in this storyboard are complex. – We can break the actions down into simpler steps using stepwise refinement. Event: An object is mouse-clicked Event handler: shootBolt Parameter: who — the object that was clicked Do in order prepare to strike the object that was clicked thunder plays and lightning strikes the object that was clicked lightning is repositioned for the next strike

Event: An object is mouse-clicked Event handler: shootBolt Parameter: who — the object that was clicked Do in order call prepareToShoot method — send who as the target call lightningAndThunder method — send who as the target lightning move to cloud’s position prepareToShoot: Parameter: target Do together turn Zeus to face the target make the lightning bolt visible lightningAndThunder: Parameter: target Do together play sound call specialEffects method — send target specialEffects: Parameter: target Do 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 down

Demo Ch05Lec2Zeus Concepts illustrated: – The shootBolt method is at the top of the storyboard design. This method calls two other methods – a driver method. – object under the mouse cursor is used in the When mouse is clicked event to pass the clicked object as the target

Opacity In this example, opacity is used to make the lightning bolt visible and invisible. – In setting up the initial scene, the lightning bolt is made invisible by setting its opacity to 0 (0%). – In preparing to shoot the lightning bolt, it was made visible by setting its opacity to 1 (100%). (Review Tips & Techniques 4 for more details about opacity.)

Built-in Methods cycleSmoke is a special built-in method for the smoke object. The duration of cycleSmoke is about 2 1/2 seconds. Several statements in the 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, the lightening bolt is moved to the position of the cloud. (The move to instruction is described in detail in Tips & Techniques 2.)

Testing When parameters are used in interactive programming, it is 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?