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

2013/2/18

Little Crab

nitaadiningrum nitaadiningrum

2013/2/18

#
How to make two life for crab and when the lobster eat the crab, game will begin again?
danpost danpost

2013/2/18

#
Add an instance integer field to be a life counter in the world class. Initialize its value to 2. In the world act method (or a method it calls), check to see if Crab is in the world, if not, decrement the life counter and then check its value; if the value is not zero, add the crab back into the world; otherwise start a new instance of the world. You may prefer to add the same Crab object back into the world after the first life is gone because the field holding the number of worms eaten will be zero if you add a NEW Crab object into the world. To accomplish this, add an instance Crab field in the world class, initialized with 'new Crab()'. Initially add it into the world in the world constructor and re-add it into the world when the first life is lost.
You need to login to post a reply.