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. I am running the crab program from the Introduction to Programming with Greenfoot. I am trying to make it where when the lobster eats the crab, it plays the "slurp" file then plays the "fanfare" file. 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 supposed to make the loop terminate after 1000000000 executions. Can anybody please help. The way I have it now, the sound loops really fast and freezes up the scenario. Here is the code.
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
/**
* A lobster. Lobsters live on the beach. They like to eat crabs. (Well, in our game
* they do...)
*
* Version: 2
*
* The lobster walks around randomly. If it runs into a crab it eats it.
* In this version, we have added a sound effect, and the game stops when
* a lobster eats the crab.
*/
public class Lobster extends Animal
{
/**
* Do whatever lobsters do.
*/
public void act()
{
turnAtEdge();
randomTurn();
move();
lookForCrab();
}
/**
* Check whether we are at the edge of the world. If we are, turn a bit.
* If not, do nothing.
*/
public void turnAtEdge()
{
if ( atWorldEdge() )
{
turn(17);
}
}
/**
* Randomly decide to turn from the current direction, or not. If we turn
* turn a bit left or right by a random degree.
*/
public void randomTurn()
{
if(Greenfoot.getRandomNumber(100) > 90) {
turn(Greenfoot.getRandomNumber(90)-45);
}
}
/**
* Try to pinch a crab. That is: check whether we have stumbled upon a crab.
* If we have, remove the crab from the game, and stop the program running.
*/
public void lookForCrab()
{
if (canSee(Crab.class) )
{
eat (Crab.class);
Greenfoot.playSound ("slurp.wav");
int i = 0;
while ( i < 1000000000 )
{
Greenfoot.playSound ("fanfare.wav");
Greenfoot.stop();
i = i + 1;
}
}
}
}

