greenfoot Flashcards
what does round brackets mean?
they are used in mathematical expressions, and to surround the parameter lists for method calls
what does curly brackets mean?
these are used to surround blocks of code, such as methods or the contents of classes.
what does square brackets mean?
they are used for arrays.
what does compile mean?
compile combines the different classes and subclasses onto the world, we must compile the classes before we run the program otherwise it wouldn’t work, if we don’t compile the classes, they are unable to go on the world
what does move() mean?
allows the classes/objects to move and the number inside the brackets dictates how far it moves each click
what does SetRotation() mean
allows the classes/objects to turn and the number inside the bracket dictates how far it turns
what does if() mean?
this works the same way an if statement does in python for example if the down key is pressed it will move down (if that’s how you have programmed it)
whats does Greenfoot.isKeyDown(“left”) mean?
if the left arrow key is pressed the classes/ object will turn left
how would you make the classes turn right and move?
if (Greenfoot.isKeyDown(“right”))
{
setRotation(0);
move(1);
}
how would you make it so that if your main character touches a specific actor, the specific actor will disappear?
if(isTouching(cherry.class))
{
removeTouching(cherry.class);
}
how do you add a counter so that when the cherry disappears a point is added to this previous piece of code?
if(isTouching(cherry.class))
{
removeTouching(cherry.class);
Counter counter = (Counter)getWorld().getObjects(Counter.class).get(0);
counter.add(1);
}
how would the code look if you wanted to change it so that when the plum disappears a point is deducted
if(isTouching(plum.class))
{
removeTouching(plum.class);
Counter counter = (Counter)getWorld().getObjects(Counter.class).get(0);
counter.add(-1);
}
how do you make your actor turn at random
move(1);
if (Greenfoot.getRandomNumber(10)<1)
{
turn(Greenfoot.getRandomNumber(90)-45);
}
how would you play a sound when a cherry is removed
if(isTouching(cherry.class))
{
removeTouching(cherry.class);
Greenfoot.playSound(“sound2.mp3”);
}