﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.IO;
using System;

public class KeypadLock : MonoBehaviour {
    public Text screen;
    public int highLoad;
    public int lowLoad;
    private int tries = 0;

	// Use this for initialization
	void Start () {
    }
	
	// Update is called once per frame
	void Update () {
	
	}
    public void NumberPress(string s)
    {
        screen.text = screen.text + s;
    }
    public void Enter()
    {
        if (PlayerPrefs.GetInt("Load_Condition") == 1 && screen.text == ""+lowLoad)
        {
            WriteData();
        }
        else if (PlayerPrefs.GetInt("Load_Condition") == 2 && screen.text == ""+highLoad)
        {
            WriteData();
        }
        else
        {
            //screen.text = "";
            tries++;
        }
        if(tries >= 5)
        {
            WriteData();
        }
        screen.text = "";
    }
    public void Cancel()
    {
        screen.text = "";
    }
    public void WriteData()
    {
        var form = new WWWForm();
        form.AddField("ID", PlayerPrefs.GetString("ID"));
        form.AddField("tries", tries);
        form.AddField("number_entered", screen.text);
        var download = new WWW("http://surveysensei.uconn.edu/something.php", form);
        print("game over");
        Application.Quit();
    }
}
