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

public class ScoreManager : MonoBehaviour {

	//Score
	int score = 0;
	int multiplier = 1;
	int multiplierTimerMax = 240;
	int multiplierTimer = 0;

	//GuiTexts
	public GUIText scoreText;
	public GUIText multiplierText;

	//Color Array
	Color[] colorArray = {Color.red, Color.yellow, Color.blue, Color.green, Color.cyan, Color.magenta, Color.white};

	//Points for each enemy
	Dictionary<string, int> pointsPer = new Dictionary<string, int>();

	// Use this for initialization
	void Start () {
		//Set the points for killing each enemy
		pointsPer.Add ("SquareEnemy(Clone)", 50);
		pointsPer.Add ("CircleEnemy(Clone)", 30);
		pointsPer.Add ("TriangleEnemy(Clone)", 40);
	}
	
	// Update is called once per frame
	void Update () {

		//Handle the multiplier
		multiplierTimer --;
		if(multiplierTimer == 0){
			multiplier = 1;
		}

		//Color the multiplier
		multiplierText.color = colorArray[Random.Range (0, colorArray.Length)];

		//Display the score.
		scoreText.text = "Score: " + score;

		//Display the multiplier
		if(multiplier > 1){
			multiplierText.text = "X" + multiplier;
		}
		else{
			multiplierText.text = "";
		}

	}

	public void killedEnemy(string enemyName){
		addPoints (pointsPer[enemyName]);
	}

	public void addPoints(int amount){
		score += amount * multiplier;
		multiplierTimer = multiplierTimerMax;//reset the multiplier
		multiplier ++;
	}

	public int getScore(){
		return score;
	}
}
