using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class GameManager : MonoBehaviour
{
    public Mole[] moles;
    public float spawnInterval = 1.5f;
    public float gameDuration = 30f;
    public TextMeshProUGUI scoreText;
    public TextMeshProUGUI timerText;

    private int score = 0;
    private float timeLeft;

    void Start()
    {
        timeLeft = gameDuration;
        InvokeRepeating(nameof(SpawnMole), 1f, spawnInterval);
    }

    void Update()
    {
        timeLeft -= Time.deltaTime;
        timerText.text = "Time: " + Mathf.CeilToInt(timeLeft);

        if (timeLeft <= 0f)
        {
            CancelInvoke(nameof(SpawnMole));
            timerText.text = "Time: 0";
        }
    }

    void SpawnMole()
    {
        if (moles.Length == 0) return;

        int index = Random.Range(0, moles.Length);
        moles[index].Show();
    }

    public void AddScore(int points)
    {
        score += points;
        scoreText.text = "Score: " + score;
    }
}
