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

public class Grid : MonoBehaviour {

	public int Width;
	public int Height;

	public DropCube DropCubeObject;

	private DropCube[,] dropCubes;

	// Use this for initialization
	void Start () {
		dropCubes = new DropCube[Width, Height];
		for(int x = 0; x < Width; x++)
			for(int y = 0; y < Height; y++)
			{
				dropCubes[x,y] = Instantiate(DropCubeObject);
				dropCubes[x,y].transform.SetParent(transform, false);
				dropCubes[x, y].transform.localPosition = new Vector3(x, y);
			}
	}

    public void Clean()
    {
        for(int x = 0; x <Width; x++)
			for(int y = 0; y <Height; y++)
				dropCubes[x, y].Clean();
    }

    // Update is called once per frame
    void Update () {
		if(Input.GetKeyDown(KeyCode.Q))
		{
			string outStr = ""; 
			for(int x = 0; x < Width; x++)
			{
				for(int y = 0; y < Height; y++)
				{
					outStr += ((int)dropCubes[x, y].currentShape).ToString() + ",";
				}
				outStr += "-";
			}
			Debug.Log(outStr);
		}
	}

	public ShapesEnum[,] GetCastle()
	{
		var result = new ShapesEnum[Width, Height];
		for(int x = 0; x <Width; x++)
			for(int y = 0; y <Height; y++)
				result[x, y] = dropCubes[x, y].currentShape;
		return result;
	}
}
