Variables and Inheritance Part 1

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 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.
Arrays and Array Visualization
Fall 2007ACS-1805 Ron McFadyen1 Chapter 4 OO Programming Concepts.
MrsBillinghurst. net A2 Computing A2 Computing Projects Game Animation in Pascal.
Making a Timer in Alice.
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
Arrays and Array Visualization Alice. What is an array? An array is a collection of objects or information that is organized in a specific order. The.
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.
The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.
Variables and Inheritance A More Complex Example Alice.
Making a Timer in Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University July
Variables and Inheritance Part 1
Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July
Computer Game Design ActionScript is… Object-oriented programming Everything you do in ActionScript does something to some object* Some objects.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Countdown Clock 60-minute version
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
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.
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),
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.
Class-Level Variables in Alice
Parameters Section 8-8 Web Design.
Variables.
Programming: Simple Control Structures
Arrays and Array Visualization
Variables and Inheritance Part 2
Programming: Simple Control Structures
Making a Timer This is an modification of the July 2008 timer tutorial by Jenna Hayes By Natalie Huffman Under the direction of Susan Rodger Duke University.
Functions CIS 40 – Introduction to Programming in Python
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Text Section 2.3 Pages
Parameters Alice.
Programming: Simple Control Structures
Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline Test-Driving the Microwave Oven Application Designing.
Class-level Methods Alice.
Lists Alice.
Lists Alice.
Programming: Simple Control Structures
Parameters and World-level methods
Interactive Programming
Programming: Simple Control Structures
Programming: Simple Control Structures
Lists Alice.
Presentation Companion Slide Pack
Assignment Operators Topics Increment and Decrement Operators
Functions Alice.
ICT Gaming Lesson 3.
Programming: Simple Control Structures
Game Over Module 4 Lesson 2.
Assignment Operators Topics Increment and Decrement Operators
Assignment Operators Topics Increment and Decrement Operators
The Web Wizard’s Guide To JavaScript
Parameters Alice.
Functions Alice.
Programming: Simple Control Structures
Class-level Methods and Inheritance
Assignment Operators Topics Increment and Decrement Operators
Interactive Programming
Functions Alice.
under the direction of Professor Susan Rodger
Functions Alice.
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 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. The new variable is 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.

Example Game programs often make use of a timer – some mechanism to keep track of the time remaining in the game. We will construct a timer. First, add a 3D text object to the world. Any string of digits could be used. We arbitrarily chose "0.0"

Creating a new variable Select the timer object and then create a new variable named timeLeft. The isOn variable is declared to be a Number type. The value is 0 (the game hasn't begun, as yet).

Start the timer At the start of the game, the timer's timeLeft variable must be initialized to the amount of time allowed for playing the game. (This example uses seconds, but minutes would work just as well.) Storyboard for a method to initialize the timeLeft variable: initialize parameter: amountOfTime timeLeft is set to a value specified by amountOfTime

Counting down In this example, the timer will count down to 0 (no seconds left on the clock). Storyboard for a countDown method: countDown Do in order While timeLeft is greater than 0 update the 3D text to show the remaining number of seconds decrease timeLeft by 1 update the 3D text to display 0 seconds Note: The last instruction updates the 3D text display after the While loop ends .

class-level function To coordinate the game with the timer's countdown, write a function that returns the value of the timeLeft variable.

Demo Ch10Lec1aTimer Concepts illustrated in this example The value in a variable can be used in a conditional expression to control a loop. The value of timeLeft is compared to 0. The value in a variable can be changed at runtime. The value of timeLeft is decreased by 1 each time through the While loop. A number can be displayed as a text string by calling a built-in conversion function (as a string).

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

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.

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

Assignment Read Chapter 10 Section 1, up to page 257.