Kakihijau.googlepages.com Introduction To Greenfoot Part-2.
-
Upload
samuel-simon -
Category
Documents
-
view
216 -
download
0
Transcript of Kakihijau.googlepages.com Introduction To Greenfoot Part-2.
![Page 1: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/1.jpg)
kakihijau.googlepages.com
Introduction To
GreenfootPart-2
![Page 2: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/2.jpg)
2Introduction to Greenfoot
Eueung Mulyana | 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).
![Page 3: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/3.jpg)
3Introduction to Greenfoot
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
![Page 4: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/4.jpg)
4Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Outline
Class Display Revisited Class Editor The Leaf Class The Wombat Class The WombatWorld Class
![Page 5: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/5.jpg)
5Introduction to Greenfoot
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)
![Page 6: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/6.jpg)
6Introduction to Greenfoot
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“
![Page 7: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/7.jpg)
7Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Class Editor (2)
![Page 8: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/8.jpg)
8Introduction to Greenfoot
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
![Page 9: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/9.jpg)
9Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (1)import necessary packages
class header;Wombat is a subclassfrom Actor
data (constants andvariables)
class constructor and methods
![Page 10: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/10.jpg)
10Introduction to Greenfoot
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()
![Page 11: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/11.jpg)
11Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (3)
constructor initialisingdirection and leavesEaten
this method is inherited fromthe superclass Actor
is there any Leaf objectin my position?
remove that Leaf objectupdate the variableleavesEaten
![Page 12: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/12.jpg)
12Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (4)
![Page 13: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/13.jpg)
13Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (5)
this method is inherited fromthe superclass Actor
![Page 14: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/14.jpg)
14Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (6)
change direction 90 degreesto the left
![Page 15: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/15.jpg)
15Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (7)
these methods areinherited from Actor
new coordinateif the object movesforward; depends on its direction
checks if the objectreaches the edges of the world
![Page 16: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/16.jpg)
16Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (8)
![Page 17: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/17.jpg)
17Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
The Wombat Class (9)
if object reaches one ofthe borders, do nothing!
setLocation() isinherited from Actor
the object movesforward; depends on its direction
![Page 18: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/18.jpg)
18Introduction to Greenfoot
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!
![Page 19: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/19.jpg)
19Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
The WombatWorld Class (1)
1 constructor : WombatWorld()
2 methods :– populate()– randomLeaves()
![Page 20: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/20.jpg)
20Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
The WombatWorld Class (2)
calls the World constructor
sets the background.the method is inheritedfrom the superclass World
cell.jpg
![Page 21: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/21.jpg)
21Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
The WombatWorld Class (3)
![Page 22: Kakihijau.googlepages.com Introduction To Greenfoot Part-2.](https://reader035.fdocuments.us/reader035/viewer/2022062500/5697c0271a28abf838cd6207/html5/thumbnails/22.jpg)
22Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
The WombatWorld Class (4)
Create a Leaf object at a randomposition (x,y); repeat howmanytimes