using Darkmatter.Core;
using System;
using UnityEngine;

namespace Darkmatter.Core
{
    public class ScoreService : IScoreService
    {
        public event Action<int> OnScoreChange;
        public int score { get; private set; }

        public int highScore { get; private set; } = PlayerPrefs.GetInt("HighScore");

        public void AddScore()
        {
            score += 5;
            if (score > highScore)
            {
                SetNewHighScore();
            }
            OnScoreChange?.Invoke(score);
        }

        private void SetNewHighScore()
        {
            highScore = score;
            PlayerPrefs.SetInt("HighScore", highScore);
            PlayerPrefs.Save();
        }
    }
}


