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

public class ConsumeManager : MonoBehaviour {

	#region Private Variables
	private float _score;
	private List <GameObject> _dolls;

	private GameObject _room;
	#endregion


	#region Events
	void Start () {

		_room = GameObject.FindGameObjectWithTag ("Room");
		_dolls = new List <GameObject> ();

	}
	#endregion


	#region Methods
	public void AddScore (GameObject go, int score) {
		
		_dolls.Add (go);
		_score += score;

		if (_dolls.Count == 4 && Mathf.Abs (_score) != 4) {
			
			foreach (GameObject doll in _dolls)
				doll.GetComponent <DollControl> ().Reset ();

			_score = 0;
			_dolls.Clear ();

		} else if (_dolls.Count == 4 && Mathf.Abs (_score) == 4) {

			KillRoom ();

		}
		
	}

	void KillRoom () {

		GameObject.FindObjectOfType <ActiveCamera> ().Reset ();
		Destroy (_room.gameObject);

	}
	#endregion
	
}
