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

Report as inappropriate.

Mamang_Superhero presents ...


Catch That Egg (DEMO)

No description.

1350 views / 4 in the last 7 days

1 vote | 0 in the last 7 days

Tags: with-source

open in greenfoot
Your browser does not support the canvas tag.
can someone help me with the code? the code so that if an egg is eaten or destroyed it will spawn a new egg? I have published the code so, please help me! Vote, Comment, Follow... I am open for your suggestions...
and the counter code too.. please, Help is very much appreciated....


To add a new egg, add the following line in your world act method: if (getObjects(Egg.class).isEmpty()) spawnEgg(); where 'spawnEgg' can be a method you create to add the new egg into the world or you can replace it with the code block that adds the new egg.


I took a look at the code and see you already have methods to add the eggs. Still, you should be able to work it from what I gave above. Couple things about code: Greenfoot.getRandomNumber(2) will always return a value less than 2 (or any number greater than 2); so the checks in your egg spawning methods are always true. NewGame should probably not extend the Animal class and should remove itself when space is pressed (code to remove it should not be in Chicken class). Add the counter object from the world constructor. In the Chicken class, when eating an egg (or Sugok), use something like the following to increase the counter: ((Counter2)getWorld().getObjects(Counter2.class).get(0)).bumpCount(5);
thanks sir danpost, it really helps me out a lot...

Want to leave a comment? You must first log in.

Who likes this?