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

2013/1/10

Really need help with multilevels

Rockermaster Rockermaster

2013/1/10

#
Hey, so i have this two methods in my enemy actor public void gone() { score (); getWorld().removeObject(this); } public void score() { level1 o= (level1)getWorld(); o.AddPoint(1); } And AddPoint is one method in the first level my question is how can i add score in my second level by killing the same enemy
Rockermaster Rockermaster

2013/1/10

#
i know i might have to change the method score() but i dont have any ideas right now.
danpost danpost

2013/1/10

#
If you show the 'AddPoint' method in your world class, someone may be able to show you how to code it from an actor class.
davmac davmac

2013/1/10

#
First: class names should begin with a capital, and method names shouldn't. So, it should be "Level1" not "level1", and "addPoint" not "AddPoint". You want to be able to call addPoint regardless of whether the world is a Level1 or Level2, right? The easiest way is to make a new world class called eg ScoreWorld. You put the addPoint method in ScoreWorld, and you make Level1 and Level2 be subclasses of ScoreWorld. i.e. in Level1, where it says: public class Level1 extends World Change it to: public class Level1 extends ScoreWorld If you like, you can override the addPoint method, having different versions in Level1 and Level2. Change your score() method above to:
public void score()
{
    ScoreWorld o= (ScoreWorld) getWorld();
    o.AddPoint(1);
}
That should do it.
You need to login to post a reply.