using UnityEngine;
using System.Collections;

public enum GameState { NotStarted,win,running, loss };
public class Player : MonoBehaviour {
    public static Player ActivePlayer;
    public Transform beginPos;
    bool win;
    bool loss;
    public float BeginScore = 3;

    float score;
    mv mv;
    public GameState st;
    public float time;
    public float Score
    {
        get
        {
            return score;
        }

        set
        {
            score = value;
            if(score <= 0)
            {
                score = 0;
                st = GameState.loss;
            }
        }
    }

    // Use this for initialization
    void Start () {
        mv = GetComponent<mv>();
        ActivePlayer = this;
	}
	
	// Update is called once per frame
	void Update () {
        switch (st)
        {
            case GameState.win:
                Win();
                break;
            case GameState.running:
                Running();
                break;
            case GameState.loss:
                lost();
                break;
            default:
                break;
        }
    }
    void Running()
    {
        if(mv !=null)
             mv.UpdateSt();
        time += Time.deltaTime;
    }

    public void Damage(float am)
    {
        if (am <= 0) return;
        Score -= am;

    }
    public void AddScore(float am)
    {
        if (am <= 0) return;
         Score += am;

    }
    void FirstTimeWin()
    {
        if (!win) return;
        win = true;


    }
    void FirstTimeLoss()
    {
        if (!loss) return;
        loss = true;




    }


    void Win()
    {
        FirstTimeWin();


    }
    void lost()
    {
        FirstTimeLoss();


    }

    public void Begin()
    {
        if (st == GameState.running)
            return;
        BeginAgain();
    }
    public void BeginAgain()
    {
        st = GameState.running;
        score = BeginScore;
        win = false;
        loss = false;
        transform.position = beginPos.position;
    }
	void OnControllerColliderHit(ControllerColliderHit col)
	{
		print (col.gameObject.name);
	}



}
