using System.Collections;
using UnityEngine;

public static class GameManager  
{
	public static int playerLifes = 4;
	public static int playerLifesCap = 4;
	public static int bulletCap = 3;
	public static int enemyPorcentage = 20;
	public static int envirotraps = 10;

	public static int money = 0;
	public static bool doublejump;
	public static bool weaponUpgrade;
	public static int currentLevel = 1;

	private static UIManager _ui;
	public static UIManager UI
	{
		get
		{
			if(_ui == null)
			{
				_ui = GameObject.FindObjectOfType<UIManager> ();
			}
			return _ui;
		}
	}


	public static void IncreaseLife(bool increaseCap, int amount)
	{
		playerLifes += amount;
		if(increaseCap)
		{
			playerLifesCap += amount;
		}
		UI.ChangeHearts ();
	}

	public static void IncreaseBullet(int amount)
	{
		bulletCap += amount;
		UI.ChangeBullets ();
	}


	public static bool IsGameOver ()
	{
		return playerLifes <= 0;
	}

	public static void WonMoney (int enemy, Vector3 pos)
	{
		int rmdMon = 0;
		if(enemy == 0)
		{
			rmdMon = Random.Range (1, 5);
		}
		else
		{
			rmdMon = Random.Range (1, 8);
		}

		money += rmdMon;
		UI.SetScore (pos, rmdMon);
	}

	public static void NextLevelDificult ()
	{
		enemyPorcentage = Random.Range (enemyPorcentage, enemyPorcentage + 15);
		envirotraps += 10;
		currentLevel += 1;
	}

	public static void StartOver ()
	{
		playerLifes = 4;
		playerLifesCap = 4;
		bulletCap = 3;
		enemyPorcentage = 20;
		money = 0;
		currentLevel = 1;
		doublejump = false;
		weaponUpgrade = false;
	}
}
