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

2017/11/6

I cant get my world to generate

Gühnter Gühnter

2017/11/6

#
public class Brett extends World
{
    public Brett()
    {
        super(8, 8, 60); 
        figurenSetzen();
    }

    public void figurenSetzen()
    {
        for(int i=0;i<8;i++)
        {
            int x = Greenfoot.getRandomNumber(7)+1;
            int y = Greenfoot.getRandomNumber(7)+1;
            if(getObjectsAt(x, y, null).isEmpty())
            {
                addObject(new Bauer(), x, y);
            }            
            else
            {
                i--;
            }
        }
        for(int i=0;i<1;i++)
        {
            int x = Greenfoot.getRandomNumber(7)+1;
            int y = Greenfoot.getRandomNumber(7)+1;
            if(getObjectsAt(x, y, null).isEmpty())
            {
                addObject( new Turm(), x, y);
            }
            else
            {
                i--;
            }
        }
    }
}
Here is the code.
danpost danpost

2017/11/7

#
Try using 'Actor.class' instead of 'null' on lines 15 and 28. If still no go, show Turm and Bauer classes.
Super_Hippo Super_Hippo

2017/11/7

#
Adding the import greenfoot and empty Bauer and Turm classes, the program runs fine and places green feet randomly across the scenario. So you can keep the 'null' there. Make sure the Bauer and Turm classes have an image and the Brett is the active world.
You need to login to post a reply.