Variables and Inheritance Part 1 Alice. Review: Properties A class defines properties for its own kind of object. When an object is created (instantiated),

Slides:



Advertisements
Similar presentations
SimpleGameInAlice1 Barb Ericson Georgia Institute of Technology June 2008 Creating a Simple Game in Alice.
Advertisements

Visual Lists By Chris Brown under Prof. Susan Rodger Duke University July 2012.
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
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.
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 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.
Events Chapter 7. Interactive Real world is interactive User determines order of actions instead of programmer.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Python Magic Select a Lesson: Why Learn to Code? Basic Python Syntax
CS320n –Visual Programming Random Numbers and Random Motion (Slides 6-3) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CS320n –Visual Programming Interactive Programs Mike Scott (Slides 5-1)
Fall 2007ACS-1805 Ron McFadyen1 Chapter 4 OO Programming Concepts.
Calvin and Hobbes Teach Properties and Functions Created by Daniel MacDonald under the direction of Professor Susan Rodger Duke University June 2013.
Functions and Conditionals in Alice 1 Stephen Cooper Wanda Dann Barb Ericson September 2009.
Princess & Dragon Part 4: Breathing Fire—Adding Effects to Alice By Elizabeth Liang under the direction of Professor Susan Rodger Duke University June.
MrsBillinghurst. net A2 Computing A2 Computing Projects Game Animation in Pascal.
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June
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.
Tips & Techniques 4 Visible and Invisible Objects Alice.
Changing Camera Views! Part 2: Simple Scene Change & Lighting Fixes By Bella Onwumbiko under the direction of Professor Susan Rodger Duke University July.
Events (2) (Alice In Action, Ch 6) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Where are we? Alice is a “toy” language Fundamentals are exactly like “real”
Interactive Programming Sec 49 Web Design. Objectives The student will: Understand the difference between movie mode and an interactive program Understand.
Variables and Inheritance A More Complex Example Alice.
Lesson 9B Adding sound and Billboards. What is a function? Give an example. How do you create a method? Give an example. What is an event? Give examples.
Writing Our Own Functions Alice. Functionality A function receives value(s), performs some computation on the value(s), and returns (sends back) a value.
Functions Alice.
Variables and Inheritance Part 1
Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1,
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
Balancing the scales: Inequalities By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Variables and Functions Alice. Naming is Important If you get a new pet one of the first things you do is name it Gives you a way to refer to the new.
Functions Sec 8-11 Web Design. Objectives The Student will: Understand what a function is Know the difference between a method and a function Be able.
Copyright 2008 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Variables & Conditions.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
“everything is an object”. Class Template Code for defining an object Objects are created with NEW keyword (method) Namespace – (disambiguation) Context.
Lists Alice. Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing.
Lists Alice. Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing.
Lists Alice. Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing.
Skater World: Part Four By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1, 2009.
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 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
Headshots in Alice Duke University Professor Susan H. Rodger Gaetjens Lezin July 2008.
CompSci 4 Chap 10 November 4, 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.
PaintPictureBoxDemo Refers to the PaintPictureBoxDemo Visual Basic Program Included With The Lecture.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
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.
Creating a UFO Rescue Game in Alice
Tips & Techniques 4 Visible and Invisible Objects
Variables and Inheritance Part 2
Creating a UFO Rescue Game in Alice
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Class-level Methods Alice.
Variables and Inheritance Part 1
ICT Gaming Lesson 3.
Learning to Program: Part 3 Camera Control, Invisibility and 3-D Text
Tips & Techniques 4 Visible and Invisible Objects
Class-level Methods and Inheritance
Variables and Inheritance A More Complex Example
Presentation transcript:

Variables and Inheritance Part 1 Alice

Review: Properties A class defines properties for its own kind of object. When an object is created (instantiated), it receives its own set of properties.

State Each property stores some information about the object. Examples: vehicle isShowing The set of information about the object is called the state of the object.

State Change Instructions in our program code generally cause a change in a property value -- a state change. For example, a set instruction can be used to change the color of an object.

Class-level Variables New variables can be added to the properties list of an object. class-level The value of the variable can be changed We say the variable is mutable. This extends the capability of an object to track state changes.

Inheritance If the object (with its new variable) is saved out and given a new name, a new class is created. This is an example of inheritance. The new class inherits all the properties and methods (move, turn, roll, etc.) of the original class. Also, the new class has the newly declared variable and an extended capability to track state changes. In this session, we will look at a simple example of adding a new class-level variable and inheritance.

Example A switch is potentially useful as a controller for an animation switch handle up  animation running switch handle down  animation not running The problem is that the switch does not have a built-in property to track whether the switch handle is up or down.

Creating a new variable Create a new class-level variable named isOn. The isOn variable is declared to be a Boolean type. The value is initialized to true.

On-off Controller Storyboard The switch will act as an on-off controller. When the user clicks on the switch, the handle will turn in the opposite direction to provide a visual cue. A visual cue is helpful because variables are not visible. click: If isOn is true Do together set isOn to false turn the handle forward Else Do together set isOn to true turn the handle backward

switch.click isOn property value is Boolean, so we don't need to write switch.isOn == true

Save out Save out the switch as a new class. Rename the object (we used onOffSwitch) Right-click on the object name and select save object…

Import Now you can add an instance of the newly created class to a new world.

Event An instance of the new class has all the built-in properties and methods of the original Switch class, plus isOn variable click method Still, you must use the Events editor to link a mouse-click event to the click method.

Demo