Alice Inheritance and Event Handling. Inheritance Concept Consider this hierarchy; parents describe properties of children Animals Vertebrates MammalsFish.

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.
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.
PIIT Computer Science Summer Camp - Alice July 11, 2012 Brenda Parker Computer Science Department MTSU.
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.
CMSC 202 Inheritance. Aug 6, Object Relationships An object can have another object as one of instance variables. The Person class had two Date.
Comp 249 Programming Methodology Chapter 7 - Inheritance – Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University,
Slides prepared by Rose Williams, Binghamton University Chapter 7 Inheritance.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 5 Interactive Programs.
CS102--Object Oriented Programming Lecture 7: – Inheritance Copyright © 2008 Xiaoyan Li.
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)
Interaction: Events and Event Handling
Introduction to Alice Alice is named in honor of Lewis Carroll’s Alice in Wonderland.
01-Intro-Object-Oriented-Prog-Alice1 Barb Ericson Georgia Institute of Technology Aug 2009 Introduction to Object-Oriented Programming in Alice.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Programming Alice Alice is named in honor of Lewis Carroll’s Alice in Wonderland.
Welcome! The Topic For Today Is…Review for Test. Your Topic Basics of Programming Control Statements Programming Concepts InteractionAlice Concepts 200.
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.
Interaction: Events and Event Handling
Alice Learning to program: Part Three Camera Control, Invisibility, and 3-D Text By Ruthie Tucker and Jenna Hayes, Under the direction of Professor Rodger.
Review For Test Chapter 4 & 5 Test is Wednesday, January 27th.
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.
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.
Interactive Programming Sec 49 Web Design. Objectives The student will: Understand the difference between movie mode and an interactive program Understand.
An Introduction to Alice (Short Version) – Extras! Yossra Hamid Under the Supervision of Professor Susan Rodger Duke University, June 2014 This is a continuation.
CMSC 202 Inheritance I Class Reuse with Inheritance.
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.
CS320n – Elements of Visual Programming Sending Parameters to Event Handler Methods (Slides 5-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
Computer Game Design ActionScript is… Object-oriented programming Everything you do in ActionScript does something to some object* Some objects.
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.
5 Event Handling Interactive Programming Suggested Reading Interaction: Events and Event Handling, Supplemental Text for CPSC 203 Distributed this term.
Understanding JavaScript and Coding Essentials Lesson 8.
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.
CompSci 4 Chap 5 Sec 1 and 2 Oct 14, 2010 Prof. Susan Rodger.
Using Placeholders to Simplify your Methods: Learning Methods, Part 2 By Deborah Nelson Duke University Professor Susan Rodger June 16, 2008.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Variables and Inheritance Part 1 Alice. Review: Properties A class defines properties for its own kind of object. When an object is created (instantiated),
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
1 Quiz Show Programming Terms. 2 Alice - 3D Virtual Programming Vocabulary Quiz Board Chapter 1 Chapter 2a Chapter 2b Chapter 3 Chapter 4 $100 $200 $300.
Parameters and Event-Handler Methods
Getting started in Alice
Obj: Introduction to Alice
Introduction to Events
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Introduction to Alice Alice is named in honor of
Comp 249 Programming Methodology
Inheritance I Class Reuse with Inheritance
CMSC 202 Inheritance.
Class Reuse with Inheritance
Interactive Programming
Introduction to Alice Alice is named in honor of
Introduction to Object-Oriented Programming in Alice
ICT Gaming Lesson 3.
Introduction to Alice Alice is named in honor of
Event-driven programming
Class-level Methods and Inheritance
Interactive Programming
Chapter 7 Inheritance.
Presentation transcript:

Alice Inheritance and Event Handling

Inheritance Concept Consider this hierarchy; parents describe properties of children Animals Vertebrates MammalsFish Carnivores BearsCatsDogs

Introduction to Inheritance Inheritance is one of the main techniques of object- oriented programming (OOP) Using this technique, a very general form of a class is first defined and compiled, and then more specialized versions of the class are defined by adding properties and methods – The specialized classes are said to inherit the methods and properties of the general class

Introduction to Inheritance Inheritance is the process by which a new class is created from another class – The new class is called a derived class – The original class is called the base class A derived class automatically has all the properties and methods that the base class has, and it can have additional methods and/or properties as well Inheritance is especially advantageous because it allows code to be reused, without having to copy it into the definitions of the derived classes

Derived Classes When designing certain classes, there is often a natural hierarchy for grouping them – In a record-keeping program for the employees of a company, there are hourly employees and salaried employees – Hourly employees can be divided into full time and part time workers – Salaried employees can be divided into those on technical staff, and those on the executive staff

Derived Classes All employees share certain characteristics in common – All employees have a name and a hire date – The methods for setting and changing names and hire dates would be the same for all employees Some employees have specialized characteristics – Hourly employees are paid an hourly wage, while salaried employees are paid a fixed wage – The methods for calculating wages for these two different groups would be different

A Class Hierarchy

Inheritance in Alice Alice supports a rather weak form of inheritance; a more powerful/complex version exists in most OOP languages like Java, C++, or C# – Add existing class to the project – Create new methods for the class – Save out as a new class using a different name – Can now Import the new class and it has the properties/methods of the parent along with the new methods – TO DO: Demonstrate creating and saving new class The process is more dynamic and seamless in other OOP languages

Guidelines for Class-Level Methods Create many different class level methods and study methods already written for some objects (e.g. see animal classes) Play a sound in a class level method only if the sound has been imported for the object, instead of the world – Not loaded if imported into another world Do not call world level methods from class level methods Do not use instructions for other objects from within a class level method – Possible exceptions include camera, world objects

Interaction: Events and Event Handling To date, most of our programs have been movie- centric Many programs are user-centric, requiring user input One way to get user input is through events An event is when something happens, like a particular condition is met, the user clicks the mouse, hits a key, or some other action is performed – We can write methods that react to events, such methods are called event handlers

Event Example Create keyboard control for a biplane – Up turns backward, down turns forward, left turns left, right turns right – Loop for always moving forward

Create Methods and Events Create separate methods for turning left, right, up, and down Click to create an event and pick the method and key that will activate the method Complete the events to control the biplane – Can experiment with rolling

Example

To Do: Add another event that completes a barrel roll when the spacebar is pressed Simulate a plane crash into the building – Create a new Biplane variable under its Properties named “Flying” and set to True – While true, the plane is flying, if false, it has crashed

Plane Crash In the world method, the plane should only go forward if it is flying Make a new biplane method, Crashed, that moves the plane to the ground and sets flying to false

Plane Crash Add event : while some condition, do event handler. In this case, crash if the plane is close enough to the building

Events and Parameters Event handlers can also take parameters, just like any other method For example, we can create a method that takes an Object parameter, then the object to send in can be specified in the Event Example: Zap Euripides and Socrates with lightning when clicked – Add Euripides, Socrates, Lightning, Animated Fire but set lightning and fire’s visible property to false

Lightning Create a world method, LightningZap – Should take a parameter, the object to zap – Position the lightning above the object – Make the lightning visible – Move the lightning to the object – Make the lightning not visible – Move the fire to the object – Make the fire visible – Make the fire invisible – Make the object spin and disappear

LightningZap Method Can test by invoking it from the Main method

Using LightningZap in a Click Event Create a new click event for whatever the mouse is under Send in the object clicked as the parameter for LightningZap

Class Exercise Penguin Slide – Create a world with a lake scene and three penguins. Allow the user to click on a penguin and make it slide down the slope into the water then disappear. Add a parameter to control how many times the penguin spins as it slides. – Hint: Use an invisible object as the target