[email protected] of kent a practical introduction to greenfoot david barnes lecturer...

13
[email protected] c.uk University of Kent A practical introduction to Greenfoot www.greenfoot.org David Barnes Lecturer in Computer Science University of Kent

Upload: charity-blankenship

Post on 16-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: D.j.barnes@kent.ac.ukUniversity of Kent A practical introduction to Greenfoot  David Barnes Lecturer in Computer Science University of

[email protected]

University of Kent

A practical introduction to Greenfoot

www.greenfoot.org

David Barnes

Lecturer in Computer Science

University of Kent

Page 2: D.j.barnes@kent.ac.ukUniversity of Kent A practical introduction to Greenfoot  David Barnes Lecturer in Computer Science University of

[email protected]

University of Kent

Overview

• Introducing object-orientation

• BlueJ

• The Greenfoot environment

• Greenfoot scenarios

• Practical application

Page 3: D.j.barnes@kent.ac.ukUniversity of Kent A practical introduction to Greenfoot  David Barnes Lecturer in Computer Science University of

[email protected]

University of Kent

Introducing object-orientation

• Building early understanding of key concepts is crucial:– Class– Object– State– Behaviour

• Hard to do without tool support – e.g. visualisation.

Page 4: D.j.barnes@kent.ac.ukUniversity of Kent A practical introduction to Greenfoot  David Barnes Lecturer in Computer Science University of

[email protected]

University of Kent

BlueJ

• IDE designed specifically for the teaching of introductory object-orientation.

• Developed by Michael Kölling.• Good visualisation of key concepts.• Interactivity brings these concepts to

life.• Typically used at u/g level.

Page 5: D.j.barnes@kent.ac.ukUniversity of Kent A practical introduction to Greenfoot  David Barnes Lecturer in Computer Science University of

[email protected]

University of Kent

Greenfoot

• An environment and framework that supports World+Actor scenarios.

• Developed by Michael, and Poul Henriksen.

• Provides visually engaging and concrete experiences for pre-University students.

• Built on top of BlueJ.

Page 6: D.j.barnes@kent.ac.ukUniversity of Kent A practical introduction to Greenfoot  David Barnes Lecturer in Computer Science University of

[email protected]

University of Kent

A few Greenfoot scenarios

• Wombats

• Ants

• Lifts

• Lunar lander

Page 7: D.j.barnes@kent.ac.ukUniversity of Kent A practical introduction to Greenfoot  David Barnes Lecturer in Computer Science University of

[email protected]

University of Kent

Practical application

• The framework API• The crab world, by Michael Kölling.

– Basic movement.– Actor interaction.– Simulation controls.– Key strokes.– Sound.– Image manipulation.

Page 8: D.j.barnes@kent.ac.ukUniversity of Kent A practical introduction to Greenfoot  David Barnes Lecturer in Computer Science University of

[email protected]

University of Kent

little-crab

• You will use the little-crab scenario in the crabworld folder. (Try to ignore the 2, 3, 4 and 5 folders which are cribs!)

• We start by using methods inherited from Animal to add movement, edge-detection and turning.

Page 9: D.j.barnes@kent.ac.ukUniversity of Kent A practical introduction to Greenfoot  David Barnes Lecturer in Computer Science University of

[email protected]

University of Kent

Worms

• Add a new subclass of Animal.

• No behaviour required.

• Add random turning to the Crab:– getRandomNumber in Greenfoot

• Add Worm detection to the Crab:– getOneObjectAtOffset in Actor– removeObject in World

Page 10: D.j.barnes@kent.ac.ukUniversity of Kent A practical introduction to Greenfoot  David Barnes Lecturer in Computer Science University of

[email protected]

University of Kent

Lobster

• Add Lobster as a subclass of Animal.– Copy Crab’s functionality.– Make it hunt crabs rather than worms.

• Stop the simulation when a crab is eaten:– stopSimulation in Greenfoot

• Variation: stop when the last crab is eaten.

Page 11: D.j.barnes@kent.ac.ukUniversity of Kent A practical introduction to Greenfoot  David Barnes Lecturer in Computer Science University of

[email protected]

University of Kent

Adding sound

• Play different sounds when crabs and worms are eaten (see the sounds folder):– playSound in Greenfoot

• Setup an initial population:– Use the constructor of CrabWorld.

• Change images as the crab moves:– setImage in Actor.

Page 12: D.j.barnes@kent.ac.ukUniversity of Kent A practical introduction to Greenfoot  David Barnes Lecturer in Computer Science University of

[email protected]

University of Kent

Other capabilities

• Detecting key presses:– isKeyDown in Greenfoot.

• Actor inspection.• Interactive method invocation.• Interactive movement:

– setLocation in Actor.

• Linking actor interaction (plane scenario).

Page 13: D.j.barnes@kent.ac.ukUniversity of Kent A practical introduction to Greenfoot  David Barnes Lecturer in Computer Science University of

[email protected]

University of Kent

Review

• Greenfoot provides a rich environment and framework for scenario creation.

• Teachers can build scenarios that are attractive and interesting.

• An intermediate implementation layer provides an appropriate abstraction for target groups of students.