Introduction to Object-Oriented Programming in Alice

Slides:



Advertisements
Similar presentations
Create a Simple Game in Scratch
Advertisements

Mike Scott University of Texas at Austin
Create a Simple Game in Scratch
Introduction to Object-Oriented Programming in Alice and Java
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Alice: A Free 3D Animation World for Teaching Programming Barbara Ericson Georgia Institute of Technology Oct 2005.
Creating a 3D Interactive Story Prof. Susan Rodger Duke University Feb. 24, 2007.
Alice Learning to program: Part 1 Scene Setup and Starting Animation by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke.
01-Intro-Object-Oriented-Prog-Alice1 Barb Ericson Georgia Institute of Technology Aug 2009 Introduction to Object-Oriented Programming in Alice.
Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Georgia Institute of Technology Barb Ericson Georgia Institute of Technology May 2006 Teaching Java using Turtles part 1.
Graphics Movies & Games. Jump In! Feeling sleepy and stupid… Extract the Alice from the zip archive and copy it to C:\Programs.
Getting started with Alice Adapted from presentations by Jenna Hayes, Duke University Donna Gavin, UWP Computer Science and Software Engineering.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
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.
Georgia Institute of Technology Pictures and Alice Barb Ericson Georgia Institute of Technology September 2006.
Georgia Institute of Technology Simulations Barb Ericson Jan 2005.
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
Creating a 3D Interactive Story Prof. Susan Rodger Duke University July 19, 2007.
Learning to Program: Part 1 Scene Setup and Starting Animation by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University,
Georgia Institute of Technology Barb Ericson Georgia Institute of Technology Aug 2006 Introduction to Object-Oriented Programming in Alice and Java.
Alice: A Free 3D Animation World for Teaching Programming.
Georgia Institute of Technology Barb Ericson Georgia Institute of Technology Sept 2006 Introduction to Object-Oriented Programming in Alice and Java.
The Essentials of Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University May 2009.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Jonathon Kuo Under the Direction of Dr. Susan Rodger
The Essentials of Alice (Bunny)
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Getting Started With Alice: The Basics
Create a Halloween Computer Game in Scratch
Scratch for Interactivity
An Introduction to Alice (Short Version)
Teaching Characters to Walk: Learning Methods, Part 1
Appendix A Barb Ericson Georgia Institute of Technology May 2006
An introduction to programming Created by Dr. Randy Pausch
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Programming Logic Alice.
Introduction to Object-Oriented Programming in Alice and Java
Graphics Movies & Games
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
The Essentials of Alice
Teaching Java using Turtles part 1
Programming using Alice 3
Michelle Venable-Foster Barb Ericson Jan 2007
Alice in Action with Java
Alice Variables Pepper.
Alice: Beyond the Basics
Making Objects Move in Unison: Using Lists
An Introduction to Alice
Scratch for Storytelling
Barb Ericson Georgia Institute of Technology Oct 2005
Introduction to Object-Oriented Programming in Alice and Java
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events
Alice: A Free 3D Animation World for Teaching Programming
Getting Started With Alice
Alice: A Free 3D Animation World for Teaching Programming
Professor Susan Rodger
Professor Susan Rodger
Getting Started With Alice: The Basics
Michelle Venable-Foster June 2006
Professor Susan Rodger
Making Objects Move in Unison: Using Lists
Creating a Simple Game in Scratch
Teaching Java using Turtles
under the direction of Professor Susan Rodger
Presentation transcript:

Introduction to Object-Oriented Programming in Alice Barb Ericson Georgia Institute of Technology July 2009 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Learning Goals Introduce computation as simulation Introduce Alice Create objects in Alice Invoke methods on objects in Alice Create a method in Alice Pass a parameter to a method in Alice Introduce subclasses 01-Intro-Object-Oriented-Prog-Alice

Computers as Simulators “The computer is the Proteus of machines. Its essence is its universality, its power to simulate. Because it can take on a thousand forms and serve a thousand functions, it can appeal to a thousand tastes.” Seymour Papert in Mindstorms 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Creating a Simulation Computers let us simulate things We do this by creating models of the things we want to simulate We need to define what types of objects we will want in our simulation and what they can do Classes define the types and create objects of that type Objects act in the simulation 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Running a Simulation How many objects does it take to get a person fed at a restaurant? Pick people to be the customer, greeter/seater, waiter, chef, and cashier and have them role play What data does each of these people need to do his or her job? What does each type need to know how to do? What other objects do you talk about? How about simulating going to a dentist? Or to the movies? 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Introduction to Alice Free development environment From Carnegie Mellon University Available from http://www.alice.org Used to create 3D movies 3D games 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Getting Started Install Alice Pick CD2 Windows – copy Alice 2.2 folder Macs – click on MacScratch1.4.dmg Start Alice Double Click on Icon (Alice.exe) Wait for Alice to start Can take a few minutes 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Turning On Java Syntax Click in Edit and then Preferences Change the display my program: from Alice Style to Java Style in Color Quit Alice and start it up again It will keep this setting until you change it again 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Pick a World Click on the Examples tab And click on a world to open it You might need to scroll down to see this world 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Playing the Movie To play a saved world Click the Play button The movie or game will start to play in a separate window Click on target to play this movie Most example worlds will just start to play 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Create Your Own Movie Click on File Then New World Click on a template Background and ground type 01-Intro-Object-Oriented-Prog-Alice

Add Objects To the World Click the Add Objects button Select a category from the Local Gallery Select Local Gallery to get back from a category To the list of categories Use the Search Gallery button to look for a certain type 01-Intro-Object-Oriented-Prog-Alice

Add Objects to the World Click on the item to select it Click on the Class description Click Add Instance to world Button Or drag the object from the class description and drop it into position in the world 01-Intro-Object-Oriented-Prog-Alice

Position an Object in the World Once the object is in the world You can move it by Dragging it with the mouse Or using the mouse controls Click the Undo button to undo the last action 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Mouse Controls Use mouse control buttons (from left to right) To move object left, right, forward, back Up and down Turn left or right Turn forward or backwards Tumble the object (free rotation) Resize object Copy the object You can click the Undo button at the top left (next to the Play button) to undo the last operation. 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Create More Objects You can use the copy object mouse control Or add another instance to the world Click on the Class Click on the Add instance to world button Or drag another object from the class description 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Objects and Classes You can make many objects of the same class The class creates the object Each object will have a unique name in the object window (a reference) bunny, bunny2, bunny3 Class names start with a capital letter Object names start with a lower case letter 01-Intro-Object-Oriented-Prog-Alice

Telling Objects To Do Things Click the Done button to stop adding objects Click on a reference to an object in the object tree window to select it Click on the Methods tab to see what it can do 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Messages to Objects In object-oriented programming we send messages to objects Drag a method from the left to the middle window (world - my first method) A green line will show you were it will go 01-Intro-Object-Oriented-Prog-Alice

How to Execute my_first_method Click on the Play button This starts the world When the World starts it will execute the method my_first_method 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Method Syntax Syntax is how statements need to be formed in a programming language The syntax for a method call on an object is: objRef.method(parameterList); We call this “dot” notation 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Who does the action? We had selected bunny in the object tree window Before we dragged the method So the method is invoked on bunny How do you think we can get bunny2 to do the same action? 01-Intro-Object-Oriented-Prog-Alice

Moving Several Objects To get bunny2 to move Select bunny2 in the object tree window Or just click on it Then select the method tab Drag out the same methods for bunny2 Click play to see what happens 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Sequential Execution By default all Alice methods are executed one after the other You can specify this explicitly using a doInOrder control structure Drag it from here And drag the other statements into it What happens when you play it again? 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Parallel Execution What if you want two or more statements to execute at the same time? Use a doTogether Put the things that you want to happen at the same time in the doTogether block We added methods to make each bunny say hello as it goes up What happens if you put a move up and move down in a doTogether? If you put two items that “cancel” each other out in a doTogether like move up and move down by the same amount you won’t see any movement. 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Challenge Create a world in Alice with at least 2 objects of the same class and at least 3 objects from different classes Have each object do some actions Some at the same time Some one after the other (sequential) You can use say to have objects “talk” to each other 01-Intro-Object-Oriented-Prog-Alice

Creating a Method in Alice You can create behaviors (methods) in Alice Let’s teach our bunny how to hop Click on bunny in the object tree window Then click on the create new method button Make sure you create the hop method on the bunny and not on some other object. We want to teach bunnies to hop and not worlds! 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Naming the Method We name methods starting with a lowercase letter So name this method hop Now drag in the commands to make the bunny hop The bunny should go up and forward and then go down and forward Use doTogether to do two things at the same time Use doInOrder to do things one after the other 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Changing the Amount You can change the amount to go forward by Click on the downward arrow next to the current amount Pick one of the values or use other to enter a number 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Try Out the Method Click on the world.my first method tab This is the method that runs when you click on play Drag in the hop method Click play to try it And see what it does 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Having bunny2 hop If you click on bunny2 it won’t have the hop method It was created before you added this method to the Bunny class So delete bunny2 Click right on it in the object tree and select delete Click on the add objects button to get the mouse controls back And make a copy of bunny And position it with the mouse controls Then click the done button 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Adding bunny2 hopping Click on bunny2 in the objects window Click the method tab See that bunny2 now has a hop method as well Drag the hop method to the world.my first method There is an implicit doInOrder around these 01-Intro-Object-Oriented-Prog-Alice

Adding parameters to Alice Methods To add a parameter to a method in Alice Click on the method tab Click on the create new parameter button Name the parameter and pick the type Change the code to use the parameter Click down arrow and pick expressions and then the parameter 01-Intro-Object-Oriented-Prog-Alice

Trying a Method with a Parameter Specify the value for the parameter when the method is called You can’t use this new method with bunny2 Since it was created before you changed the method So delete bunny2 and create a new copy of bunny 01-Intro-Object-Oriented-Prog-Alice

Creating Subclasses in Alice When you create a new method in Alice or modify an existing method You are in affect creating a new subclass that has that method or that version of the method A subclass inherits the fields and methods from the parent class but can add new fields and methods or change inherited ones You should name and save this subclass So you can reuse it 01-Intro-Object-Oriented-Prog-Alice

Saving a Subclass in Alice Rename the variable that refers to the object Right click on it in the Object tree and select rename Save the class Right click on the object in the Object tree and select save object It will save the class definition which starts with an upper case letter 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Use a Subclass in Alice Select File and then Import And select the class file you created This will automatically add an object of the new class to your world You may need to move the new object to see it 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Challenge Create a subclass from one of the existing Alice classes With at least two new methods in the subclass Be sure to use the new methods in the movie Have at least two objects of the subclass in the movie Have at least two objects of other classes in the movie 01-Intro-Object-Oriented-Prog-Alice

01-Intro-Object-Oriented-Prog-Alice Summary You can create objects from classes in Alice Each object needs a unique way to refer to it You can create new methods Let’s you reuse a block of statements You can pass parameters to methods To make them more flexible and reusable You can create subclasses of other classes They will inherit fields and methods from the parent class 01-Intro-Object-Oriented-Prog-Alice