programming with alice - prince edward island · •alice does allow spaces in its naming...

25
Programming with Alice Part 2

Upload: lequynh

Post on 18-Dec-2018

222 views

Category:

Documents


1 download

TRANSCRIPT

Programming with AlicePart 2

Methods

• A set of instructions that executes when you play and Alice world

• Drag tiles into the “Methods Editor”

• Dot Notationworld.my first

Object Name of method

Primitive Methods

• Alice provided numerous methods that have already been created.

• ALL OBJECTS have a common set of built-in methods for performing basic actions. These are called PRIMITIVE METHODS

Method Calls

• Calling the Method – a term programmers use to exectute a method.

• When you call the MOVE method you must provide two necessay pieces of information:

The directionThe amount

Arguments

• The two pieces of information provided to a Method (Move) are called ARGUMENTS.

• When you provide this information, it is called PASSING THE ARGUMENT.

• To change an argument, click on the instruction tile.

“More” label

• The “more” label located at the end of assigning arguments to methods, allows you to pick more options for the argument.

• Know how to DELETE and COPY Methods

Custom Methods

• Certain Objects have custom methods

• A custom method is a method that only objects of a specific class have

• Example: Frog Class» foottap

» ribbit

» headnod

Naming Conventions

• The standard rules that programmers follow when they create names for object and methods

Meaningful Names

• You should change the names of the objects you add to make them meaningful

• Also….with Methods

– ie… world.my first method does not have a very descriptive name

– better name in the Hare App. from Tutorial 2-2 might be :

• hareAnimation

Spaces

• Alice does allow spaces in its naming conventions (rules)

• BUT…most programming languages prohibit the use of spaces.

• From this point on, you should NOT uses spaces in the names of objects or methods.

camelCase Names• Names should reflect the purpose of the

object or method

• Use meaningful words

– not horse1 but black beauty

• Rules:

– begin in lower case

– the first characted of the second and subsequent words in upper case

• blackBearty or petCockerSpaniel

PascalCase for Class Names

• Most traditional programming languages use the practice of beginning the class name with uppercase

• Examples:

– IceSkater

– CheshireCat

Summary of Naming Conventions

• objects and methods have meaningful names

• use only letter and numbers when naming. NO SYMBOLS

• do not use spaces

• use camelCase convention for naming objects and methods

• use PascalCase convention for class names

Renaming Objects & Methods

• Objects:

– Rt. Click on the object’s tile in the Object Tree

• Methods (renaming the my first method Method)

– 1st select the world object

– Then select the methods tab

– Rt. Click on the tile

Designing a Program

• Programmers use a repetitive process known as the Program Development Cycle to plan, develop, and test their programs.

– Design the program

– Write the methods

– Test the Methods

– Debug the Methods

• Repeat the cycle until no errors are found in the program

The Problem

• A hare shows off his acrobatic skills by jumping up and spinning all the way around in mid air. The hare comes back to the ground and exclaims “That was fun!”

Pseudocode

• An English algorithm

– hare moves up in the air

– hare turns completely around

– hare moves down to the ground

– hare says “That was fun!”

Flowcharts

Writing the Methods

• Actual conversion of the statements to programming instructions

• Drag tiles into the methods editor

Testing and Debugging

• Play the world

• A logical error is known as a “Bug”

• Fix the “bugs” is debugging

Find the “Bug”

Tasks

• Complete Tutorials 2-3 and 2-4

• Save accordingly

Scene Setup

• You can use Primitive Methods to set up a scene.

– Move objects to face each other

– Move body parts to desired positions

– Move objects to center of world

– Position object a specific distance apart

– Move the camera to an object

Executing Instructions Simultaneously

• DO TOGETHER Structure can be used to execute a set of instructions at the same time

• DO IN ORDER Structure

Exporting your code for printing

• You can export the code that is part of your world to an HTML file that can be opened in your browser and printed.