When then new world starts, the sound file won't stop playing. Is There a way to fix it? Here is my coding....
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Crab2 here. * * @author (your name) * @version (a version number or a date) */ public class Crab2 extends Animal { /** * Act - do whatever the Crab2 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(4); checkKeys(); tryToEat(); } /** * Check if keys are being pressed. Press left turn left. * Press right turn right. */ public void checkKeys() { if (Greenfoot.isKeyDown("left")) { turn(-5); } if (Greenfoot.isKeyDown("right")) { turn(5); } } public void tryToEat() { if (canSee(Lettuce.class)) { eat(Lettuce.class); Greenfoot.playSound("slurp.wav"); createNewLobster2(); createNewLobster2(); createNewLobster2(); createNewWorm(); createNewWorm(); createNewWorm(); createNewWorm(); createNewWorm(); createNewWorm(); createNewWorm(); createNewWorm(); createNewWorm(); } if (canSee(Worm.class)); { eat(Worm.class); Greenfoot.playSound("slurp.wav"); } } public void tryToEatWorm() { if (canSee(Worm.class)); { eat(Worm.class); Greenfoot.playSound("slurp.wav"); } } /** * Create a new lobster2 and place it randomly */ private void createNewLobster2() { Lobster2 newLobster2; newLobster2 = new Lobster2(); World world; world = getWorld(); int worldWidth = world.getWidth(); int worldHeight =world.getHeight(); int x = Greenfoot.getRandomNumber(worldWidth); int y = Greenfoot.getRandomNumber(worldHeight); world.addObject(newLobster2, x, y); } /** * Create a new lobster2 and place it randomly */ private void createNewWorm() { Worm newWorm; newWorm = new Worm(); World world; world = getWorld(); int worldWidth = world.getWidth(); int worldHeight =world.getHeight(); int x = Greenfoot.getRandomNumber(worldWidth); int y = Greenfoot.getRandomNumber(worldHeight); world.addObject(newWorm, x, y); } }