A dialogue will pop up that lets you enter a valueįor this parameter. The term 'int' tells you that a whole number isĮxpected, and the name 'howMany' suggests that you should specify how many leaves you It means that you must specify some additional bit of information Words between the parenthesis after its name: 'int howMany'. Some leaves in the world at random locations. YouĪnother world method is 'randomLeaves(int howMany)'. That creates several leaves and wombats and places them into the world. One of the methods in this menu is 'populate()'. Right-click on any empty space in the world, or in the greyĪrea immediately next to the world, and you will see the world's menu: The world itself is also an object with methods that youĬan invoke. We have seen that objects in the world have methods which you can invoke The old world isĭiscarded (and with it all the objects that were in it) - you can only have This is usually done by clicking the 'Reset' button in theĮxecution controls. Want to start all over, there is one easy option: throw away the world andĬreate a new one. If you have many objects in the world that you do not want anymore, and you If you want just one object to act instead ofĪll the objects in the world, you can do this by invoking the object's act() You will also notice a method called 'act()'. The wombat to eat another leaf, and try calling that method again. You how many leaves this wombat has eaten so far. You can select any of the methods shown here to ask the wombat to do Wombat class), and you will see that objects in the world also have a pop-up Then right-click on the wombat (the one in the world, not the Make sure you have a wombat in the world, and the scenario is not A method is a single action that an object can perform. Instead of just running the whole scenario, you can also invoke single methods. Then change the slider, and you'll see the difference. The slider next to the Act and Run buttons sets the speed. To a 'Pause' button Clicking Pause stops everything acting. You will notice that the Run button changes This is equivalent to clicking the 'Act' button Wombats, then click Act - the wombats will move forward and eat the leaves. Placing two wombats into the world and press Act again. In ourĮxample, leaves are programmed to do nothing, while wombats are programmed to move forward. That is: each object does whatever it is programmed to do. Much faster! Make objects actĬlick the 'Act' button in the execution controls. Will place one object of the selected class at every click. Then hold down the Shift key and left-click in the world several times. Make sure the Leaf class is selected (leftĬlick on it in the classes panel, and it will get a thicker black border), There is a shortcut to place several objects a bit faster: Right-click the Leaf class, select 'new Leaf()' and place the leaf into Wombats eat leaves, so let's put some leaves into the world as Have just created a wombat (in Java terms: an object) and placed it into the Right-click (on Mac, Control-click whenever this tutorial says right-click) the Wombat class in the class display. We will now place some objects into the world. Let's label all these things on our interface: Place objects into the world The other classes belong to the wombat scenario, and will be differentīelow the world are the Execution Controls (the area with the 'Act' and 'Run'īuttons and the slider). "World" and "Actor" will always be there - they come with the Greenfoot You can see all Java classes that are involved in the project. Towards the right side of the window is the class display. Since we have a scenario here that has to do The large grid area that covers the majority of the window is called "the Have diagonal slashes over them, this is because the code is uncompiled.Ĭlick on the "Compile" button in the bottom-right. If you don't see the world, and the classes on the right Open the wombats scenario in Greenfoot you should then see this: This tutorial uses a scenario called 'wombats' which you can download here (it is also included in the example scenarios with Greenfoot versions before 2.4.0). This tutorial will explain the basics of the Greenfoot interface, and
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |