This is the next arrow code. When you click it, it should always go to the next world, yet it does not do this. The idea is that every time the next arrow button is clicked, it will go to the next world. Clicking NextArrow in Map1 will send it to Map2. Clicking NextArrow in Map2 will send it to Map3 and so on.
This is the Map1 code. It is the same as the other maps besides the parameters for the next arrow which is set to the number of the world it is in.
Thanks in advance for any advice and suggestions!
public class NextArrow extends Actor
{
public int worldVar;
public NextArrow(int worldVar)
{
}
/**
* Act - do whatever the NextArrow wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
//int number = 0;
//int number2 = 1;
if(Greenfoot.mouseClicked(this))
{
//Greenfoot.setWorld(new ("Map"+number()) );
//Greenfoot.setWorld(new Map2());
System.out.println("before "+worldVar);
World world = getWorld();
if(worldVar == 2)
{
Greenfoot.setWorld(new Map3());
System.out.println(worldVar);
}
if(worldVar == 1)
{
Greenfoot.setWorld(new Map2());
System.out.println(worldVar);
}
}
}
}public class Map1 extends World
{
/**
* Constructor for objects of class Map1.
*
*/
public Map1()
{
super(700, 500, 1);
Actor actor = new Bulbasaur();
addObject(actor,100,100);
prepare();
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
NextArrow nextarrow = new NextArrow(1);
addObject(nextarrow,698,547);
nextarrow.setLocation(604,454);
}
}
