/*
 * Created on Dec 4, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package WheelOfFortune.game.userOutput;

import java.io.File;
import java.io.IOException;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;


/**
 * @author Hua
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class SoundEffects {
	public static final String PATH = ".\\WheelOfFortune\\game\\sound\\";
	
	public void play(String filename)
	{
		{
			File soundFile = new File(filename);
		
			AudioInputStream audioInputStream = null;
			try
			{
				audioInputStream = AudioSystem.getAudioInputStream(soundFile);
			}
			catch (Exception e)
			{
			}

			AudioFormat	audioFormat = audioInputStream.getFormat();
			SourceDataLine line = null;
			DataLine.Info info = new DataLine.Info(SourceDataLine.class,
													 audioFormat);
			try
			{
				line = (SourceDataLine) AudioSystem.getLine(info);
				line.open(audioFormat);
			}
			catch (Exception e)
			{}
			line.start();

			int	nBytesRead = 0;
			byte[]	abData = new byte[128000];
			while (nBytesRead != -1)
			{
				try
				{
					nBytesRead = audioInputStream.read(abData, 0, abData.length);
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
				if (nBytesRead >= 0)
				{
					int	nBytesWritten = line.write(abData, 0, nBytesRead);
				}
			}
			line.drain();
			line.close();
		}
	}	
	public void spinWheel()
	{
		
	}
	public void correctLetter()
	{
		play(PATH + "correctLetter.wav");
		
	}
	public void incorrectLetter()
	{
		wrong();
	}
	public void loseTurn()
	{
		wrong();
	}
	private void wrong()
	{
		play(PATH + "wrong.wav");
	}
	public void winGame()
	{
		play(PATH + "winGame.wav");
	}
	public void loseGame()
	{
		
	}
	public void winRound()
	{
		play(PATH + "winRound.wav");
	}
}
