Hey~ I'm very new to coding, and my scenario is pretty simple, just a polar bear moving around trying to eat dolphins, but when I tried to make another dolphin appear when the last one's eaten, the error kept popping out and I don't know how to fix it...
My Dolphin code's this:
Thanks a lot!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class ToothedWhale extends Animal { public void act() { doWhatever(); WorldEdge(); duplicateDolphin(); } World world= getWorld(); public void doWhatever() { turn( Greenfoot.getRandomNumber( 10 )- 5 ); move( 5 ); } public void WorldEdge() { if (atWorldEdge()) { turn( 30 ); } } public void duplicateDolphin() { if (world.getObjects(ToothedWhale. class ).isEmpty()) { ToothedWhale toothedwhale = new ToothedWhale(); world.addObject( toothedwhale , 1 , 1 ); } } } |