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

2017/3/16

I need help URGENTLY :(

Katsura Katsura

2017/3/16

#
Good evening Greenfooters I want to create a "portal" that will serve as the link between my four levels in my game. The "portal" needs to appear once a JOptionpane question is answered correctly by the player and if it is not answered correctly the game will be over. How do I do this? I haven't a clue what to do but please keep it simple as I am a simpleton in coding xD. Thank you for taking your time to read. Best regards Katsura
Super_Hippo Super_Hippo

2017/3/16

#
Do you already have the question popping up?
Katsura Katsura

2017/3/16

#
Hey Supper_Hippo No I don't have a question that pops up but that shouldn't be tricky, I just don't know how to implement the correct answer to activate the portal and how to make incorrect answer end game
Super_Hippo Super_Hippo

2017/3/16

#
It will look something like this:
String answer = Greenfoot.ask("Question text"); //or use some J thing if you prefer that
if ("correct answer".equals(answer))
{
    //create portal
}
else
{
    //end game
}
Katsura Katsura

2017/3/16

#
Awesome stuff thanks Hippo! But how do I make a portal that links between worlds? And how do I make the game end? I have a counter in my game but I don't how to set limit of "10" points before round passed... Can you help me please xD Katsura :)
Super_Hippo Super_Hippo

2017/3/16

#
For linking portals, I would think of doing it like the following. (Call the addPortal method when you want to add a portal. Depending on how you want to do it, this method could look different or could be simplified.) For the other part, in your counter, when the value changes, check if it is 10.
private static World worlds =
{
    new MyWorld(0);
    new MyWorld(1);
    new MyWorld(2);
    new MyWorld(3);
};

private int level;

public MyWorld() //without parameter, when starting the game
{
    this(0); //start with level 1
}

public MyWorld(int lvl)
{
    super(......);
    level = lvl;
    //objects added to every world in the same place, maybe score, health
    switch(level)
    {
        case 0: //things added to the first level
        
        break;
        
        case 1: //things added to the second level
        
        break;
        
        //...
    }
}

public void addPortal()
{
    switch(level)
    {
        case 0: //in first level
        addObject(new Portal(1), 210, 120); //add a portal leading to the second level
        break;
        
        case 1: //in second level
        //...
    }
}

public void changeWorld(int target)
{
    Greenfoot.setWorld(worlds[target]);
}
private int target;

public Portal(int t)
{
    target = t;
}

public void changeWorld()
{
    ((MyWorld)getWorld()).changeWorld(target);
}
//in player's act method
Portal p = (Portal) getOneIntersectingObject(Portal.class);
if (p != null)
{
    p.changeWorld();
}
You need to login to post a reply.