Presentation is loading. Please wait.

Presentation is loading. Please wait.

Kakihijau.googlepages.com Introduction To Greenfoot Part-2.

Similar presentations


Presentation on theme: "Kakihijau.googlepages.com Introduction To Greenfoot Part-2."— Presentation transcript:

1 kakihijau.googlepages.com Introduction To Greenfoot Part-2

2 Introduction to Greenfoot Eueung Mulyana | 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).

3 Introduction to Greenfoot 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

4 Introduction to Greenfoot Eueung Mulyana | kakihijau.googlepages.com 4 Outline  Class Display Revisited  Class Editor  The Leaf Class  The Wombat Class  The WombatWorld Class

5 Introduction to Greenfoot 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)

6 Introduction to Greenfoot 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“

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

8 Introduction to Greenfoot 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

9 Introduction to Greenfoot 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

10 Introduction to Greenfoot 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()

11 Introduction to Greenfoot Eueung Mulyana | kakihijau.googlepages.com 11 The Wombat Class (3) constructor  initialising direction and leavesEaten this method is inherited from the superclass Actor is there any Leaf object in my position? remove that Leaf object update the variable leavesEaten

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

13 Introduction to Greenfoot Eueung Mulyana | kakihijau.googlepages.com 13 The Wombat Class (5) this method is inherited from the superclass Actor

14 Introduction to Greenfoot Eueung Mulyana | kakihijau.googlepages.com 14 The Wombat Class (6) change direction 90 degrees to the left

15 Introduction to Greenfoot 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

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

17 Introduction to Greenfoot Eueung Mulyana | kakihijau.googlepages.com 17 The Wombat Class (9) if object reaches one of the borders, do nothing! setLocation() is inherited from Actor the object moves forward; depends on its direction

18 Introduction to Greenfoot 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!

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

20 Introduction to Greenfoot 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

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

22 Introduction to Greenfoot Eueung Mulyana | kakihijau.googlepages.com 22 The WombatWorld Class (4) Create a Leaf object at a random position (x,y); repeat howmany times


Download ppt "Kakihijau.googlepages.com Introduction To Greenfoot Part-2."

Similar presentations


Ads by Google