Greenfoot Flashcards

1
Q

How do you make an actor turn and move randomly?

A

move(Greenfoot.getRandomNumber(2));
turn(90*Greenfoot.getRandomNumber(3));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you make actor move in the direction of the arrow keys when pressed?

A

if (Greenfoot.isKeyDown(“left”))
{
setLocation(getX()-1,getY());
}
if (Greenfoot.isKeyDown(“right”))
{
setLocation(getX()+1,getY());
}
if (Greenfoot.isKeyDown(“up”))
{
setLocation(getX(),getY-1());
}
if (Greenfoot.isKeyDown(“down”))
{
setLocation(getX(),getY+1());
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to edit actor(1) code to make an actor(1) remove another actor(2) when it collided with it?

A

Actor collided = getOneIntersectingObject(actor(2).class);
if (collided != null)
{
getWorld().removeObject(collided);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to add a sound every time actor(1) collides with actor(2)?

A

Greenfoot.playSound(“pop.wav”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to edit actor(1) code so the counter displays how many actor(2) it’s collided with?

A

((Counter)getWorld().getObjects(Counter.class).get(0)).bumpCount(1);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the correct counter code?

A

private int totalCount = 0;
public Counter()
{
setImage(new GreenfootImage(“0”, 20, Color.WHITE, Color.BLACK));
}
public void bumpCount(int amount)
{
totalCount += amount;
setImage(new GreenfootImage(“” + totalCount, 20, Color.WHITE, Color.BLACK));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to edit actor(2) code so it removes itself if it collides with actor(3)?

A

Actor collided = getOneIntersectingObject(actor(3).class);
if (collided != null)
{
getWorld().removeObject(this);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to edit actor(2) code so that 1 point is deducted from the counter if actor(2) is removed?

A

((Counter)getWorld().getObjects(Counter.class).get(0)).bumpCount(-1);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to make the world class a square

A

Change the numbers in the world class’s method into:
super(9, 9, 60);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to make actor(2) move randomly left to right?

A

move(Greenfoot.getRandomNumber(2));
turn(180*Greenfoot.getRandomNumber(3));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the term ‘superclass’ mean and examples?

A

A class which other classes inherit from, e,g. World & Actor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does the term ‘property’ mean?

A

A variable associated with a class, e.g. private xyz

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the term ‘class’ mean?

A

Representation of a real world object, e.g. cat, mouse & ground

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the term ‘method’ mean?

A

A function associated with a class, e.g. public xyz

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the term ‘comment’ mean?

A

An additional bit of information that explains what some code is doing, e.g.
/**
*xyz
*/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly