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

public class ScoreManager : MonoBehaviour {
    
    public Text m_p1Score;
    public Text m_p2Score;
    public Text m_p3Score;
    public Text m_p4Score;

    public GameManager m_gameManager;

    // Use this for initialization
    void Start () {

        m_p1Score.text = "Player 1";
        m_p2Score.text = "Player 2";
        m_p3Score.text = "Player 3";
        m_p4Score.text = "Player 4";
    }
	
	// Update is called once per frame
	void Update ()
    {
        int scoreP1 = m_gameManager.AskForPlayerScore(0);
        int scoreP2 = m_gameManager.AskForPlayerScore(1);
        int scoreP3 = m_gameManager.AskForPlayerScore(2);
        int scoreP4 = m_gameManager.AskForPlayerScore(3);
        
        m_p1Score.text = "Player 1: " + scoreP1.ToString();
        m_p2Score.text = "Player 2: " + scoreP2.ToString();
        m_p3Score.text = "Player 3: " + scoreP3.ToString();
        m_p4Score.text = "Player 4: " + scoreP4.ToString();

        if(scoreP1 >= 40 || scoreP2 >= 40 || scoreP3 >= 40 || scoreP4 >= 40)
        {
            //End Game
            m_gameManager.GlobalGameEnd = true;

            if(scoreP1 >= 40)
                m_gameManager.ShowVictoryPanel(0);
            else if(scoreP2 >= 40)
                m_gameManager.ShowVictoryPanel(1);
            else if(scoreP3 >= 40)
                m_gameManager.ShowVictoryPanel(2);
            else if(scoreP4 >= 40)
                m_gameManager.ShowVictoryPanel(3);

        }
    }
}
