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

import javax.swing.*;
import java.awt.event.*;


import WheelOfFortune.game.GameModel;

/**
 * @author caih
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class DecisionAction extends AbstractAction{

	private GameModel gm;
	private GameInput gi;
	/**
	 * @param arg0
	 */
	public DecisionAction(String name, GameModel gm, GameInput gi) {
		this.gm = gm;
		this.gi = gi;
		this.putValue(Action.NAME, name);
		this.putValue(Action.SHORT_DESCRIPTION, name);
	}
	
	
	public DecisionAction (String name, String descrip, GameModel gm, GameInput gi)
	{
		this.gm = gm;
		this.gi = gi;
		this.putValue(Action.NAME, name);
		this.putValue(Action.SHORT_DESCRIPTION, descrip);
	}
	/**
	 * @param arg0
	 * @param arg1
	 */
	public DecisionAction(String name, ImageIcon ic, String desc, GameModel gm, GameInput gi) {
		this.gm = gm;
		this.gi = gi;
		this.putValue(Action.NAME, name);
		this.putValue(Action.SMALL_ICON, ic);
		this.putValue(Action.SHORT_DESCRIPTION, desc);
	}

	public void actionPerformed(ActionEvent e)
	{
		String name = (String)getValue(Action.NAME);
		ImageIcon ic = (ImageIcon)getValue(Action.SMALL_ICON);
		String answer;
		if(name.equalsIgnoreCase(GameInput.SPIN))
		{
			gi.disableActions();
			Runnable r = new Runnable() {
				public void run() {
					gm.spinWheel();
				}
			};
			new Thread(r).start();
		}
		else if(name.equalsIgnoreCase(GameInput.BUY))
		{
			gi.disableActions();
			gm.buyVowel();
		}
		else if(name.equalsIgnoreCase(GameInput.SOLVE))
		{
			answer = (String)JOptionPane.showInputDialog(null, 
					"Enter your answer","Solve Puzzle",
					JOptionPane.QUESTION_MESSAGE);
			if(answer == null || answer.equalsIgnoreCase(""))
				return;
			else
			{
				gi.disableActions();
				gm.guessSolution(answer);
			}
		}
		else if(ic == gi.play)
		{
			gi.music.play();
		}
		else if(ic == gi.stop)
		{
			gi.music.stopPlay();
		}
		else
		{
			gi.music.next();
		}
		
	}

}
