SlideShare uma empresa Scribd logo
1 de 22
Introduction To
                            Greenfoot
                               Part-2


kakihijau.googlepages.com
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
Purpose
 This is the second part of the document „Introduction to
  Greenfoot“ and focuses on understanding 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
Outline
   Class Display Revisited
   Class Editor
   The Leaf Class
   The Wombat Class
   The WombatWorld Class




                                       Introduction to Greenfoot              4
                                 Eueung Mulyana | kakihijau.googlepages.com
Class Display Revisited




 Class display contains all classes which are used in a scenario
 Class World and Actor are abstract superclasses, part of the
  Greenfoot system
 Scenario wombats has 2 actor classes (Wombat, Leaf)

                                                      Introduction to Greenfoot              5
                                                Eueung Mulyana | kakihijau.googlepages.com
Class Editor (1)
 We can modify objects behaviour by
  editing the source code of the
  corresponding class

 To display the source code editor:
   – Double-click the class
   – Right-click the class, choose the item
     „Open editor“




                                                    Introduction to Greenfoot              6
                                              Eueung Mulyana | kakihijau.googlepages.com
Class Editor (2)




                   Introduction to Greenfoot              7
             Eueung Mulyana | kakihijau.googlepages.com
The Leaf Class
 The simplest class compared to the Wombat and
  WombatWorld class
 Leaf objects do nothing!
 As you can see in the previous slide, the Leaf class has no
  statement and consists of an empty constructor




                                              Introduction to Greenfoot              8
                                        Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (1)
import necessary packages




class header;
Wombat is a subclass
from Actor




data (constants and
variables)




class constructor and
methods


                                   Introduction to Greenfoot              9
                             Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (2)
 4 constants : EAST, WEST,
  NORTH, SOUTH
 2 variables : direction,
  leavesEaten
 1 constructor : Wombat()
 8 methods :
  – getLeavesEaten(), foundLeaf(),
    eatLeaf()
  – setDirection(), turnLeft()
  – canMove(), move()
  – act()



                                           Introduction to Greenfoot              10
                                     Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (3)

                           constructor  initialising
                           direction and leavesEaten




is there any Leaf object
in my position?            this method is inherited from
                           the superclass Actor




remove that Leaf object
update the variable
leavesEaten



                                  Introduction to Greenfoot              11
                            Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (4)




                    Introduction to Greenfoot              12
              Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (5)



              this method is inherited from
              the superclass Actor




                     Introduction to Greenfoot              13
               Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (6)


         change direction 90 degrees
         to the left




                             Introduction to Greenfoot              14
                       Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (7)

                                 these methods are
                                 inherited from Actor
new coordinate
if the object moves
forward;
depends on
its direction




                              checks if the object
                              reaches the edges of the world




                                   Introduction to Greenfoot              15
                             Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (8)




                    Introduction to Greenfoot              16
              Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (9)
                            if object reaches one of
                            the borders, do nothing!




the object moves                            setLocation() is
forward;                                    inherited from Actor
depends on
its direction




                                     Introduction to Greenfoot              17
                               Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (10)



               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
               the left!




                     Introduction to Greenfoot              18
               Eueung Mulyana | kakihijau.googlepages.com
The WombatWorld Class (1)
 1 constructor : WombatWorld()
 2 methods :
   – populate()
   – randomLeaves()




                                        Introduction to Greenfoot              19
                                  Eueung Mulyana | kakihijau.googlepages.com
The WombatWorld Class (2)


                                 calls the World constructor




           sets the background.
           the method is inherited
           from the superclass World
                                                      cell.jpg




                                Introduction to Greenfoot              20
                          Eueung Mulyana | kakihijau.googlepages.com
The WombatWorld Class (3)




                       Introduction to Greenfoot              21
                 Eueung Mulyana | kakihijau.googlepages.com
The WombatWorld Class (4)


               Create a Leaf object at a random
               position (x,y); repeat howmany
               times




                          Introduction to Greenfoot              22
                    Eueung Mulyana | kakihijau.googlepages.com

Mais conteúdo relacionado

Mais de Eueung Mulyana

ONOS SDN Controller - Clustering Tests & Experiments
ONOS SDN Controller - Clustering Tests & Experiments ONOS SDN Controller - Clustering Tests & Experiments
ONOS SDN Controller - Clustering Tests & Experiments Eueung Mulyana
 
Open stack pike-devstack-tutorial
Open stack pike-devstack-tutorialOpen stack pike-devstack-tutorial
Open stack pike-devstack-tutorialEueung Mulyana
 
ONOS SDN Controller - Introduction
ONOS SDN Controller - IntroductionONOS SDN Controller - Introduction
ONOS SDN Controller - IntroductionEueung Mulyana
 
OpenDaylight SDN Controller - Introduction
OpenDaylight SDN Controller - IntroductionOpenDaylight SDN Controller - Introduction
OpenDaylight SDN Controller - IntroductionEueung Mulyana
 
Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming BasicsEueung Mulyana
 
Cloud Computing: Overview and Examples
Cloud Computing: Overview and ExamplesCloud Computing: Overview and Examples
Cloud Computing: Overview and ExamplesEueung Mulyana
 
selected input/output - sensors and actuators
selected input/output - sensors and actuatorsselected input/output - sensors and actuators
selected input/output - sensors and actuatorsEueung Mulyana
 
Connected Things, IoT and 5G
Connected Things, IoT and 5GConnected Things, IoT and 5G
Connected Things, IoT and 5GEueung Mulyana
 
Connectivity for Local Sensors and Actuators Using nRF24L01+
Connectivity for Local Sensors and Actuators Using nRF24L01+Connectivity for Local Sensors and Actuators Using nRF24L01+
Connectivity for Local Sensors and Actuators Using nRF24L01+Eueung Mulyana
 
NodeMCU with Blynk and Firebase
NodeMCU with Blynk and FirebaseNodeMCU with Blynk and Firebase
NodeMCU with Blynk and FirebaseEueung Mulyana
 
Trends and Enablers - Connected Services and Cloud Computing
Trends and Enablers  - Connected Services and Cloud ComputingTrends and Enablers  - Connected Services and Cloud Computing
Trends and Enablers - Connected Services and Cloud ComputingEueung Mulyana
 
Digital Ecosystems - Connected Services and Cloud Computing
Digital Ecosystems - Connected Services and Cloud ComputingDigital Ecosystems - Connected Services and Cloud Computing
Digital Ecosystems - Connected Services and Cloud ComputingEueung Mulyana
 
Services Convergence - Connected Services and Cloud Computing
Services Convergence - Connected Services and Cloud ComputingServices Convergence - Connected Services and Cloud Computing
Services Convergence - Connected Services and Cloud ComputingEueung Mulyana
 
Models and Architecture - Connected Services and Cloud Computing
Models and Architecture - Connected Services and Cloud ComputingModels and Architecture - Connected Services and Cloud Computing
Models and Architecture - Connected Services and Cloud ComputingEueung Mulyana
 
Introduction, Examples - Firebase
Introduction, Examples - Firebase Introduction, Examples - Firebase
Introduction, Examples - Firebase Eueung Mulyana
 
Vue js and Vue Material
Vue js and Vue MaterialVue js and Vue Material
Vue js and Vue MaterialEueung Mulyana
 
React Example + Bootstrap
React Example + BootstrapReact Example + Bootstrap
React Example + BootstrapEueung Mulyana
 
introduction to material design lite MDL
introduction to material design lite MDLintroduction to material design lite MDL
introduction to material design lite MDLEueung Mulyana
 

Mais de Eueung Mulyana (20)

ONOS SDN Controller - Clustering Tests & Experiments
ONOS SDN Controller - Clustering Tests & Experiments ONOS SDN Controller - Clustering Tests & Experiments
ONOS SDN Controller - Clustering Tests & Experiments
 
Open stack pike-devstack-tutorial
Open stack pike-devstack-tutorialOpen stack pike-devstack-tutorial
Open stack pike-devstack-tutorial
 
Basic onos-tutorial
Basic onos-tutorialBasic onos-tutorial
Basic onos-tutorial
 
ONOS SDN Controller - Introduction
ONOS SDN Controller - IntroductionONOS SDN Controller - Introduction
ONOS SDN Controller - Introduction
 
OpenDaylight SDN Controller - Introduction
OpenDaylight SDN Controller - IntroductionOpenDaylight SDN Controller - Introduction
OpenDaylight SDN Controller - Introduction
 
Mininet Basics
Mininet BasicsMininet Basics
Mininet Basics
 
Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming Basics
 
Cloud Computing: Overview and Examples
Cloud Computing: Overview and ExamplesCloud Computing: Overview and Examples
Cloud Computing: Overview and Examples
 
selected input/output - sensors and actuators
selected input/output - sensors and actuatorsselected input/output - sensors and actuators
selected input/output - sensors and actuators
 
Connected Things, IoT and 5G
Connected Things, IoT and 5GConnected Things, IoT and 5G
Connected Things, IoT and 5G
 
Connectivity for Local Sensors and Actuators Using nRF24L01+
Connectivity for Local Sensors and Actuators Using nRF24L01+Connectivity for Local Sensors and Actuators Using nRF24L01+
Connectivity for Local Sensors and Actuators Using nRF24L01+
 
NodeMCU with Blynk and Firebase
NodeMCU with Blynk and FirebaseNodeMCU with Blynk and Firebase
NodeMCU with Blynk and Firebase
 
Trends and Enablers - Connected Services and Cloud Computing
Trends and Enablers  - Connected Services and Cloud ComputingTrends and Enablers  - Connected Services and Cloud Computing
Trends and Enablers - Connected Services and Cloud Computing
 
Digital Ecosystems - Connected Services and Cloud Computing
Digital Ecosystems - Connected Services and Cloud ComputingDigital Ecosystems - Connected Services and Cloud Computing
Digital Ecosystems - Connected Services and Cloud Computing
 
Services Convergence - Connected Services and Cloud Computing
Services Convergence - Connected Services and Cloud ComputingServices Convergence - Connected Services and Cloud Computing
Services Convergence - Connected Services and Cloud Computing
 
Models and Architecture - Connected Services and Cloud Computing
Models and Architecture - Connected Services and Cloud ComputingModels and Architecture - Connected Services and Cloud Computing
Models and Architecture - Connected Services and Cloud Computing
 
Introduction, Examples - Firebase
Introduction, Examples - Firebase Introduction, Examples - Firebase
Introduction, Examples - Firebase
 
Vue js and Vue Material
Vue js and Vue MaterialVue js and Vue Material
Vue js and Vue Material
 
React Example + Bootstrap
React Example + BootstrapReact Example + Bootstrap
React Example + Bootstrap
 
introduction to material design lite MDL
introduction to material design lite MDLintroduction to material design lite MDL
introduction to material design lite MDL
 

Último

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Último (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

Greenfoot Introduction (2)

  • 1. Introduction To Greenfoot Part-2 kakihijau.googlepages.com
  • 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. Purpose  This is the second part of the document „Introduction to Greenfoot“ and focuses on understanding 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. Outline  Class Display Revisited  Class Editor  The Leaf Class  The Wombat Class  The WombatWorld Class Introduction to Greenfoot 4 Eueung Mulyana | kakihijau.googlepages.com
  • 5. Class Display Revisited  Class display contains all classes which are used in a scenario  Class World and Actor are abstract superclasses, part of the Greenfoot system  Scenario wombats has 2 actor classes (Wombat, Leaf) Introduction to Greenfoot 5 Eueung Mulyana | kakihijau.googlepages.com
  • 6. Class Editor (1)  We can modify objects behaviour by editing the source code of the corresponding class  To display the source code editor: – Double-click the class – Right-click the class, choose the item „Open editor“ Introduction to Greenfoot 6 Eueung Mulyana | kakihijau.googlepages.com
  • 7. Class Editor (2) Introduction to Greenfoot 7 Eueung Mulyana | kakihijau.googlepages.com
  • 8. The Leaf Class  The simplest class compared to the Wombat and WombatWorld class  Leaf objects do nothing!  As you can see in the previous slide, the Leaf class has no statement and consists of an empty constructor Introduction to Greenfoot 8 Eueung Mulyana | kakihijau.googlepages.com
  • 9. The Wombat Class (1) import necessary packages class header; Wombat is a subclass from Actor data (constants and variables) class constructor and methods Introduction to Greenfoot 9 Eueung Mulyana | kakihijau.googlepages.com
  • 10. The Wombat Class (2)  4 constants : EAST, WEST, NORTH, SOUTH  2 variables : direction, leavesEaten  1 constructor : Wombat()  8 methods : – getLeavesEaten(), foundLeaf(), eatLeaf() – setDirection(), turnLeft() – canMove(), move() – act() Introduction to Greenfoot 10 Eueung Mulyana | kakihijau.googlepages.com
  • 11. The Wombat Class (3) constructor  initialising direction and leavesEaten is there any Leaf object in my position? this method is inherited from the superclass Actor remove that Leaf object update the variable leavesEaten Introduction to Greenfoot 11 Eueung Mulyana | kakihijau.googlepages.com
  • 12. The Wombat Class (4) Introduction to Greenfoot 12 Eueung Mulyana | kakihijau.googlepages.com
  • 13. The Wombat Class (5) this method is inherited from the superclass Actor Introduction to Greenfoot 13 Eueung Mulyana | kakihijau.googlepages.com
  • 14. The Wombat Class (6) change direction 90 degrees to the left Introduction to Greenfoot 14 Eueung Mulyana | kakihijau.googlepages.com
  • 15. The Wombat Class (7) these methods are inherited from Actor new coordinate if the object moves forward; depends on its direction checks if the object reaches the edges of the world Introduction to Greenfoot 15 Eueung Mulyana | kakihijau.googlepages.com
  • 16. The Wombat Class (8) Introduction to Greenfoot 16 Eueung Mulyana | kakihijau.googlepages.com
  • 17. The Wombat Class (9) if object reaches one of the borders, do nothing! the object moves setLocation() is forward; inherited from Actor depends on its direction Introduction to Greenfoot 17 Eueung Mulyana | kakihijau.googlepages.com
  • 18. The Wombat Class (10) 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 the left! Introduction to Greenfoot 18 Eueung Mulyana | kakihijau.googlepages.com
  • 19. The WombatWorld Class (1)  1 constructor : WombatWorld()  2 methods : – populate() – randomLeaves() Introduction to Greenfoot 19 Eueung Mulyana | kakihijau.googlepages.com
  • 20. The WombatWorld Class (2) calls the World constructor sets the background. the method is inherited from the superclass World cell.jpg Introduction to Greenfoot 20 Eueung Mulyana | kakihijau.googlepages.com
  • 21. The WombatWorld Class (3) Introduction to Greenfoot 21 Eueung Mulyana | kakihijau.googlepages.com
  • 22. The WombatWorld Class (4) Create a Leaf object at a random position (x,y); repeat howmany times Introduction to Greenfoot 22 Eueung Mulyana | kakihijau.googlepages.com