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

public class GameWinCheckerScript : MonoBehaviour {

	[HideInInspector] public float timer;
	public float endTime = 300.0f;
	public float delay = 25.0f;
	public SignalReceiveScript[] endPoints;
	private GameLogicScript _gl;

	public ClockScript _clock;
	private PlayerMovementScript _player;
	private bool initiated = false;


	void Start () {
		_gl = GameObject.FindGameObjectWithTag ("GameController").GetComponent<GameLogicScript> ();
		_player = GameObject.FindGameObjectWithTag ("Player").GetComponent<PlayerMovementScript> ();
		_player.active = false;
		_clock.enabled = false;
	}

	void Update () {
		timer += Time.deltaTime;

		if (timer >= delay && !initiated) {
			_player.active = true;
			_clock.enabled = true;
			initiated = true;
		}
		
		foreach (SignalReceiveScript endPoint in endPoints) {
			if (endPoint.requiredSignalIndex == endPoint._socket.signalReceivedSocket) {
				//do nothing
			} else {
				break;
			}

			Debug.Log ("You Win");
			_gl.Win ();
		}

		if (timer >= endTime + delay) {
			Debug.Log ("You Lose");
			_gl.Lose ();
		}
	}
}
