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

2019/2/3

Control Redirection to Multiple Worlds with One Method.

Lewis12374 Lewis12374

2019/2/3

#
I'm trying to achieve making my menu as abstract as possible, but I cannot seem to find a way around doing so. This is what I have tried so far, with no progression. Please help? SuperClass
public abstract class SuperClass extends Actor
{
    public void menuControl(String world)
    {
        if(Greenfoot.mouseClicked(this))
        {
            Greenfoot.setWorld(new world);
        }
    }
}
SubClass1
    
public void act() 
    {
        menuControl("HelpScreen");
    }  
danpost danpost

2019/2/3

#
Lewis12374 wrote...
I'm trying to achieve making my menu as abstract as possible, but I cannot seem to find a way around doing so. This is what I have tried so far, with no progression. Please help? << Code Omitted >> The error received is: '(' or '' expected on the SuperClass.
The compiler is expecting a class name followed by a parameter list (a set of round parentheses that may or may not contain any elements). It has yet to complain that you use a String object for the name or that it cannot find a class named "HelpScreen" (including the quotes) -- I suspect it will do one or the other after you add parentheses to it. You will have to replace line 7 with a bunch of if statements (or a switch statement) that branches to each type world dependent on the String value.
You need to login to post a reply.