Presentation is loading. Please wait.

Presentation is loading. Please wait.

Greenfoot. Getting Started Open the Greenfoot download site: Select Greenfoot 2.0.1.

Similar presentations


Presentation on theme: "Greenfoot. Getting Started Open the Greenfoot download site: Select Greenfoot 2.0.1."— Presentation transcript:

1 Greenfoot

2 Getting Started Open the Greenfoot download site: http://www.greenfoot.org/download/ http://www.greenfoot.org/download/ Select Greenfoot 2.0.1 “For other systems (executable jar file).” Download the.jar file to your Desktop. You can also download Greenfoot to your personal computer, but Java™ is a prerequisite.

3 Installing Greenfoot Open a terminal window and type the command below to change to your Desktop directory : cd Desktop Run the installer by typing the following command in your terminal window: java -jar Greenfoot-generic-201.jar (you must be in your Desktop directory)

4 The Installer Accept the default directories in the installer pop-up window. Complete the installation. The installer will install Greenfoot in your Desktop directory.

5 Running Greenfoot To run Greenfoot, simply type the following command in the terminal window: greenfoot/greenfoot (you must be in your Desktop directory) Choose this one

6 Cleanup Move the.jar file to the trash Empty the trash

7 What is Greenfoot? Who developed it? “Greenfoot supports development of graphical applications in the Java™ Programming Language.” “Greenfoot was designed and implemented at the University of Kent, England, and Deakin University, Melbourne, Australia.”

8 First Look You should see something similar to what is displayed as a background to this slide.

9 Getting Started World Class Diagram Execution Controls

10 Objects and Classes Right Click on Wombat Click New Wombat() Drag to World

11 Populate the world Press Run to run the simulation

12 Interacting with Objects Invoke the Move method Right Click on the Wombat

13 Return values

14 Parameters

15 Directions 1 3 2 0

16 Invoking wombatWorld Methods right-click the WombatWorld class and select ‘ new WombatWorld() ’. What happens? What type of function is WombatWorld()? How did you know that? right-click in the world “grid” –Try populate(). –Try randomLeaves(int howMany).

17 Change the Scenario Asteroids scenario

18 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

19 Inspect Right Click on an Object and Select Inspect Create a few objects

20 Inspect Right Click on the Object and Select Inspect

21 Editing Code Change back to the Wombat scenario Right-click on the Wombat class icon and select “Open editor”

22 Changing the Wombat Class Add the following method to the Wombat class: public void turnRandom() { // get a random number between 0 and 3... int turns = Greenfoot.getRandomNumber(4); //...an turn left that many times. for(int i=0; i<turns; i++) { turnLeft(); }

23 Change act() public void act() { if(foundLeaf()) { eatLeaf(); } else if(canMove()) { move(); } else { turnRandom(); // change turnLeft(); to turnRandom(); }

24 Compile Before you can execute your class changes you must compile your project. –Compile within the editor, or –Compile from Greenfoot’s main window. Once you have successfully compiled, you can create objects again. –Compilation (if successful) automatically instantiates a world object.

25 Changing Images 2 ways to change the image of objects –Change the image of a class, changing the image for all objects of that class. Select ‘Set Image...’ from the class’s pop-up menu. –Change the image of a object, changing only the individual object. Objects can change images as often as desired Call the ‘setImage’ method inherited from Actor. –one version of setImage() has a parameter of type GreenfootImage –one version of setImage() takes a String that is the name of an image file.

26 Documentation To make changes to object behavior, you often need to make use of some standard Greenfoot classes. Greenfoot provides four important classes that you should know about: 1.World 2.Actor 3.GreenfootImage 4.Greenfoot. Greenfoot’s online documentation: http://www.greenfoot.org/doc/ http://www.greenfoot.org/doc/ Video tutorials

27 In Class Activity If there isn’t one, create a Rock class---it doesn’t need to do anything. Modify wombatWorld’s populate() to initialize the world with 2 rocks, 3 wombat and 7 leaves to the wombatWorld. Run the simulation and notice that the wombats walk through the rocks. Modify the Wombat class so that it can’t walk through rocks. (BIG HINT: look at the Wombat2 scenario for a solution.)


Download ppt "Greenfoot. Getting Started Open the Greenfoot download site: Select Greenfoot 2.0.1."

Similar presentations


Ads by Google