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

2015/3/8

When obstacle on the right --> stop. How? xD

enchino enchino

2015/3/8

#
Hello! I'm programming a method, where a spider changes the places of the flies. look at this: http://prntscr.com/6e64gx. First it has to be like the left picture, at the end it has to be like the right one. The code is given and it's programmed for RUN not for ACT. I just need the command for else(obstacleRight()) >.< Normally they are in german, I just translated them into english, so they aren't the correct codes, just the words are translated, hope u still understand. Thanks ahead for help!! :)
public void ChangeThePlacesOfFlies() {
        feedSpider(2);
        if(flyAtPlace())
            {
               eatFly();
               run();
            }
        else if(!flyAtPlace())
            {
                spitOutFly();
                run();
            }
        else if(obstacleRight())
            {
                ?????
            }
            nachrichtenVerbergen();
        }
erdelf erdelf

2015/3/8

#
how about that ?
public void ChangeThePlacesOfFlies() {
        feedSpider(2);
        if(flyAtPlace())
            {
               eatFly();
            }
        else if(!flyAtPlace())
            {
                spitOutFly();
            }
        if(!obstacleRight())
            {
                run();
            }
            nachrichtenVerbergen();
        }
enchino enchino

2015/3/8

#
thanks, works, but at the end it keeps eating and spitting out the fly the whole time xDD
danpost danpost

2015/3/8

#
Would something like this do?
while (!obstacleRight())
{
    if (flyAtPlace())
    {
        eatFly();
        run();
        spitOutFly();
    }
    else
    {
        run();
    }
}
enchino enchino

2015/3/8

#
danpost wrote...
Would something like this do?
while (!obstacleRight())
{
    if (flyAtPlace())
    {
        eatFly();
        run();
        spitOutFly();
    }
    else
    {
        run();
    }
}
nope, it wouldn't be individual, but thanks :))
You need to login to post a reply.