So I am doing this assignment for school and 1 line of code isn't working. Everything compiles correcty but when it runs it freezes every time it runs the line of code.
The line getWorld().addObject(new Fish(), 0, 0); is what isn't working.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Fish here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Fish extends Animals
{
public int Health;
/**
* Act - do whatever the Fish wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move();
Respawn();
Fatality();
}
public void Respawn()
{
if(atWorldEdgeforFish())
{
//This teleports the fish to either the same spot on the y-axis or a random spot
//on the y-axis whenever a fish reaches the right edge of the world
if(Greenfoot.getRandomNumber(3) == 1)
{
setLocation(0,getY());
Health++;
}
else
{
setLocation(0,Greenfoot.getRandomNumber(getWorld().getHeight() + 1));
Health++;
}
}
}
public void Fatality()
{
//this will remove fish after a certain number of laps and then add a new fish in
if(Health >= 7 + Greenfoot.getRandomNumber(4) && Greenfoot.getRandomNumber(21) == 1)
{
getWorld().removeObject(this);
getWorld().addObject(new Fish(), 0, 0);
}
}
}

