Parameters and Event-Handler Methods Alice. Mouse clicks Interactive programs often allow the user to mouse click an object in the display. buttons in.

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

Class-level Methods and Inheritance Part 1 Alice.
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 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.
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 Alice.
Repetition Structures
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.
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.
Fall 2007ACS-1805 Ron McFadyen1 Ch 9 Lists In some animations, several objects must perform the same actions Example: A marching band, where the band members.
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.
Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.
Execution Control with If/Else and Boolean Functions Sec 52 Web Design.
Classes, Objects, and World-level Methods Alice. Larger Programs As you become more skilled in writing programs, you will find that programs quickly increase.
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.
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 MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
Execution Control with If/Else and Boolean Functions Alice.
What we will do today Learn about functions in Alice.
Programming: Simple Control Structures Part 2 – Repetition Alice.
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.
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.
Questions Alice. Functionality A question receives value(s), performs some computation on the value(s), and returns (sends back) a value.
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.
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 Alice. A beetle band Our task is to create an animation for a bug band as an advertisement for their next concert.
Parameters Alice. Overview The need for more flexible methods Passing a parameter to a method Demos Using the Alice interface to write code for a parameter.
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.
Parameters and Event-Handler Methods
While: Indefinite Loops
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Parameters Alice.
Class-level Methods Alice.
CS320n –Visual Programming
Parameters and Event-Handler Methods
List Search Alice.
Parameters and World-level methods
Parameters and Event-Handler Methods
Parameters and Event-Handler Methods
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
List Search Alice.
Parameters 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.
Class-level Methods and Inheritance Part 2
Presentation transcript:

Parameters and Event-Handler Methods Alice

Mouse clicks Interactive programs often allow the user to mouse click an object in the display. buttons in a windows-based interface targets in a game checklist of items on a form In this session, we look at how to pass information about a mouse clicked object to an event handler method.

Example People are trapped in a burning building and the user will select which person will be rescued next.

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 Demonstration of the code for firetruck.savePerson

Three events The argument sent to the parameters depends on which person is mouse clicked. NOTE: in setting up our demo world, we positioned the fire truck so the distance of the ladder from the 1 st floor is 1 meter, 2 nd floor is 2 meters, and 3 rd floor 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’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

A driver The shootBolt method is at the top level of our design. It calls other methods (prepareToShoot and lightningAndThunder) 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.

prepareToShoot In setting up the initial scene, we made the lightning bolt invisible by setting its opacity to 0 (0%). (Review Tips & Techniques 4 for more details about opacity.) To prepare to shoot the lightning bolt, it must be made visible – set the opacity back to 1 (100%).

lightningAndThunder Coordinate the sound of thunder with lightning and other special effects.

specialEffects The smoke.cycleSmoke is a built-in instruction with a duration of about 2 1/2 seconds.

move to 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.)

move to with an object parameter If an object parameter is used to specify a target position, the process of creating a move to statement involves two steps: 1)Drag in an arbitrary object as the parameter 2)Substitute the object parameter name This subterfuge is necessary because an Object parameter is only a placeholder for an object – not an actual object.

Demo Test run of Zeus world. 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?

Assignment Read Chapter 5-2, Parameters with Interactive Programming Read Tips & Techniques 5 Lab 5-2