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

2012/4/10

World Subclasses

Dingram Dingram

2012/4/10

#
Hi, I'm attempting to build a game which has multiple levels and I'd like overriding variables which keeps track of things like entry locations and enemies remaining etc. To do this I thought I'd create a subclass of world and then from there create my game as subclasses of that subclass. This doesn't seem to work, bringing up and error "cannot find symbol - constructor subWorld(int, int, int)" when I attempt to specify the size of the world which I want to create, is there any way around this and also do you have any advice on how I could approach the situation differently? Thanks in advance.
nccb nccb

2012/4/10

#
What you want should work fine, it's just an issue with constructors. You need to make sure that your middle class has a constructor that passes the size to the World constructor, and then get the sub-class to call it. So e.g.
class MySubClass extends World
{
    MySubClass(int width, int height, int cellSize)
    {
        super(width, height, cellSize);
    }
}

class SpecificWorld extends MySubClass
{
    SpecificWorld()
    {
        super(640, 480, 1);
    }
}
Does that make sense?
Dingram Dingram

2012/4/10

#
Excellent, thank you very much!
You need to login to post a reply.