xyoreo.blogg.se

Greenfoot commands
Greenfoot commands






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.

greenfoot commands

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.

greenfoot commands

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

  • We shall be using the Java programming language for our projects.
  • In this case, they are World, WombatWorld, Actor, Leaf, and Wombat. The class diagram shows us the classes involved in this scenario.
  • We shall discuss the class diagram first.
  • We’ll come back to them in a little while, too. The Act, Run, and Reset buttons and the speed slider at the bottom are the execution controls. We shall discuss this in more detail shortly. The area on the right with the beige-colored boxes and arrows is the class diagram. This is where the program will run and we will see things happen. The largest area covering most of the screen (a sandcolored grid in this case) is called the world.






    Greenfoot commands