using UnityEngine;
using System.Collections;

public class PacManGame : MonoBehaviour 
{
	public static string state="menu";
	public Texture2D character1_png;
	public Texture2D character2_png;
	public Texture2D character3_png;
	private int Character=0;
	private int Difficulty=0;
	public GUISkin GUILoose;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update ()
	{
		switch(state)
		{
			//case "win"   : UpdateWin()   ; break;
			case "loose" : UpdateLoose() ; break;
			case "quit"  : UpdateQuit()  ; break;
		}
	}
	void OnGUI ()
	{
		switch(state)
		{
			case "menu"   : OnGUIMenu()  ; break;
			case "selectCharacter" : OnGUISelectCharacter(); break;
			case "difficulty"  : OnGUIDifficulty(); break;
			case "loose" : OnGUILoose (); break;
		}
	
	}
	void OnGUIMenu()
	{
		if (GUI.Button(new Rect(50,100,Screen.width - 100,Screen.height/5),"Play"))
		{
			state="difficulty";
		}
		if (GUI.Button(new Rect(50,100+Screen.height/2,Screen.width - 100,Screen.height/5),"Quit"))
		{
			state="quit";
		}
	}
	void OnGUIDifficulty()
	{
		if (GUI.Button(new Rect(Screen.width/2-Screen.width/10,25,Screen.width/5,Screen.height/5),"Easy"))
		{
			Difficulty=0;
			state="selectCharacter";
		}
		if (GUI.Button(new Rect(Screen.width/2-Screen.width/10,50+Screen.height/5,Screen.width/5,Screen.height/5),"Normal"))
		{
			Difficulty=1;
			state="selectCharacter";
		}
		if (GUI.Button(new Rect(Screen.width/2-Screen.width/10,75+2*Screen.height/5,Screen.width/5,Screen.height/5),"Hard"))
		{
			Difficulty=2;
			state="selectCharacter";
		}
		if (GUI.Button(new Rect(Screen.width/2-Screen.width/10,100+3*Screen.height/5,Screen.width/5,Screen.height/5),"Return"))
		{
			state="menu";
		}
	}
	void OnGUISelectCharacter()
	{
		if (GUI.Button(new Rect((Screen.width-3*Screen.width/5)/4,100,Screen.width/5,Screen.height/2),character1_png))
		{
			Character=1;
			state="level_1";
			Application.LoadLevel("Level1");
		}
		if (GUI.Button(new Rect((Screen.width-3*Screen.width/5)/2+Screen.width/5,100,Screen.width/5,Screen.height/2),character2_png))
		{
			Character=2;
			state="level_1";
			Application.LoadLevel("Level1");
		}
		if (GUI.Button(new Rect((Screen.width-3*Screen.width/5)*3/4+2*Screen.width/5,100,Screen.width/5,Screen.height/2),character3_png))
		{
			Character=3;
			state="level_1";
			Application.LoadLevel("Level1");
		}
		if (GUI.Button(new Rect(50,200+Screen.height/2,Screen.width - 100,Screen.height/7),"Return"))
		{
			state="difficulty";
		} 
	}
	void UpdateQuit()
		{
			Debug.Log("Dans Quit");
			Application.Quit();
		}
	void OnGUILoose()
	{
		
		GUI.Label(new Rect(Screen.width/2-200,Screen.height/2-200,400,100),"T'as perdu Gros Nul!!!!",GUILoose.label);
			
	}
	
	void UpdateLoose()
	{
		if(Input.GetMouseButtonDown(0))
		{
			state="menu";
		}
	}
}
