Interaction: Events and Event Handling

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.
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.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Parameters and Event-Handler Methods Sec 50 Web Design.
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.
CS320n –Visual Programming Interactive Programs Mike Scott (Slides 5-1)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley This week: Whew!!! The last homework was tough! The homework for this week.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
CS 0004 –Lecture 1 Wednesday, Jan 5 th, 2011 Roxana Gheorghiu.
Execution Control with If/Else and Boolean Functions Sec 52 Web Design.
Introduction to Scratch!
Alice Project 1 Web Design. Electronic Greeting Card or Music Video Electronic Greeting Card: Build an animation for an electronic greeting card (any.
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.
Alice Project 1 Web Design. Electronic Greeting Card Build an animation for an electronic greeting card (any occasion you choose – birthday, get well,
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.
Exploring Computer Science 2/23/15 2/23 Develop a Scratch story project -Brainstorming 2/24 Develop a Scratch story project –Developing 2/25 Develop a.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
Exploring Computer Science 2/16/15
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.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
Events (Alice In Action, Ch 6) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
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.
Review for test! Alice Chapter 1&2 Test is tomorrow! - March 26 th March 25th.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
Chapter 5 Interaction: Events and Event Handling.
CompSci 4 Chap 5 Sec 2 Oct 9, 2008 Prof. Susan Rodger.
5 Event Handling Interactive Programming Suggested Reading Interaction: Events and Event Handling, Supplemental Text for CPSC 203 Distributed this term.
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 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
Fall 2008ACS-1805 Ron McFadyen1 Event-driven programming Chapter 5 covers event-driven programming. Events are user or condition driven and so each event.
CompSci 4 Chap 5 Sec 1 and 2 Oct 14, 2010 Prof. Susan Rodger.
Presenter: Carol Liss Timberlane Regional Middle School 6 th and 7 th grade Tech. Educator Co presenters:
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Introducing Scratch Learning resources for the implementation of the scenario
Alice Project 1 Web Design.
Parameters and Event-Handler Methods
Starting Out with Alice: A Visual Introduction to Programming
Event-driven programming
Introduction to Events
Class-level Methods Alice.
Learn… Create… Program
Parameters and Event-Handler Methods
Learn… Create… Program
Interactive Programming
Parameters and Event-Handler Methods
Parameters and Event-Handler Methods
Learn… Create… Program
Learn… Create… Program
Event-driven programming
Parameters and Event-Handler Methods
Interactive Programming
Presentation transcript:

Interaction: Events and Event Handling Chapter 5 - Alice Interaction: Events and Event Handling

Interactive Program –vs- Non-Interactive Program What is the main difference? The sequence of actions is determined at runtime! Occurs when: The user clicks the mouse Presses a key on the keyboard Objects in the scene move (randomly or guided by the user) User can create some conditions like a collision. Non-Interactive The sequence of actions is pre-determined by programmer Programmer designs a complete storyboard Programmer writes the program code for the animated actions. Every time the program runs the same sequence will occur.

What is an Event? An event is something that happens. Every time the user clicks the mouse or presses a key on the keyboard to send a signal to Alice about what to do next. The mouse click or key press is an event! In this chapter we learn the mechanics of how the user create an event and how the program responds to the event. Example: think of a video game – A Car Race. The scene is determined on how skillful the driver is steering the car.

Event handling method! How does it affect what I do? As a animation programmer you must think about all possible events and make plans for what should happen. You need to response to the events. Remember: When the event handling method occurs, the location of objects in the scene may or may not be the same as the last time.

Biplane Example: Is an interactive program! Biplane is in mid-air and the user is able to fly the plane. The plane can move forward, left, and right and a barrel turn. The user uses the keyboard and mouse to provide interaction. The whole idea is to let the user interact with the biplane.

Biplane Example: Has two events: The spacebar press for the barrel turn and the up arrow key to move the biplane forward. Event: Spacebar Response: Do together roll biplane a full revolution Play biplane engine sound Event: Up arrow key press Response: Do together move biplane forward play biplane egine sound Page 122 to 123. Just follow the steps.

Testing! How to test? Just save the world and press the PLAY button. Tip: It is important to test event handling methods as they are developed. Write a method and test it, write a method and test it, until the program is completed. Why? Incremental development! The advantage is in making it easier to debug your program. When something isn’t working, it can easily be fix before it causes bigger problems elsewhere in your program.

Parameters and event handling methods: Parameters are powerful! They allow us to customize methods to work with different objects and different numeric values. Take a look at the Firetruck/Burning Building example. (page 125 to 127, just follow the steps)

Burning Building Example: Another interactive program that shows how to use parameters in event handling methods. Firetruck is called to a burning building. The truck will need to extend its ladder so that each person can climb down to safety.

Burning Building Example: Three Events are: Event: Click on guy1 Responding Method: Save guy on the first floor Event: Click on girl2 Responding Method: Save girl on the second floor Event: Click on girl3 Responding Method: Save girl on the third floor Are all these events necessary? Why three? Can we do the same in one event?

Burning Building Example: A better solution is to write only one event and send the information to the action. Look: savePerson Parameters: whichFloor, whichPerson, howFar Do in order: Point ladder at whichFloor Extend the ladder howFar meters whichPerson slides down the ladder to the firetruck Pull the ladder back howFar meters Take a look at the program. Follow the steps on page 125 to 127

A Greek tragedy! A more complex program! Responses to an event may involve multiple actions. Can be a bit messy! Use stepwise refinement! Break up your instructions into small steps. In Greek mythology, Zeus was an all-powerful god. If Zeus was angered, a thunderbolt would be shot out of the heavens and strike anyone who got in the way. In this program, the tunderbolt has been hidden in a cloud and smoke is waiting 5 meters below the gound. To make this program interactive, we will let the user choose the object that will be the next victim of Zeus’s anger. When the user clicks the object, the object will be passed to the event handling method. We have alot of actions going on in this program.

A Greek tragedy! We need a parameter to send in the object that was click. This may contain lots and lots of coding we simply break it down (stepwise refinement) it the following: 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 lightingAndThunder method-send who as the target Lightning move to cloud’s position Take a look at the program. Follow the steps on page 129 to 134.

For Today: Re-read chapter 5! Take notes for yourself. (You can use them on the test) Complete the worksheet questions. You have 5 of them! Answers in Chapter 5. Finish with the examples in Chapter 5. Last chance if you want credit. Plane Program – Page 121 to 124 Burning Building – Page 125 to 127 A Greek Tragedy – Zeus – Page 128 to 134 Page 137, #5 Rotational Motion Program. Project 1 – Due Wednesday, February 11th before you leave.

Alice Project #1 for Semester Two! Due Date is Wednesday, February 11th. Problem: Build an animation for an electronic greeting card for Valentine’s Day. You can get ideas from the following web sites: free.bluemountain.com or greetings.yahoo.com The animation is to be a program that is interactive. Use the material from Chapter 5. You are also to create a storyboard for your animation. The storyboard should be done first. Templates on Web Site – www.prosseracademy.org You will give a presentation next week where you are required to show off your storyboard and then demonstrate a working version of your program. Grading is to be as follows: Storyboard: 25% Presentation: 25% Program: 50% Instructions: Create your Valentine’s Greeting Card. Save to your flash drive and bring to my computer. Be prepared to present on Tuesday, February 17th.