I have this game where once the ball is eaten by the bullet, you get one point. The games is over when you get 7 points. However, when I apply the code, (this code is in the Bullet.class), the game stops once you have shot 7 bullets. How can I correct this?
Here is my code for the bullet:
public class Bullet extends Animal
{
private int ballEaten = 0;
/**
* Act - do whatever the Bullet wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
moveUpwards();
ballGone();
outOfScreen();
gameOver();
}
/**
* The bullets move in an upwards direction.
*/
public void moveUpwards()
{
setLocation(getX(), getY()-3);
}
/**When the bullet touches the ball, the ball will disappear.
*
*/
public void ballGone()
{
if (canSee(Ball.class))
{
eat(Ball.class);
ballEaten++;
if (ballEaten == 2)
{
gameOver();
}
}
}
public void gameOver()
{
Greenfoot.stop();
}
/**
* When the bullets reach the top of the World/Screen, they will disappear.
*/
public void outOfScreen()
{
if (atWorldEdge())
{
removeTouching(Bullet.class);
}
}
}

