using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StatsManager : MonoBehaviour
{
    public int[] kills;
    public int numberOfKillsToWin = 5;

    public void Start()
    {
        kills = new int[4];
    }

    public void AddKill(int playerNumber)
    {
		Debug.Log("AddKIll: " + playerNumber);
				    	
        kills[playerNumber]++;

        foreach(int k in kills)
        {
            if(kills[playerNumber] >= numberOfKillsToWin)
            {
                WinGame(playerNumber);
            }
        }
    }

    void WinGame(int playerNumber)
    {
        FindObjectOfType<PlayerWinstate>().winningPlayer = playerNumber;
        FindObjectOfType<SceneController>().FadeAndLoadScene("WinScene");
    }

    private void Update()
    {
        if(Input.GetKeyDown("1"))
        {
            WinGame(1);
        }

        else if (Input.GetKeyDown("2"))
        {
            WinGame(2);
        }

        else if (Input.GetKeyDown("3"))
        {
            WinGame(3);
        }

        else if (Input.GetKeyDown("4"))
        {
            WinGame(4);
        }
    }
}
