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

public class NaytaPisteet : MonoBehaviour
{
    public TextMeshProUGUI scoreText;
    // Start is called before the first frame update
    void Start()
    {
        scoreText.SetText(Pistehet.pisteet.ToString());
        CheckHighScores();
        LogPoints();
        Pistehet.pisteet = 0;
    }

    void CheckHighScores()
    {
        for (int i = 0; i < Pistehet.highSchores.Length; i++)
        {
            if(Pistehet.pisteet > Pistehet.highSchores[i])
            {
                
                MovePoints(i);
                Pistehet.highSchores[i] = Pistehet.pisteet;
                break;
            }
        }
    }

    void MovePoints(int index)
    {
        for(int i = index; i < Pistehet.highSchores.Length-1; i++)
        {
            Pistehet.highSchores[i + 1] = Pistehet.highSchores[i];
        }
    }

    void LogPoints()
    {
        foreach(var piste in Pistehet.highSchores)
        {
            Debug.Log(piste);
        }
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
