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...
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);
2013/3/17
2013/3/17
2013/3/17
2013/3/17
2013/3/17