import greenfoot.*;
/**
* Apples are falling from trees with different speed.
* When the basket catch them, they will disappear.
* But if apples hit the ground, they will explode.
*
* Kim & Iris
* 5/19/2016
*/
public class Apple extends Actor
{
private int speed;
private GreenfootImage image2;
private int appleFell;
private int score;
private int time;
/**
* Constructor: Initialise the speed to a somewhat random value.
*/
public Apple()
{
speed = Greenfoot.getRandomNumber(2) + 1;
image2 = new GreenfootImage("explode.png");
appleFell = 0;
}
/**
* Fall from the tree
*/
public void act()
{
setLocation(getX(), getY()+speed);
switchImage();
stopGame(6);
}
/**
* When apples hit the ground, they will explode.
*/
public void switchImage()
{
if (getY() == 570)
{
setImage(image2);
Greenfoot.delay(5);
getWorld().removeObject(this);
appleFell = appleFell +1;
}
}
public void stopGame(int points)
{
if (appleFell == 6)
{
appleFell++;
appleFell = appleFell +1;
Greenfoot.stop();
}
}
}
smcgee wrote...
I am unable to make the game stop after 6 apples have fallen.


