
void setDirection(int direction) The parentheses after the method name hold the parameter list.Parameters The other bit in the method menu that we have not yet discussed are the parentheses after the method name. When the wombat eats a leaf the int (integer) will increase to 1. Here we have the getLeavesEaten() method returning 0 since the wombat has not eaten any leaves. This example shows the canMove() method call returning false since the wombat cannot move since it is at the edge of the game world. Here we see the Greenfoot interface with the method canMove() returning true. In this case the methods is telling us that the wombat can move if we want it to move. This example shows a return type of true, which is a boolean return type. The return type of a method specifies what a method call will return. They just carry out their action, and then stop. The word void means “nothing” in this context: Methods with a void return type do not return any information. It tells us what the method returns to us when we invoke it. Return Types The word at the beginning is called the return type. Interact with objects through the contextual menu by right clicking on the object to see what methods can be called. Make three wombats and three leaves as shown here.

The game world for the wombat is part of the world class. A wombat is an object of the Actor class.
Greenfoot commands how to#
This is how to make a wombat appear in the game world. Objects and Classes Right Click on Wombat We can invoke a method by selecting it from the menu. It cannot hurt to get used to standard terminology straightaway, so we shall also call them methods from now on. In Java, these operations are called methods.For example, a wombat’s object menu shows us what this wombat can do (plus two additional functions, Inspect and Remove, which we shall discuss later). The object menu shows us all the operations this specific object can perform. This will pop up the object menu (Figure 1.4). Once we have placed some objects into the world, we can interact with these objects by rightclicking them.(Objects are also often referred to as instances in programming-the two terms are synonyms.) Once we have a class in Greenfoot, we can create objects. The class Wombat stands for the general concept of a wombat-it describes all wombats. Let us start by looking at the Wombat class.

The concepts of classes and objects are fundamental in object orientation.
