I'm having an issue with the getWorld error. I'm trying to have spikes randomly spawn throughout the map at set intervals, and I set it up accordingly. However, whenever I compile my code I get an error stating that Greenfoot cannot find symbol - method getWorld()
Here is my code:
public class world extends World { private int counter; static int randomNumber; /** * Constructor for objects of class world. * */ public world() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); addSpikes(); int randomNumber = 1+ Greenfoot.getRandomNumber(24); } public void addSpikes() { if (randomNumber > 0) { randomNumber --; if (randomNumber == 0) { int x = Greenfoot.getRandomNumber(getWorld().getWidth()); int y = Greenfoot.getRandomNumber(getWorld().getWidth()); for (int count = 0; count < 2; count = count + 1) { if (getObjects(Spike.class, x, y).isEmpty()) setLocation(x,y); } } } } }