1 / 43

Chapter 1 - Getting to know Greenfoot

Chapter 1 - Getting to know Greenfoot. Bruce Chittenden. Desktop Icon. 1.1 Getting Started. World. Class Diagram. Execution Controls. 1.2 Objects and Classes. Right Click on Wombat. Drag to World. Click New Wombat(). Exercise 1.1. 1.3 Interacting with Objects.

sheri
Download Presentation

Chapter 1 - Getting to know Greenfoot

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 1 - Getting to know Greenfoot Bruce Chittenden

  2. Desktop Icon

  3. 1.1 Getting Started World Class Diagram Execution Controls

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

  5. Exercise 1.1

  6. 1.3 Interacting with Objects Right Click on the Wombat Invoke the Move method

  7. 1.4 Return Types

  8. Exercise 1.3

  9. Exercise 1.3

  10. Exercise 1.4

  11. 1.5 Parameters

  12. Exercise 1.5

  13. Exercise 1.5

  14. Exercise 1.5 2 1 0 3

  15. Exercise 1.5 Parameter > 3 Does Nothing

  16. Exercise 1.5 Non-Integer Returns Error

  17. 1.6 Greenfoot Execution

  18. Exercise 1.6

  19. Exercise 1.6 Wombat Moves toward the Leaves

  20. Exercise 1.6 Wombat Moves to Leaves

  21. Example 1.7 Wombat Eats Leaf

  22. Exercise 1.8

  23. Exercise 1.8 The >Act Execution Control Affects All the Wombats

  24. Exercise 1.9 Wombat Runs Around the Edge of the World

  25. 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

  26. 1.7 A Second Example

  27. 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

  28. 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

  29. Exercise 1.10 Right Click on the Object

  30. Exercise 1.10 Click on setGunReloadTime and Type 5

  31. Exercise 1.11 Right Click on the Object and Select Inspect

  32. Exercise 1.11 Right Click on the Object and Select Inspect

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

  34. Exercise 1.12

  35. Exercise 1.13

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

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

  38. Source Code for Rocket

  39. Exercise 1.15 Change gunReloadTime from 20 to 5

  40. Exercise 1.15

  41. Exercise 1.15 Class Changed Class Compiled

  42. 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.

  43. Concept Summary

More Related