using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;


public enum GameState
{
    Menu = 1000,

    Play = 2000,

    Win = 3000,

    Lose = 4000


}
public class GameManager : MonoBehaviour {

    public GameState State { get { return GetState(); } set { SetState(value);  } }
    private GameState state;
    public GameObject menu;
    public GameObject play;
    public GameObject win;
    public GameObject lose;
    public MusicEngine audiomanager;
    public GameObject playerRef;
    //List<GameObject> toDestroy = new List<GameObject>();



    // Use this for initialization
    void Start () {
        menu = GameObject.FindGameObjectWithTag("Canvas_Menu");
        play = GameObject.FindGameObjectWithTag("Canvas_Play");
        win = GameObject.FindGameObjectWithTag("Canvas_Win");
        lose = GameObject.FindGameObjectWithTag("Canvas_Lose");
        playerRef = GameObject.FindGameObjectWithTag("Player");
        //State = GameState.Menu;
        State = GameState.Play;
        audiomanager.MusicStart("song1");
    }
	
	// Update is called once per frame
	void Update () {
        if (Input.GetKeyDown(KeyCode.Escape)) {
            if (State == GameState.Play) {
                OnLose();
            }
        }
        if (State == GameState.Win)
        {
            playerRef.transform.position = new Vector3(0.186f, 3.3f, -4);
            //playerRef.transform.rotation = Quaternion.Euler(Vector3.forward);
        }
    }
    public void OnMenu()
    {
        State = GameState.Menu;
    }

    public void OnPlay()
    {
        State = GameState.Play;
        playerRef.transform.position = new Vector3(0.3f, 5, 80);
        //toDestroy = GameObject.FindGameObjectsWithTag("Obstacle").ToList();
        //toDestroy.AddRange(GameObject.FindGameObjectsWithTag("Bass").ToList());
    }

    public void OnWin()
    {
        State = GameState.Win;
        
    }

    public void OnLose()
    {
        State = GameState.Lose;
    }
    public void OnExit()
    {
        Application.Quit();
    }

    private GameState GetState()
    {
        return state;
    }



    private void SetState(GameState value)
    {
        state = value;

        switch(state)
        {
            case GameState.Menu:
                menu.SetActive(true);
                play.SetActive(false);
                win.SetActive(false);
                lose.SetActive(false);
                break;

            case GameState.Play:
                menu.SetActive(false);
                play.SetActive(true);
                win.SetActive(false);
                lose.SetActive(false);
                break;

            case GameState.Win:
                menu.SetActive(false);
                play.SetActive(false);
                win.SetActive(true);
                lose.SetActive(false);
                break;

            case GameState.Lose:
                menu.SetActive(false);
                play.SetActive(false);
                win.SetActive(false);
                lose.SetActive(true);
                break;

            default:
                Debug.LogError("SetState() invalid state");
                break;


        }

    }
}
