39
Greenfoot f Introductory Programming Teaching with Greenfoot 3 Michael Kölling supported by

Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

Greenfoot f

Introductory Programming Teaching with Greenfoot 3

Michael Kölling

supported by

Page 2: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

Wombats.

Page 3: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

© 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

Page 4: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

Asteroids, Ants and other creatures.

Page 5: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

An example

• little-crab-start.zip - Scenario

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

Crabs:

Page 6: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Greenfoot classes

Actor GreenfootImage

Greenfoot

World

MouseInfo

GreenfootSound

Page 7: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Actors

• image

• location (in the world)

• rotation

'Actors' have predefined state:

x

y

α

Page 8: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Actor methods

• act()

• getX(), getY()

• setLocation(int x, int y)

• ...

inherited from class 'Actor'

Actor

Crab

Page 9: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

The act method

code goes here

Actor

Crab

Page 10: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

The Stride editor

Page 11: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Movement

move(4)

Page 12: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Make your own creature

Page 13: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Exercises

move(4)

Page 14: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Method calls

or

method-name ()

method-name (parameter)

Page 15: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

© 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 ()

Page 16: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Actor

boolean isAtEdge()

Actor

Crab

Page 17: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Method calls - examples

boolean atEdge()

Specification:

You write:

true or false atEdge ()

Page 18: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

If statementstrue / false

Page 19: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

If statements

isAtEdge()

Page 20: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Code completionCtrl-Space

Page 21: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Exercise

• movement, edge detection, turning

Page 22: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Turn at edge

Page 23: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Some meta remarks...

Page 24: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Other options

Move only when there is some noise!

Page 25: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Modification and ownership

• Let students take control

Page 26: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

?

Page 27: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Keyboard input

Page 28: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

© 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)

Page 29: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Eating worms

Page 30: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Some meta remarks...

Page 31: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Reinforcement

• Students need practice and reinforcement

• Apply same concepts in different context

Page 32: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Sound

• The crab project includes a sound file:

• "slurp.wav" (crab eats worm)

Page 33: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

Recording sound

Page 34: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

And now again in Java…

Page 35: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Greenfoot Gallery

• Share!

Page 36: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Page 37: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Workshop slides

• www.greenfoot.org/static/workshop

Page 38: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

Joy of Code videos

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

Page 39: Greenfoot · © M. Kölling, University of Kent, 2016 An example • little-crab-start.zip - Scenario • Download from Crabs:Download · Book · Latest Activity · Scenarios · Documentation

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

• Meet!

greenroom.greenfoot.org

Greenroom