![]() ![]() These methods include, but are not limited to, 'getX()', getObjectAtOffset(int, int, Class)', 'getIntersectingObjects(Class)', 'getNeighbours(int, boolean, Class)', and 'move(int)'.Īlso, a NullPointerException will occur if you use 'getWorld().someWorldClassMethod()' if the actor has not been added or has been removed from the world. Make sure that you call any methods of the actor, while it's in the world, or make sure that removing the Actor is the last thing that happens (ex: removing the actor and then telling the actor to move, changed to telling the actor to move (or not at all) then removing the actor).To be more to the point: An IllegalStateException error will occur if you try to use a method that require the actor to be in the world when, in fact, the actor is not in the world (either has not yet been added or has been removed from the world). If (Greenfoot.getRandomNumber(100) 6) // R4įlyingRabidUnicornPig wrote.Your error happens when you haven't added the Actor to the world, or if you removed it and continued to do more. WormsEaten= Greenfoot.getRandomNumber(7) +5 //R3 * R7 -The Crabs shall move in a random pattern (without key controls) and eat Worms. * R2 -Automatically populate the world with 3 Crabs randomly placed( using loops). * R1 -Automatically populate the world with 40 Worms randomly placed (using loops). If ( canSee(Worm.class) & wormsEaten 6) // This code satisfies requirement R4 * Check whether we have stumbled upon a worm. * Check whether a control key on the keyboard has been pressed. * Alternate the crab's image between image1 and image2. * the 'Act' or 'Run' button gets pressed in the environment. * Act - do whatever the crab wants to do. WormsEaten= Greenfoot.getRandomNumber(7) +5 //this line satisfies requirement R3. Image2 = new GreenfootImage("crab2.png") * Create a crab and initialize its two images. Private int wormsEaten //BA: this line satisfies requirement R3. * In this version, the crab behaves as before, but we add animation of the * (very yummy, especially the green ones). ![]() * R8 -Stop the game once all the Worms have been eaten or all the Crabs have died. * R6 -Once a Crab has reached zero Worms eaten, it dies and disappears from the world. * R5 -Each time a Crab moves it uses 1/20 of a Worm worth of energy. * R4 -If a Crab has more than 6 worms eaten, it cannot eat any more worms. * R3 -Set the initial worms eaten (on the Crabs) to a random number between 5 and 11. If(Greenfoot.Import greenfoot.* // (World, Actor, GreenfootImage, and Greenfoot) * turn a bit left or right by a random degree. * Randomly decide to turn from the current direction, or not. * Check whether we are at the edge of the world. * In this version, we have added a sound effect, and the game stops when Import greenfoot.* // (World, Actor, GreenfootImage, and Greenfoot) The way I have it now, the sound loops really fast and freezes up the scenario. I am supposed to make the loop terminate after 1000000000 executions. We were instructed to use a while loop between the playing of the sound files, define an integer variable and increment it in the loop. I am trying to make it where when the lobster eats the crab, it plays the "slurp" file then plays the "fanfare" file. I am running the crab program from the Introduction to Programming with Greenfoot. I am new to programming and I am currently trying to insert a while loop between 2 sounds to provide a short delay between them.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |