This site requires JavaScript, please enable it in your browser!
Greenfoot back
collin.leck
collin.leck wrote ...

2013/6/4

Help with changing levels

collin.leck collin.leck

2013/6/4

#
I need some help with changing levels using either an if statement or something else.
      if (counter.getValue()==80){
          Greenfoot.setWorld(new Level2());
        }
      if (counter.getValue()==150
      {
          Greenfoot.setWorld(new Level3());
       }
Thanks in advanced to anyone who can help.
It looks good. What's the problem you're having?
collin.leck collin.leck

2013/6/4

#
When I get to the next level it keeps using the first if statement and it does not go to the next if statement and so I am not able to get to level 3. Is there any way to run the first if statement and then make it false or so it does not run so i can get to the next level. If you want a copy of the application send me an email. collin.leck@gmail.com
Game/maniac Game/maniac

2013/6/4

#
What do the level subclasses extend?
collin.leck collin.leck

2013/6/4

#
The World
danpost danpost

2013/6/4

#
You can add a condition to each of the 'if' statements to make it do what you want:
if (counter.getValue()==80 && getWorld() instanceof Level1) {
    Greenfoot.setWorld(new Level2());
}
if (counter.getValue()==150 && getWorld() instanceof Level2) {
    Greenfoot.setWorld(new Level3());
}
I hope you do realize that the counter value is being reset to zero for each level.
collin.leck collin.leck

2013/6/4

#
thank you to everyone for the help. danpost thank you for the code and it works.
You need to login to post a reply.