using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class CookieMover : MonoBehaviour {
    public float score;
    public Slider sogginessSlider;
    public bool inMilk, hangTen, twoFingerTrick, brokeGlass, tooSoggy;
    public Text scoreText, fingerText, scoreOutputText;
    public int numberOfFingers = 3;
    public const string soggyText = "Too Soggy! Game Over!";
    public const string hangTenText = "Hang Ten +10";
    public const string twoFingerText = "Two Finger Trick +20";
    public const string brokenGlassText = "Broke Glass -10";
	// Use this for initialization
	void Start () {
        inMilk = false;
        hangTen = false;
        twoFingerTrick = false;
        brokeGlass = false;
        tooSoggy = false;
        numberOfFingers = 3;
        fingerText.text = "3";
	}
	
	// Update is called once per frame
	void Update () {
	    if (Input.GetKeyDown(KeyCode.UpArrow)) {
            transform.Translate(-Vector3.forward);
        }
        if (Input.GetKeyDown(KeyCode.DownArrow)) {
            transform.Translate(Vector3.forward);
        }
        if (Input.GetKeyDown(KeyCode.RightArrow)) {
            if (numberOfFingers < 20) {
                numberOfFingers++;
                fingerText.text = numberOfFingers.ToString();
            }
        }
        if (Input.GetKeyDown(KeyCode.LeftArrow)) {
            if (numberOfFingers > 0) {
                numberOfFingers--;
                fingerText.text = numberOfFingers.ToString();
            }
        }
        if (inMilk) {
            sogginessSlider.value+= 1;
            score += sogginessSlider.value;
            if (sogginessSlider.value == sogginessSlider.maxValue) {
                tooSoggy = true;
            }
        }
        if (tooSoggy) {
            scoreOutputText.text = soggyText;
            score = 0;
        }
        scoreText.text = score.ToString();
	}

    void OnTriggerEnter(Collider collider) {
        Debug.Log(collider.name);
        if (collider.name == "MilkGlass") {
            Debug.Log("Inside Milk");
            inMilk = true;
            if (numberOfFingers == 2) {
                twoFingerTrick = true;
                scoreOutputText.text = twoFingerText;
                score += 20;
            }
            if (numberOfFingers == 10) {
                hangTen = true;
                scoreOutputText.text = hangTenText;
                score += 10;
            }
        }
        else if (collider.name == "ScoreArea") {
            Debug.Log("Inside Score Area");
            Score();
        }
    }
    void OnTriggerExit(Collider collider) {
        if (collider.name == "MilkGlass") {
            Debug.Log("Left Milk");
            inMilk = false;
        }
    }

    void Score() {
        scoreText.text = sogginessSlider.value.ToString();
    }
    public void ResetLevel() {
        //Application.LoadLevel(1);
        UnityEngine.SceneManagement.SceneManager.LoadScene(0);
    }
}
