Just add the line into the 'loadCrate' method. The sound file, 'load crate.wav', must be in the 'Sounds' folder of the project's folder.
if (canMove())
{
getWorld().removeObject(platform.getSchip());
setPlatfom(null);
}// add these instance fields
private Actor[] ships = { new Schipgroen(), new Schipgeel(), new Schipzwart(), new Schiporanje(), new Schippaars(), new Schiprood() };
private int shipsRemaining = 6;
// and add this method
private void spawnRandomSchip()
{
int shipNum = Greenfoot.getRandomNumber(shipsRemaining);
addObject(ships[shipNum], 654, 96);
ships[shipNum] = ships[shipsRemaining-1];
shipsRemaining--;
}
// and add this act method
public void act()
{
if (getObjects(Schip.class).isEmpty())
{
if (shipsRemaining == 0) Greenfoot.stop();
else spawnRandomSchip();
}
}private Actor timeText = new Actor(){};timeText.setImage(new GreenfootImage("Time: 0", 16, java.awt.Color.black, null));
addObject(timeText, 100, 50);private int gameTime;
private int timeDelay;
private Actor timeText = new Actor(){};
timeText.setImage(new GreenfootImage("Time: 0", 16, java.awt.Color.black, null));
addObject(timeText, 100, 50);runTimer();
private void runTimer()
{
// rest of code
}private void runTimer()
{
int timeDelay = +1;
if (timeDelay >= 50)
{
timeDelay == 0;
}
int gameTime;
timeText.setImage(new GreenfootImage("Time: "+gameTime, 16, java.awt.Color.black, null));
if (gameTime == 60)
{
Greenfoot.stop();
Greenfoot.playSound("game over.wav");
}
}
private void runTimer()
{
int timeDelay = timeDelay++;
if (timeDelay = 50)
{
timeDelay = 0;
}
int gameTime = gameTime = 60;
timeText.setImage(new GreenfootImage("Time: "+gameTime, 16, java.awt.Color.black, null));
if (gameTime == 60)
{
Greenfoot.stop();
Greenfoot.playSound("game over.wav");
}
}private int timeDelay;
private int gameTime = 60;
private void runTimer()
{
timeDelay++;
if (timeDelay == 50)
{
timeDelay = 0;
gameTime--;
timeText.setImage(new GreenfootImage("Time: "+gameTime, 16, java.awt.Color.black, null));
}
if (gameTime == 0)
{
Greenfoot.playSound("game over.wav");
Greenfoot.stop();
}
}timeText.setImage(new GreenfootImage("Time: 60", 16, java.awt.Color.black, null));
addObject(timeText, 30, 80);