1 / 15

Alice Programming

Alice Programming . Chapter 4 Classes, Objects, Methods and Parameters. Class. A Class defines a particular kind of object In Alice, they are predefined as 3D models Class names begin with a capital letter When an object is created this is called instantiating the class

Melvin
Download Presentation

Alice Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Alice Programming Chapter 4 Classes, Objects, Methods and Parameters

  2. Class • A Class defines a particular kind of object • In Alice, they are predefined as 3D models • Class names begin with a capital letter • When an object is created this is called instantiating the class • This is because instantiating the object creates an instance of that class

  3. Objects • Objects are instances of a class • Object names begin with lowercase letters • For example, spike is the object from the class named Dog • mary is the name of the object from the class named Person • We can have an unlimited number of objects from the same class (we can have several snowmen each with different names)

  4. Methods • A method is a sequence of instruction that complete a particular task. • Alice has many built-in methods for each class. These are called primitive methods. • Methods divide a program into small, manageable pieces that work together to create a meaningful whole.

  5. Methods • Some methods need to be sent certain pieces of information in order for them to work correctly. • A move method needs to told in which direction to move. • Parameters are used to hold specific items of information that are then passed to a method.

  6. Creating your own methods • In Alice, you can define methods for an object acting along. • You can also define a method for two or more objects interacting with one another. • Methods that specifically reference more than one object are world-level methods. • Methods that define a behavior for a single object are called class-level methods.

  7. Creating your own methods • Methods are “called”. This causes the instructions in the method to be run.

  8. Stepwise Refinement • Storyboards break down our animations into scenes. • We need to also break down each overall task into it’s individual steps • This is called stepwise refinement

  9. Our Experience with Alice • Up until now, we’ve been writing all of our code in the World.my first method block. • Our code just seemed to grow and grow as we added new instructions. • To continue on this path would mean that by project time, our programs would be hundreds of line long. • Instead, we need to learn to break our code down into methods which we will then call.

  10. Revised Storyboard for First Encounter Do in order surprise – spiderRobot and alienOnWheels surprise each other investigate – spiderRobot gets a closer look at alienOnWheels react – alienOnWheels hides and spiderRobot sends a message

  11. Now we need to break down each major task of our storyboard surprise Do in order alien moves up alien says “Slithy toves?” robot’s head turns around

  12. Now we need to break down each major task of our storyboard investigate Do in order robot turns to look at alien Do together robot moves forward (toward the alien) robot’s legs walk

  13. Now we need to break down each major task of our storyboard react Do in order alien moves down robot turns to look at the camera robot’s head turns red (to signal danger) robot says “Houston, we have a problem!”

  14. World-level methods • This is an example of a world-level method. • More than one object is manipulated in the method. • Turn to page 77 in your Alice text and let’s design and call these three methods, surprise, investigate, and react

  15. World-Level Methods

More Related