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

2018/6/7

how can i find specific world detection

roonie01 roonie01

2018/6/7

#
public void switchWorld()
    {   
         
        if(score>=10100) 
        {
          Greenfoot.setWorld(new stage2());
          
        }
        if(score>=100100&&Greenfoot.getWorldOfType(stage2))
        {
            Greenfoot.setWorld(new stage3());
        }
        
    }
danpost danpost

2018/6/7

#
roonie01 wrote...
how can i find specific world detection
I do not know of any getWorldOfType method. A check for a type of world would be like this:
if (getWorld() instanceof stage2)
roonie01 roonie01

2018/6/8

#
so i did that and my switching worlds still wont work because as i change worlds the score is to be reset which happens and the score to pass to the next stage is supposed to be increased to 100k, but this never happens
 public void switchWorld()
    {   
        if(getWorld()instanceof MyWorld)
        {
            if(score>=10100) 
            {
                Greenfoot.setWorld(new stage2());
                score=0;
            }
        }
        if(getWorld()instanceof stage2)
        {
            if(score>=100100)
            {
                Greenfoot.setWorld(new stage3());
            }
        }

    }
roonie01 roonie01

2018/6/8

#
would it change anything if my stage2 and stage3 are subclasses of my main world
danpost danpost

2018/6/8

#
roonie01 wrote...
would it change anything if my stage2 and stage3 are subclasses of my main world
One should not be a subclass of another. You can adjust the score in a new stage after you create it. For example, to show process -- not precise code you may need to use:
stage3 s3 = new stage3();
s3.getPlayer().bumpScore(score+100000);
Greenfoot.setWorld(s3);
roonie01 roonie01

2018/6/12

#
is there another way by using a class for my counter
danpost danpost

2018/6/12

#
roonie01 wrote...
is there another way by using a class for my counter
A class for the counter can be used with what I suggested above.
You need to login to post a reply.