Presentation is loading. Please wait.

Presentation is loading. Please wait.

Don Slater Wanda Dann

Similar presentations


Presentation on theme: "Don Slater Wanda Dann"— Presentation transcript:

1 Don Slater Wanda Dann

2 How does the penguin “push” the ball? Back to the algorithm Do in order penguin swagger penguin push the ball penguin push Do in order penguin move forward to bump into the ball ball move forward to bump into the pin

3  Actually, the penguin could be pushing any target object, so we named the procedure pushObject A second procedure

4 Implement penguin pushObject Do in order this (penguin) move forward to bump into the ball ball move forward to bump into the pin

5 Only reference to penguin available in the instance menu We say the ball is out-of-scope (unavailable to be used in the penguin class) Problem: How to move the target (ball) We are working in the Penguin class

6  A parameter is used to send information to a procedure when the procedure is called (invoked)  Most built-in Alice statements use parameters ◦ move: direction, distance ◦ turn: direction, angleInRotations

7 pushObject Parameter: target Do in order penguin move forward (to bump into target) target move forward Algorithm with a parameter

8 Click add parameter A parameter has a type (what kind of parameter is it?) and a name (a placeholder name)

9  Available types are listed in a drop-down menu ◦ Specifies the kind of information the parameter will represent Select Type numeric boolean string of text Gallery Classes

10 Inheritance Hierarchy  The inheritance hierarchy shows the parent classes of our objects  We see that Penguin is a Flyer  BowlingPin is a Prop  We could use these any of these classes (parents or children) as types for our parameter

11 Other types But the bowling ball is from the SSphere class, which has to be the type selected

12 The parameter type Provide a name for the parameter Parameter name

13  A parameter declaration consists of  Ssphere target  We say “target is of type SSphere” Parameter declaration

14  Select parameter from the instance menu The parameter is now in scope

15 Create instruction for the parameter

16 pushObject procedural method

17 Scene class: myFirstMethod  Drag the pushObject tile into the editor  Select an argument (actual parameter) that will be sent to the parameter (formal parameter). We see that we can only choose ball, as it is the only instance of the Ssphere class we have in our program.


Download ppt "Don Slater Wanda Dann"

Similar presentations


Ads by Google