import java.applet.Applet;
import java.applet.AudioClip;
public class Sound {
public static final int ROTATE = 0, MOVE = 1, SETDOWN = 2, ADDLINES = 3, REMOVELINES = 4,
FULL = 5, LAUGHTER = 6, CHEER = 7;
private AudioClip[] audioClip = new AudioClip[8];
private boolean soundsOK, playSound = true;
public Sound()
{
try
{
audioClip[0] = Applet.newAudioClip(getClass().getResource(
"res/moveX.wav"));
audioClip[1] = Applet.newAudioClip(getClass().getResource(
"res/moveX.wav"));
audioClip[2] = Applet.newAudioClip(getClass().getResource(
"res/downX.wav"));
audioClip[3] = Applet.newAudioClip(getClass().getResource(
"res/addX.wav"));
audioClip[4] = Applet.newAudioClip(getClass().getResource(
"res/removeX.wav"));
audioClip[5] = Applet.newAudioClip(getClass().getResource(
"res/tetrisX.wav"));
audioClip[6] = Applet.newAudioClip(getClass().getResource(
"res/roflX.au"));
audioClip[7] = Applet.newAudioClip(getClass().getResource(
"res/cheer.wav"));
soundsOK = true;
}
catch (Exception e)
{
soundsOK = false;
System.out.println("SoundLoading Error, Sound disabled");
}
}
public void playSound(final int sound)
{
if(playSound)
{
if(soundsOK && sound >=0 && sound < audioClip.length && sound != MOVE )
{
new Thread( new Runnable()
{public void run()
{
audioClip[sound].play();
}
}).start();
}
}
}
public boolean isPlaySound()
{
return playSound;
}
public void setPlaySound(boolean playSound)
{
this.playSound = playSound;
}
public static void main(String[] args) throws InterruptedException
{
Sound s = new Sound();
s.playSound(7);
try { Thread.sleep(10000); }catch(InterruptedException e) {}
}
}