This site requires JavaScript, please enable it in your browser!
Greenfoot back
bian2205
bian2205 wrote ...

2016/9/22

The two sound problem. Help please

bian2205 bian2205

2016/9/22

#
I have a problem. I have 2 mouses(both are the same mouse(class)) and 1 elephant. if the elephant eats the first mouse, turns the elephant, eats the mouse and play a sound on 50 volume. And my problem is that i can't get the sound 100% if he eats the second mouse. (Both sounds are the same mp3). can some one please help me.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import greenfoot.GreenfootSound.*;
/**
 * Write a description of class Elephant3 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Elephant3 extends Animal
{
    int sound = 50;
    /**
     * Act - do whatever the Elephant3 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    /**
     * Act - do whatever the elephant2 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
       	 if (atWorldEdge() )
        {
            turn(17);
        }
        randomTurn();
        move();
        LookforMouse();
    }


	public void randomTurn()
	{
        if (Greenfoot.getRandomNumber(145) <13 )
        {
            turn(5);
        }
    
        if (Greenfoot.getRandomNumber(100) <10 )
        {
            turn(-15);
        }
    }
    
    public void LookforMouse()
    {
        if ( canSee (Mouse.class) )
        {
            eat(Mouse.class);
            turn(180);
            GreenfootSound gfs = new GreenfootSound("Rick.mp3");
			gfs.setVolume(sound);
			gfs.play();
			sound =+ 50;
			
        }
    }
}
Super_Hippo Super_Hippo

2016/9/22

#
Change line 54 to either
sound += 50;
or just
sound = 100;
bian2205 bian2205

2016/9/29

#
Thanks
You need to login to post a reply.