using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class GameController : MonoBehaviour {

	public float timestamp;
	
	public int life;
	public int score = 0;
	
	public Image life1;
	public Image life2;
	public Image life3;
	
	public Image gameEnd;
	public Image smoke;
	public Image boss;
	public Image replay;
	public Image exit;
	public Text gameOver;
	public Text scoreText;

	// Use this for initialization
	void Start () {
		timestamp = Time.time;
		gameEnd.enabled =false;
		gameOver.enabled = false;
		boss.enabled = false;
		replay.enabled = false;
		exit.enabled = false;
		smoke.enabled = false;
	}
	
	// Update is called once per frame
	void Update () {
		scoreText.text = score + "%";
	}
	
	
	
	void GameOver() {
		AudioListener.pause = true;
		gameEnd.enabled =true;
		gameOver.enabled = true;
		boss.enabled = true;
		replay.enabled = true;
		exit.enabled = true;
		smoke.enabled = true;
		float finishTime = Time.time;
		int gameTime = (int)(finishTime - timestamp);
		gameOver.text += "Game Over\nSurvival Time:\n" + gameTime + " seconds";
		scoreText.enabled = false;
	}
	
	void WinGameOver() {
		AudioListener.pause = true;
		gameEnd.enabled =true;
		gameOver.enabled = true;
		boss.enabled = true;
		replay.enabled = true;
		smoke.enabled = true;
		float finishTime = Time.time;
		int gameTime = (int) (finishTime - timestamp);
		gameOver.text += "Game Completed!\nDevelopment Time:\n" + gameTime + " seconds";
		scoreText.enabled = false;
	}
	
	public void ResetGame() {
		Application.LoadLevel("MainScreen");
	}
	
	
	public void ResetLevel() {
		Application.LoadLevel("Game");
	}
	
	public void increaseScore() {
		if(score <= 90) {
			score += 10;
		}
		if(score == 100) {
			WinGameOver();
		}
	}
	
	public void LoseLife() {
		life--;
		if(life == 0) {
			GameOver();
		}
		if(life == 2) {
			life3.enabled = false;
		} else if (life == 1) {
			life2.enabled = false;
		} else {
			life1.enabled = false;
		}
	}
}
