We have 4 levels (DemoWorld, Maze1, Maze2, Maze3) and we want to advance a level every time cheeseCount == 2 (change to Maze1), cheeseCount == 52 ( go to Maze2) and cheeseCount ==102 (go to Maze3) The program changes to Maze1 after all the cheese is collected in DemoWorld but after we enter aMaze1 and collect all the cheese, the world doesn't change.....
public class Mouse extends Actor{ private int cheeseCount=0; Actor cat = getOneIntersectingObject(Cat.class); if(cat!=null){ World DemoWorld = getWorld(); Greenfoot.setWorld(new Maze1()); } Actor falcon = getOneIntersectingObject(Falcon.class); if(falcon!=null){ World DemoWorld = getWorld(); Greenfoot.setWorld(new Maze1()); } Actor snake = getOneIntersectingObject(Snake.class); if(snake!=null){ World DemoWorld = getWorld(); Greenfoot.setWorld(new Maze1()); } Actor c = getOneIntersectingObject(Cheese.class); if(c != null){ cheeseCount++; getWorld().removeObject(c); } if(getWorld().getObjects(Cheese.class).size() == 0) { changeLevel(); } } public void changeLevel() { if(cheeseCount == 102) { Greenfoot.setWorld(new Maze3()); } if(cheeseCount == 52){ Greenfoot.setWorld(new Maze2()); } if(cheeseCount == 2) { Greenfoot.setWorld(new Maze1()); } } }