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

2021/3/14

Restart button class for two different worlds

AnJoMorto AnJoMorto

2021/3/14

#
I'm making a game with 2 two different game modes and would like to program a replay button that would identify the game mode to make a new same world. Something in this spirit (now I know that .equals() doesn't work like this but just so you have an idea of what I want to make):
        if(Greenfoot.mouseClicked(this))
        {
            
            if(getWorld().equals(ArcadeWorld.class))
            {
            
                Greenfoot.setWorld(new ArcadeWorld());
            
            }
            if(getWorld().equals(ClassicWorld.class))
            {
            
                Greenfoot.setWorld(new ClassicWorld());
            
            }   
        
        }
Does anyone have any idea on how to achieve this?
danpost danpost

2021/3/14

#
Use the instanceof conditional:
if (getWorld() instanceof ArcadeWorld)
for example.
AnJoMorto AnJoMorto

2021/3/14

#
Oh I didn't even know that this thing existed. Thank you!
You need to login to post a reply.