using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Assets.Scripts;
using Assets.Scripts.Utils;
using UnityEngine.UI;

public class UIController : MonoBehaviour
{
    public Text Distance;
    public Text Score;
    public Text HighScore;
    public Text NbVials;
    public Image Battery;
    public Image Progression;
    public Sprite[] ProgressionSprites;
    public List<Sprite> BatteryImages;

    private Player _player;
    private int _oldHs;

	void Start ()
	{
	    _player = GameObject.FindWithTag("Player").GetComponent<Player>();
	    HighScore.enabled = false;
	    _oldHs = PlayerPrefs.GetInt("highscore");
	}
	
	void Update ()
	{
	    Distance.text = (int.Parse(Distance.text) + 1).ToString();

		_player.Score += Mathf.RoundToInt(
			1f * (GameController.Speed / 4f));
	    Score.text = _player.Score.ToString();
	    NbVials.text = _player.NbVials.ToString();

	    DisplayBattery();
	    HandlePowerUps();
	    HandleScore();
		BackButtonHelper.menuOnBack();
	}

    private void HandleScore()
    {
        if (_oldHs < _player.Score)
            HighScore.enabled = true;
    }

    private void HandlePowerUps()
    {
    }

    private void DisplayBattery()
    {
        Battery.sprite = BatteryImages[_player.Battery/8];
    }
}
