

it is equivalent to the instruction x = x + 1 - The methods getWidth() and getHeight() are inherited from the World class and allow to get the width and height of the world.ġ9 De spelrand Compile your code, you should get the following screenĢ0 Klasse SnakeBody Create a new sub-class of our Block classĬall it SnakeBody et choose the image of Bobby, bobby.png All statements in Java always end with - The statement x++ allow to add 1 to the variable x. So, the statement x = 0 allow to initialize the variable x with the value 0. We will often use this type which represents an integer number (0, 1, 2, …) - The statement variable = allow to assign the value of the expression to the variable.

Next, a second loop will define a variable y, from 0 to the game height, and in this loop, we will display the blocks on the left and on the right A few additional explanations here: - Variables in Java are always typed, here the type of the variable x and y is int. In this loop, we display the blocks on the top and the bottom (note that, as we the first line index is 0, the last line index is the number of lines – 1). The syntax of a « for loop » is the following : The following schema illustrates the execution of that loop: To display the borders of our game, we will write a first loop that defines a variable x, from 0 to the width of the game. For that, we will use a very useful command, the « for loop » of Java.
#Greenfoot lessons code
To display blocks all around our screen, it would be a little tedious to write down a line of code for each block. We kunne ook zeggen dat objecten « instanties » van de klasse zijn. Een klasse is een « model » waarmee we objecten bouwen. Java applicaties bestaan uit « Objecten » Elk Object bestaat uit 2 delen: zijn eigenschappen zijn « gedrag », de acties die het object kan doenĥ Klassen en Objecten Om een object te beschrijven,definieren we een klasse.
#Greenfoot lessons mac os
Greenfoot is gratis beschikbaar voor Microsoft Windows, Mac OS X, and Linux.ģ De Java taal « Object georienteerd » taalĮén van de meest gebruikte programmeertalen te wereld Ontwikkelen van applicaties voor verschillende systemen Windows, Mac, Linux, Android, … Is gemaakt om de Java taal te leren kennen. 2 Greenfoot Ontwikkelomgeving gebaseerd op de Java programmeertaal.
