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

2019/6/17

Random World to be Spawned under a subclass that has 10 worlds in them when pressed a button

HydraLord257 HydraLord257

2019/6/17

#
Hi I do not know how to spawn a random world from a subclass that has 10 worlds. Can u help me how to do it??Image
danpost danpost

2019/6/17

#
HydraLord257 wrote...
Hi I do not know how to spawn a random world from a subclass that has 10 worlds. Can u help me how to do it?? << Image Omitted >>
You cannot share a picture directly from your system. You must upload it to a website and then share its url from there. You will need to provide more details about how your worlds are set up. Although, I suspect something like the following may be needed:
World world = null;
switch (Greenfoot.getRandomNumber(10))
{
    case 0: world = new WorldA(); break;
    case 1: world = new WorldB(); break;
    ...
    case 9: world = new WorldJ(); break;
}
Greenfoot.setWorld(world);
HydraLord257 HydraLord257

2019/6/17

#
My game basically is that I am trying to once a button is pressed, a random world will appear from the subclass "Questions", inside them has 10 questions "Q1, Q2, Q3........" worlds that are coded to act as questions. I am stuck on basically once a button is pressed from an actor, it will generate a random world from the world subclass "Questions" which inside has Q1 - Q10 that are coded.
danpost danpost

2019/6/17

#
HydraLord257 wrote...
My game basically is that I am trying to once a button is pressed, a random world will appear from the subclass "Questions", inside them has 10 questions "Q1, Q2, Q3........" worlds that are coded to act as questions. I am stuck on basically once a button is pressed from an actor, it will generate a random world from the world subclass "Questions" which inside has Q1 - Q10 that are coded.
So, use in button class act method:
if (Greenfoot.mouseClicked(this))
{
    // code above (replace WorldA thru WorldJ with Q1 thru Q10)
}
HydraLord257 HydraLord257

2019/6/17

#
Oh it worked many thanks :) p.s. might still ask plenty of questions tho cus I ain't good at programming :|
You need to login to post a reply.