Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip -...

Preview:

Citation preview

Greenfoot f

Introductory Programming Teaching with Greenfoot 3

Michael Kölling

supported by

Wombats.

© M. Kölling, University of Kent, 2016

Object Orientation

• Early understanding of key concepts is important

• class

• object

• state

• behaviour

• Not easy without tool support

• Most important: motivation

Asteroids, Ants and other creatures.

© M. Kölling, University of Kent, 2016

An example

• little-crab-start.zip - Scenario

• Download from www.greenfoot.org/static/workshop

Crabs:

© M. Kölling, University of Kent, 2016

Greenfoot classes

Actor GreenfootImage

Greenfoot

World

MouseInfo

GreenfootSound

© M. Kölling, University of Kent, 2016

Actors

• image

• location (in the world)

• rotation

'Actors' have predefined state:

x

y

α

© M. Kölling, University of Kent, 2016

Actor methods

• act()

• getX(), getY()

• setLocation(int x, int y)

• ...

inherited from class 'Actor'

Actor

Crab

© M. Kölling, University of Kent, 2016

The act method

code goes here

Actor

Crab

© M. Kölling, University of Kent, 2016

The Stride editor

© M. Kölling, University of Kent, 2016

Movement

move(4)

© M. Kölling, University of Kent, 2016

Make your own creature

© M. Kölling, University of Kent, 2016

Exercises

move(4)

© M. Kölling, University of Kent, 2016

Method calls

or

method-name ()

method-name (parameter)

© M. Kölling, University of Kent, 2016

Method calls - examples

void move(int distance)

void turn(int angle)

void stop();

Specification: You write:

move (5)

turn (45)

stop ()

© M. Kölling, University of Kent, 2016

Actor

boolean isAtEdge()

Actor

Crab

© M. Kölling, University of Kent, 2016

Method calls - examples

boolean atEdge()

Specification:

You write:

true or false atEdge ()

© M. Kölling, University of Kent, 2016

If statementstrue / false

© M. Kölling, University of Kent, 2016

If statements

isAtEdge()

© M. Kölling, University of Kent, 2016

Code completionCtrl-Space

© M. Kölling, University of Kent, 2016

Exercise

• movement, edge detection, turning

© M. Kölling, University of Kent, 2016

Turn at edge

© M. Kölling, University of Kent, 2016

Some meta remarks...

© M. Kölling, University of Kent, 2016

Other options

Move only when there is some noise!

© M. Kölling, University of Kent, 2016

Modification and ownership

• Let students take control

© M. Kölling, University of Kent, 2016

?

© M. Kölling, University of Kent, 2016

Keyboard input

© M. Kölling, University of Kent, 2016

Worms...

• New subclass of Actor: Worm

• No behaviour needed

• Crabs eat worms... (collision detection)

See (from class Actor):

isTouching(Class clss) removeTouching(Class clss)

© M. Kölling, University of Kent, 2016

Eating worms

© M. Kölling, University of Kent, 2016

Some meta remarks...

© M. Kölling, University of Kent, 2016

Reinforcement

• Students need practice and reinforcement

• Apply same concepts in different context

© M. Kölling, University of Kent, 2016

Sound

• The crab project includes a sound file:

• "slurp.wav" (crab eats worm)

Recording sound

And now again in Java…

© M. Kölling, University of Kent, 2016

Greenfoot Gallery

• Share!

© M. Kölling, University of Kent, 2007

© M. Kölling, University of Kent, 2007

Workshop slides

• www.greenfoot.org/static/workshop

© M. Kölling, University of Kent, 2007

Joy of Code videos

https://www.youtube.com/user/18km

© M. Kölling, University of Kent, 2016

• Meet!

greenroom.greenfoot.org

Greenroom

Recommended