0
Introduction To
                            Greenfoot
                               Part-3


kakihijau.googlepages.com
Disclaimer
 This document is intended to give a beginner an introductory
  material for the Greenfoot system. Greenfoot i...
Purpose
 This is the second part of the document „Introduction to
  Greenfoot“ and focuses on two topics: modification an...
Outline
 Changing the Behaviour
 Changing Representations
 Creating New Classes




                                   ...
Changing the Behaviour (1)
 We want to change the behaviour of Wombat objects :
  instead of always turning left, they sh...
Changing the Behaviour (2)


                 if you find leaves, eat !

                 if you don‘t find leaves, but yo...
Changing the Behaviour (3)




                        Introduction to Greenfoot              7
                  Eueung M...
Changing Representations (1)
 Visual representation (image) of an object can be
  changed in two different ways
   – Chan...
Changing Representations (2)




                         Introduction to Greenfoot              9
                   Eueu...
Changing Representations (3)




                         Introduction to Greenfoot              10
                   Eue...
Changing Representations (4)




  the result of populate()       Additionally change the class image
after changin the cl...
Changing Representations (5)




               to set the image of an object
                     programmatically




  ...
Changing Representations (6)




                         Introduction to Greenfoot              13
                   Eue...
Creating New Classes (1)
 We could not only modify the                     class image for
                              ...
Creating New Classes (2)




                       Introduction to Greenfoot              15
                 Eueung Muly...
Creating New Classes (3)

 To stop wombats
  from walking
  through rocks ...


 check all Rock objects
 in front of you;...
Creating New Classes (4)




                       Introduction to Greenfoot              17
                 Eueung Muly...
Upcoming SlideShare
Loading in...5
×

Greenfoot Introduction (3)

2,391

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,391
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
99
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Greenfoot Introduction (3)"

  1. 1. Introduction To Greenfoot Part-3 kakihijau.googlepages.com
  2. 2. Disclaimer  This document is intended to give a beginner an introductory material for the Greenfoot system. Greenfoot is a software framework made by Poul Henriksen and Michael Koelling at University of Kent / Deakin University. More information can be found at http://www.greenfoot.org  This document is available „AS IS“ free of charge for personal use and non-commercial redistribution. It may not be sold for profit or included in other packages which are sold for profit without written authorisation. This document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; your use of the document is at your sole risk. Reusing and modifying (part of) this document is allowed, as long as you state explicitly that your work is based on the original document produced by the copyright holder: Eueung Mulyana. The author can be contacted via eueung-[at]-yahoo.com (http://kakihijau.googlepages.com). Introduction to Greenfoot 2 Eueung Mulyana | kakihijau.googlepages.com
  3. 3. Purpose  This is the second part of the document „Introduction to Greenfoot“ and focuses on two topics: modification and programming of the wombats scenario  Part of the content of these slides is based on the Greenfoot Tutorial made by Michael Koelling, publicly accesible at the Greenfoot website, http://www.greenfoot.org Introduction to Greenfoot 3 Eueung Mulyana | kakihijau.googlepages.com
  4. 4. Outline  Changing the Behaviour  Changing Representations  Creating New Classes Introduction to Greenfoot 4 Eueung Mulyana | kakihijau.googlepages.com
  5. 5. Changing the Behaviour (1)  We want to change the behaviour of Wombat objects : instead of always turning left, they shall be able to turn to other directions in a random way  We will add an additional method, called turnRandom()  Open the source code of the Wombat class, add the following codes Generate a random number between 0 and 3 call turnLeft() turns times Introduction to Greenfoot 5 Eueung Mulyana | kakihijau.googlepages.com
  6. 6. Changing the Behaviour (2) if you find leaves, eat ! if you don‘t find leaves, but you can move forward, then move! if you don‘t find leaves and you also cannot move, then turn to a random direction! Introduction to Greenfoot 6 Eueung Mulyana | kakihijau.googlepages.com
  7. 7. Changing the Behaviour (3) Introduction to Greenfoot 7 Eueung Mulyana | kakihijau.googlepages.com
  8. 8. Changing Representations (1)  Visual representation (image) of an object can be changed in two different ways – Changing the „class image“; in this way, all objects of the same class shall look the same (to the assigned class image) – Changing the image programmatically; in this way, objects of the same class might look different, depending on the implementation  These two ways might be combined! Introduction to Greenfoot 8 Eueung Mulyana | kakihijau.googlepages.com
  9. 9. Changing Representations (2) Introduction to Greenfoot 9 Eueung Mulyana | kakihijau.googlepages.com
  10. 10. Changing Representations (3) Introduction to Greenfoot 10 Eueung Mulyana | kakihijau.googlepages.com
  11. 11. Changing Representations (4) the result of populate() Additionally change the class image after changin the class image then add 2 objects after modification Introduction to Greenfoot 11 Eueung Mulyana | kakihijau.googlepages.com
  12. 12. Changing Representations (5) to set the image of an object programmatically Introduction to Greenfoot 12 Eueung Mulyana | kakihijau.googlepages.com
  13. 13. Changing Representations (6) Introduction to Greenfoot 13 Eueung Mulyana | kakihijau.googlepages.com
  14. 14. Creating New Classes (1)  We could not only modify the class image for the Rock class behaviour of objects, but also add a completely new type of objects i.e. create new classes  Right-click the class Actor and choose item „New subclass ...“, enter the class name and select a class image in the dialog; Greenfoot will automatically generate your class !  In this case we add a new class, called Rock. The image for this images available in the wombats class is already available in the scenario folder wombats scenario folder Introduction to Greenfoot 14 Eueung Mulyana | kakihijau.googlepages.com
  15. 15. Creating New Classes (2) Introduction to Greenfoot 15 Eueung Mulyana | kakihijau.googlepages.com
  16. 16. Creating New Classes (3)  To stop wombats from walking through rocks ... check all Rock objects in front of you; if there is no Rock object, return true (i.e. okay it‘s clear!) , otherwise return false (i.e. you cannot move!) Introduction to Greenfoot 16 Eueung Mulyana | kakihijau.googlepages.com
  17. 17. Creating New Classes (4) Introduction to Greenfoot 17 Eueung Mulyana | kakihijau.googlepages.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×