CompSci 4 Chap 5 Sec 2 Oct 18, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.

Slides:



Advertisements
Similar presentations
CS320n –Visual Programming Class-level Methods and Inheritance – Part 1 Mike Scott (Slides 4-3-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger.
Advertisements

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 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.
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.
CompSci 18S Recursion Dec 4, 2006 Prof. Susan Rodger.
Parameters and Event-Handler Methods Sec 50 Web Design.
CS320n –Visual Programming Random Numbers and Random Motion (Slides 6-3) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
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.
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.
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
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.
CompSci 4 Chap 7 Sec 2 Apr 7, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
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.
Parameters and Event-Handler Methods MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
CompSci 4 Chap 8 Sec 1 Nov 17, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
Interactive Programming Sec 49 Web Design. Objectives The student will: Understand the difference between movie mode and an interactive program Understand.
What we will do today Learn about functions in Alice.
CS320n –Visual Programming Introduction to Recursion (Slides 8-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CS320n – Elements of Visual Programming Lists Mike Scott (Slides 9-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
CS320n – Elements of Visual Programming Sending Parameters to Event Handler Methods (Slides 5-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
CompSci 4 Chap 4 Sec 1 Sept 15, 2005 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.
Questions Alice. Functionality A question receives value(s), performs some computation on the value(s), and returns (sends back) a value.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
CS320n –Visual Programming Definite / Counted Loops (Slides 7-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
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.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
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.
CompSci 4 Chap 9 Sec 1 October 28, 2010 Prof. Susan Rodger.
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.
CompSci 4 Chap 10 Nov 22, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
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.
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
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Parameters Alice.
CS320n –Visual Programming
Class-level Methods Alice.
CS320n –Visual Programming
Parameters and Event-Handler Methods
Parameters and World-level methods
Parameters and Event-Handler Methods
Parameters and Event-Handler Methods
Class-level Methods and Inheritance
Parameters and Event-Handler Methods
Presentation transcript:

CompSci 4 Chap 5 Sec 2 Oct 18, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas

Announcements Read Chapter 6 Tips and tech for next time Assignment 5 –Part 1, due today –Part 2, due next week

What we will do today Lecture on Chap 5, Sec 2 –Event-handlers with parameters Classwork

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 People are trapped in a burning building Select which person will be rescued

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?

Demo Demonstration of the code for firetruck.savePerson

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 2 – 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

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 prepareToShoot Parameter: target Do together turn Zeus to face the target make the lightning bolt visible lightning and Thunder: 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 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.

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 effects

specialEffects Smoke.cycle is a built-in instruction with a duration of about 2 ½ seconds

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) –Problem 14, page 140 –Problem 15, page 141 (can use any person)