using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class EndingController : MonoBehaviour {

    public Sprite[] winBackgrounds, loseBackgrounds;
    public Image background;
    public int win;
    private int m_level;

    // Use this for initialization
    void Start () {
        m_level = PlayerPrefs.HasKey("currentLevel") ? PlayerPrefs.GetInt("currentLevel") : 1;
        SoundController.Instance.stopMusic();
        win = PlayerPrefs.HasKey("gameWon") ? PlayerPrefs.GetInt("gameWon") : 1;

        if (win == 1) {
            background.sprite = winBackgrounds[m_level - 1];
        }
        else {
            background.sprite = loseBackgrounds[m_level - 1];
        }
    }
	
    public void mainMenuClicked() {
        SceneManager.LoadScene("menu");
    }

    public void tryAgainAndContinueButton() {
        if(win == 1) {
            if (m_level == 1) {
                PlayerPrefs.SetInt("currentLevel", 2);
                PlayerPrefs.SetInt("moves", 4);
                PlayerPrefs.SetInt("targets", 9);
                SceneManager.LoadScene("level_cover");
            }
            else if (m_level == 2) {
                PlayerPrefs.SetInt("currentLevel", 3);
                PlayerPrefs.SetInt("moves", 6);
                PlayerPrefs.SetInt("targets", 15);
                SceneManager.LoadScene("level_cover");
            }
            else {
               SceneManager.LoadScene("level_menu");
            }
        }
        else {
            SceneManager.LoadScene("level");
        }
    }
}
