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

public class ScreenClickHandler : MonoBehaviour {
    public enum ScreenState
    {
        LOAD,
        TITLE,
        MAIN,
        PLAY,
        END,
        RESET
    }

    public ScreenState screenState = ScreenState.LOAD;

    private void Awake()
    {
        Observer.gameLoadedHandler += OnGameLoaded;
        Observer.gameOverHandler += OnGameOver;
    }

    void OnGameLoaded()
    {
        this.screenState = ScreenState.TITLE;
    }

    void OnGameOver()
    {
        this.screenState = ScreenState.END;
    }

    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            switch (screenState)
            {
                case ScreenState.TITLE:
                    Observer.OnGameTitleExited();
                    this.screenState = ScreenState.MAIN;
                    break;
                case ScreenState.MAIN:
                    Observer.OnGameInitiated();
                    this.screenState = ScreenState.PLAY;
                    break;
                case ScreenState.PLAY:
                    break;
                case ScreenState.END:
                    Observer.OnGameReset();
                    this.screenState = ScreenState.RESET;
                    break;
            }
        }
        if (Input.GetMouseButtonUp(0))
        {
            if (screenState == ScreenState.PLAY)
                Observer.OnMouseUp();
        }
    }
}
