Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1 - Getting to know Greenfoot Acknowledgement: Michael Kolling & Bruce Chittenden.

Similar presentations


Presentation on theme: "Chapter 1 - Getting to know Greenfoot Acknowledgement: Michael Kolling & Bruce Chittenden."— Presentation transcript:

1 Chapter 1 - Getting to know Greenfoot Acknowledgement: Michael Kolling & Bruce Chittenden

2 Greenfoot Resources Web site – http://www.greenfoot.org http://www.greenfoot.org Scenarios – http://www.greenfoot.org/scenarios /index.html http://www.greenfoot.org/scenarios /index.html Tutorial – http://www.greenfoot.org/doc/tutori al.html http://www.greenfoot.org/doc/tutori al.html Book: Introduction to Programming with Greenfoot by Michael Kölling

3 Desktop Icon

4 1.1 Getting Started World Class Diagram Execution Controls

5 World A Finite space where our program runs. Space where we can introduce some actors Allow actors to Interact

6 Class Diagram Shows Classes involved in the scenario Classes define general characteristics or behavior of a group Characteristics that are easily differentiable Is-A- Relationship Subclass relationship Diagram contains Boxes called Class boxes WombatWorld is a subclass of World Wombat is a subclass for Actor Leaf is a subclass of Actor Leaf is not a subclass of Wombat Actor is the super class of Leaf and Wombat

7 Class Hierarchy TeacherStudent Humans Mammals food() drink() think() react() enroll () study() submit_Assignments() teach () evaluate() prepare_Assignments()

8 1.2 Objects and Classes Right Click on Wombat Click New Wombat() Drag to World

9 Multiple Objects We can create multiple instances of same class

10 Exercise 1.1

11 1.3 Interacting with Objects Wombat has certain function of its own And Certain function inherited from Actor class

12 Interacting with Objects Invoke the Move method Right Click on the Wombat

13 1.4 Return Types

14 Exercise 1.3

15

16 Exercise 1.4

17 1.5 Parameters

18 Exercise 1.5

19

20 1 3 2 0

21 Parameter > 3 Does Nothing

22 Exercise 1.5 Non-Integer Returns Error

23 1.6 Greenfoot Execution

24 Exercise 1.6

25 Wombat Moves toward the Leaves

26 Exercise 1.6 Wombat Moves to Leaves

27 Example 1.7 Wombat Eats Leaf

28 Exercise 1.8

29 The >Act Execution Control Affects All the Wombats

30 Exercise 1.9 Wombat Runs Around the Edge of the World

31 Exercise 1.9 Act Method – If we’re sitting on a leaf, eat the leaf – Otherwise, if we can move forward, move forward – Otherwise, turn left

32 1.7 A Second Example

33 1.8 Understanding the Class Diagram World Class is always there in Greenfoot scenarios, it is built-in. Space represents a specific world for this scenario Arrows show relationships Explosion and Mover are subclasses of Actor Bullet, Rocket, and Asteroid are subclasses of Mover. Vector is a helper class

34 1.9 Playing with Asteroids Start Playing by Creating Some Actor Objects (Objects of the Subclass of Actor). Create Objects for Rocket, Bullet, Asteroid, and Explosion

35 Exercise 1.10 Right Click on the Object

36 Exercise 1.10 Click on setGunReloadTime and Type 5

37 Exercise 1.11 Right Click on the Object and Select Inspect

38 Exercise 1.11 Right Click on the Object and Select Inspect

39 Exercise 1.12 Right Click on the Object and Select getSpeed ( )

40 Exercise 1.12

41 Exercise 1.13

42 Exercise 1.14 Right Click on the Object and Select setSize(int Size) and Set the Size to 256

43 1.10 Source Code Right Click on the Class and Select Open editor

44 Source Code for Rocket

45 Exercise 1.15 Change gunReloadTime from 20 to 5

46 Exercise 1.15

47 Class Changed Class Compiled

48 1.11 Summary In this chapter, we have seen what Greenfoot scenarios can look like and how to interact with them. We have seen how to create objects and how to communicate with these objects by invoking their methods. Some methods are commands to objects, while other methods return information about the object. Parameters are used to provide additional information to methods, while return values pass information back to the caller.

49 Concept Summary


Download ppt "Chapter 1 - Getting to know Greenfoot Acknowledgement: Michael Kolling & Bruce Chittenden."

Similar presentations


Ads by Google