I was going through the code of one of my classmates and there's this line I cannot understand:
Asteroid.anz++;
in
public void randomAsteroid(){
Asteroid.anz++;
if ( Greenfoot.getRandomNumber(100+(5*Asteroid.anz)) < 5 )
{
Asteroid asteroid = new Asteroid();
int x = Greenfoot.getRandomNumber(getWorld().getWidth());
int y = Greenfoot.getRandomNumber(getWorld().getHeight());
getWorld().addObject(asteroid, x, y);
}
}
anz is a public static int variable declared in the class Asteroid:
public static int anz = 0;
the method is also defined in the class Asteroid.
I'm a rookie and my question is - why do I have to mention the class in Asteroid.anz++?
When I delete "Asteroid" from the line the code works but I get multiple asteroids in the universe. And when it is there, there's only one asteroid. Why is it like this? :)
