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

2012/12/11

Removing all objects

1
2
danpost danpost

2012/12/12

#
My suggestion is this: if the Camel wins, remove the Alligator object and change the Camel's image; and if the Alligator wins, remove the Camel object and change the Alligator's image. This way, the frog count will only be zero if the Alligator wins. You should not have to remove the Frog objects if the Camel wins, unless there is something I am not aware of in your scenario.
vonmeth vonmeth

2012/12/12

#
        if(getWorld().getObjects(Frog.class).isEmpty()) // end game  
        {   
            setImage(new GreenfootImage("player1.jpg"));  
          setLocation(425, 275);  
          //GreenfootImage img = getImage();  
           img.scale(850,550);  
            Greenfoot.stop();  
        }  
That shouldn't be in your Frog class. After each "getWorld().removeObject(this);", you should have on the next line, "return;" so that rest of the act method doesn't execute. Else, you are going to be getting that error that is coming up (in certain cases.)
bbwf bbwf

2012/12/13

#
How would you add in the return?
bbwf bbwf

2012/12/13

#
danpost wrote...
My suggestion is this: if the Camel wins, remove the Alligator object and change the Camel's image; and if the Alligator wins, remove the Camel object and change the Alligator's image. This way, the frog count will only be zero if the Alligator wins. You should not have to remove the Frog objects if the Camel wins, unless there is something I am not aware of in your scenario.
I'm confused about how I would do this. Sorry.
bbwf bbwf

2012/12/13

#
Sorry for the problems here, just confused.
bbwf bbwf

2012/12/14

#
Anyone please?
danpost danpost

2012/12/14

#
'return;' is just a statement that causes an immediate exit from the method that is currently executing. Placing it in your code prevents later statements in the method from executing.
You need to login to post a reply.
1
2