World-level Methods with Parameters Alice. Larger Programs As you become more skilled in writing programs, you will find that your programs quickly begin.

Slides:



Advertisements
Similar presentations
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010 modified July 2011.
Advertisements

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.
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.
CSC1401 Animation Creating methods/instructions (class-level)
Parameters and World-level methods Alice. Our Dragon world The dragon must to take off and fly, to carry the princess.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
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.
Classes, Objects, and World-level Methods Alice. Programming in Alice© 2006 Dr. Tim Margush2 Class / Object Class A template describing the characteristics.
Animation Programs Alice. Overview 4-step process for creating animations Step 1: Understand Problem Step 2: Design Step 3: Implementation Step 4: Test.
Classes / Objects / Methods
Classes, Objects, and World-level Methods
Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.
Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.
Classes, Objects, and World-level Methods Alice. Larger Programs As you become more skilled in writing programs, you will find that programs quickly increase.
Classes, Objects, and World-level Methods Section 47 Web Design.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
CS320n –Visual Programming Introduction to Alice Mike Scott (Slides 2)
Classes, Objects, and World-level Methods Alice. Larger Programs As you become more skilled in writing programs, you will find that programs quickly increase.
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.
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.
Creating An Animation Program Part 2 Alice. Method A segment of program code (instructions) that defines how to perform a specific task.
CS329e – Elements of Visual Programming Implementing Programs Mike Scott (Slides 2-2)
Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University.
Animation Programs: Scenarios and Storyboards Alice.
Methods Tutorial: Part Two By Deborah Nelson Duke University Professor Susan Rodger June 16, 2008.
Now that the kangaroo and the turtle have raced, let's make a method for the kangaroo to hop back to the turtle and challenge him to a race again. Click.
Classes, Objects, and World-level Methods Alice. Larger Programs As you become more skilled in writing programs, you will find that programs quickly increase.
Animation Programs Alice.
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
CompSci 4 Chap 4 Sec 1 Sept 15, 2005 Prof. Susan Rodger.
CS320n –Visual Programming Classes, Objects, and World- Level Methods Mike Scott (Slides 4-1)
Classes, Objects, and World-level Methods MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
The Essentials of Alice Mrs. Jayne Slease SBMS CTE Computer Science and Animation Credit to Duke Students under the direction of Professor Susan Rodger.
Creating a 3D Interactive Story Prof. Susan Rodger Duke University July 19, 2007.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
World-level Classes Chapter 6 Part 2. Programs Grow Program code grows larger over time This makes it more difficult to read and process the code in our.
Creating An Animation Program Alice. Recall We began the animation creation process We introduced the concept of storyboard We will continue using the.
Creating an Animation Program Alice. The programming steps.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
Animation Programs: Scenarios and Storyboards Alice.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
Using Placeholders to Simplify your Methods: Learning Methods, Part 2 By Deborah Nelson Duke University Professor Susan Rodger June 16, 2008.
The Essentials of Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University May 2009.
Creating an Animation Program Alice. Step 1: Design Decide on the problem to be solved Design a solution We will use a storyboard design technique, commonly.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Classes, Objects, and World-level Methods
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.
Classes, Objects, and World-level Methods
Animation Programs: Scenarios and Storyboards
Classes, Objects, and World-level Methods
Making Objects Move in Unison: Using Lists
Classes, Objects, and World-level Methods
Classes, Objects, and World-level Methods
World-level Methods with Parameters
Classes, Objects, and World-level Methods
Making Objects Move in Unison: Using Lists
Class-level Methods Alice.
Classes, Objects, and World-level Methods
Methods Tutorial: Part Two
Alice 2.2 Introduction.
Learning to Program: Part 3 Camera Control, Invisibility and 3-D Text
Classes / Objects / Methods
Using Placeholders to Simplify your Methods: Learning Methods, Part 2
Animation Programs: Scenarios and Storyboards
Classes, Objects, and World-level Methods
Class-level Methods and Inheritance
Presentation transcript:

World-level Methods with Parameters Alice

Larger Programs As you become more skilled in writing programs, you will find that your programs quickly begin to increase to many, many lines of code. Games and other "real world" software applications can have thousands, even millions of lines of code. In this session, we begin to look at organizing large programs into small manageable pieces.

Goals of OOP organize a large program into small pieces design and think about an intricate program find and remove errors (bugs)

Modifying the program To make the snowpeople animation more realistic, we might want the snowman to be a little less shy. In our original program, the snowman tries to catch the snowwoman's attention only once. Perhaps he could try to get her attention more than once. To make this modification, additional lines would be added to the code. This would make the program code longer and more difficult to read and think about.

A Solution A solution to the problem is to define our own method name the new method catchAttention Then, we can drag-and-drop the catchAttention method into the edit box just like the built-in methods

Demo: The solution First, to associate the new method with the World select the World tile in the Object Tree select the methods tab in the details area click on the "create new method" button

Create a World Method Choose a meaningful name Edit the method

Demo A demonstration of writing the catchAttention method

World-level method catchAttention is a world-level method because it is defined as a method for World has instructions that involve more than one object (snowman, snowwoman, camera)

Using the catchAttention method The catchAttention method is executed by calling (invoking) the method from my first method

Why? Why do we want to write our own methods? saves time -- we can call the method again and again without reconstructing code reduces code size – we call the method rather than writing the instructions again and again allows us to "think at a higher level" can think “catchAttention" instead of “turn head to face the camera, then say ‘Ahem’ while moving eyes up and down" the technical term for "think at a higher level" is "abstraction"

Programming in Alice© 2006 Dr. Tim Margush12 moveInCircle Another candidate for a world method is one to move an object in a circle Here a world method does it to a car Adding spinning wheels would be fun, but complicate our example

Programming in Alice© 2006 Dr. Tim Margush13 Using moveInCircle Here we just do the maneuver twice What about moving different objects in a circle? Create a method for each???? No! That's what parameters are for!

Programming in Alice© 2006 Dr. Tim Margush14 Add an Object Parameter Edit the moveInCircle method and click the create new parameter button Give it a name Choose a type OK?

Programming in Alice© 2006 Dr. Tim Margush15 moveInCircle(whichObject) The parameter is named whichObject It holds the place of a real object that will be substituted later Replace all occurrences of car (in the method) with the parameter Just drag it into place drag

Programming in Alice© 2006 Dr. Tim Margush16 Test I got this error message when I tested my program The problem is in the call of this method We added a parameter We did not choose an argument Click to select the argument

Programming in Alice© 2006 Dr. Tim Margush17 Other Arguments Several additional choices come to mind How big of a circle? How long should it take? Which direction should it turn? moveInCircle(whichObject, radius, duration, direction) Add more parameters!

Programming in Alice© 2006 Dr. Tim Margush18 Adding Parameters Note the Types Number, Number, and Other Under Other, find Direction so you will be able to choose up, down, left, etc.

Programming in Alice© 2006 Dr. Tim Margush19 Adapting the Code The parameters will need to be dragged into the body of the method to replace the specific constants Convert radius to circumference

Programming in Alice© 2006 Dr. Tim Margush20 Advantages of Methods Abstraction Methods allow the programmer to organize details of a task under the method's name Code reuse Methods can be called several times without having to copy the details of the code Generality Parameters allow the same actions to be applied to a variety of objects Debugging and maintenance Fixing or changing part of a program may only require modification of a single method

Assignment World-level Methods How to create them How to call them When it is appropriate to use them Lab 05