using UnityEngine;
using System.Collections;
using System.IO;

public class Jeu : MonoBehaviour {
	
	public GameObject Depart;
	public GameObject Arrivee;
	public GameObject Gagne;
	public GameObject Dalle;
	
	
	GameObject[] tab_dalle = new GameObject[100];
	
	protected int nb_dalle = 10;
	protected int i=0;
	protected int z=0;
	protected float ecart_x=1.2f;
	protected float ecart_z=1.2f;
	
	
	//string state="menu";
	
	// Use this for initialization
	void Start () {
	
		
	}
	
	// Update is called once per frame
	void Update () {
	
	/*	
		
		switch(state){
									
			case "init_dalle":
				UpdatePlateau();
				break;
			
			case "jeu": 
				UpdateJeu();			
				break;
			
			case "win": 
				UpdateWin();			
				break;
			
			case "lose": 
				UpdateLose();			
				break;
			
			case "quit":
				UpdateQuit();
				break;
		}

		*/
	
	
		
		
		
		
		

		
		
		
		
		while(i<100){
		
			//tab_dalle[i]=Dalle;
			
			for(int x=0; x<nb_dalle; x++){
			
								
				tab_dalle[i]=(GameObject)Instantiate(Dalle,new Vector3(x+(x*ecart_x),0,z+(z*ecart_z)),new Quaternion(0,0,0,0));
				
				if(Level.tab_way[i]==1){
				
					tab_dalle[i].layer = 22;
					
					if(z==0){
					
						Depart.layer = 20;
						Depart.transform.position = new Vector3(tab_dalle[i].transform.position.x,-0.2f,(tab_dalle[i].transform.position.z)-2.2f);
						
												
						
					}
											
					if(z==9){
						
						Arrivee.layer = 26;
						Arrivee.transform.position = new Vector3(tab_dalle[i].transform.position.x,-0.2f,(tab_dalle[i].transform.position.z)+2.2f);
						Gagne.transform.position = Arrivee.transform.position;
					}
						
						
				}				
				else{
				
					tab_dalle[i].layer = 24;
				}
				
				
				
				//Debug.Log(Level.tab_way[i]);
				//Debug.Log(tab_dalle[i].layer);
				
				//tab_dalle[i].transform.position = new Vector3(x*2,0,z*2);
				
				//Debug.Log(tab_dalle[i].transform.position.z);
				
				//tab_dalle[i].renderer.enabled=true;
				i++;
				//ecart_x=0.1f;
				//ecart_z=0.1f;
								
			}
			
			z++;
			//Debug.Log(tab_dalle[i].transform.position.x);
			//Debug.Log(i);
			//Debug.Log(Level.tab_way[i]);
		}
		
		
		//Perso.transform.position = new Vector3(Depart.transform.position.x,15.0f,Depart.transform.position.z);
		//Debug.Log(tab_dalle[50].layer);
		
	/*	
		for(int z=0; z<nb_dalle ; z++){

			for(int x=0; x<nb_dalle ; x++){
				
				tab_dalle[i]=Dalle;
				
				
				tab_dalle[i].transform.position = new Vector3(x,0,z);
			
				
				Debug.Log(tab_dalle[i].transform.position.x);
					
				//	,new Vector3(x*1.1f,y*1.1f,0),new Quaternion(0,0,0,0)
				//Instantiate(dalle,new Vector3(x*1.1f,y*1.1f,0),new Quaternion(0,0,0,0));
				i++;
			}
		}
		 */
	}
/*	
	void OnGUI()
	{
		
		
		switch(state)
		{
			
			case "menu": 
				OnGUIMenu();			
				break;
			
			case "grille":
				OnGUIGrille();
				break;
			
			case "init_dalle":
				OnGUIPlateau();
				break;
			
			case "jeu": 
				OnGUIJeu();	
			break;	
			
			case "win": 
				OnGUIWin();			
				break;
			
			case "lose": 
				OnGUILose();			
				break;
			
			case "score": 
				OnGUIScore();			
				break;	
		}
	}
		
		
	void OnGUIMenu(){

		GUI.backgroundColor=Color.green;
			
		if(GUI.Button(new Rect(300,300,100,50),"Jouer")){
			
			state="grille";
			fond.guiTexture.enabled=false;
		}
			
		if(GUI.Button(new Rect(500,300,100,50),"Quitter")){
			
				state="quit";
			fond.guiTexture.enabled=false;
		}
	}
	
	*/

		
		
		
	}


