Greenfoot Flashcards
What is the code used to make an enemy turn randomly?
turn((Greenfoot.getRandomNumber(180)-90)
What is the code used to detect if the player is touching the collect?
if(isTouching(—–.class))
What is the code used to make the collect disappear when touched by the player?
removeTouching(—–.class)
What must be imported at the top of the counter code?
import java.awt.Color;
What variables must be created at the top of the counter code?
int score = 0;
int amount = 0;
What code is used to create the counter?
setImage(new GreenfootImage(“Score = “ + score, 20, Color:BLACK, Color:WHITE));
What code is used in the counter code to add to the score?
public void addToScore(int amount)
{
score += amount
}
What code is used in the counter code to allow the score to decrease?
public void loseLife()
{
score+=amount
}
What is used in the player code to access the counter?
counter counter = (counter) getWorld().getObjects(counter.class).get(0);
What is used in the player code to add 1 to the score?
counter.addToScore(1)