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

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

    private Player _player;

	void Start ()
	{
	    _player = GameObject.FindWithTag("Player").GetComponent<Player>();
	    HighScore.enabled = false;
	    Vial1.enabled = false;
	    Vial2.enabled = false;
	    Vial3.enabled = false;
	}
	
	void Update ()
	{
	    Distance.text = (int.Parse(Distance.text) + 1).ToString();
	    int score = _player.Score + int.Parse(Distance.text) / 5;
	    Score.text = (_player.Score + score).ToString();

	    NbVials.text = _player.NbVials.ToString();

	    DisplayBattery();
	}

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