Hi,
I'd like to set a new level/world.
I have an integer called "level". The code
Greenfoot.setWorld(level);
Will not work, because setWorld expects a world variable, but "level" is an integer. How can this problem be solved?


private int level; // you should already have this public WorldName() { this(1); // calls the other constructor passing the level value // the (1) can be adjusted; like if you start the value at zero } // this will be the constructor that does the work public WorldName(int lev) { super(600, 400, 1); level = lev; // rest of construction code
Greenfoot.setWorld(new WorldName(level+1));
WorldName world=new WorldName(); world.level=level+1; world.score=score; // etc. -- public methods in the re-created world can be called from here also world.setMainActor(zelda); // this is just an example; the method would have to be created
public WorldName() { this(1, zelda); // calls the other constructor passing the level value // the (1) can be adjusted; like if you start the value at zero } // this will be the constructor that does the work public WorldName(int lev, Zelda zelda) {
public Zelda zelda = new Zelda();
public class WorldName(int lev, Zelda zelda) { super(600, 400, 1); level = lev; this.zelda = zelda; // ***** this line **** // rest of construction }
if (diedInLevel1) { Greenfoot.setWorld(new Level1(1, zelda)); } else if (diedInLevel2 .....