// Use this for initialization
    void Start()
    {
        totalBricks = stackWidth * stackHeight;

        // Need this for onClick stuff
        cam = transform.Find("MainCamera").GetComponent <Camera> ();

        // Need this for brick checking logic stuff
        bc = gameObject.GetComponentInChildren <BrickContainer> ();
        // Subtract one so we're counting from zero
        bc.cols = stackWidth;
        // Subtract one so we're counting from zero
        bc.rows = stackHeight;

        // Create new bricks
        for (int y = 0; y < stackHeight; y++)
        {
            for (int x = 0; x < stackWidth; x++)
            {
                makeBrick(x, y);
            }
        }

        // Something to allow easier triggering of color change testing
        if (brickColorChanging)
        {
            GameObject[] bricks;
            bricks = GameObject.FindGameObjectsWithTag("Brick");
            foreach (GameObject brick in bricks)
            {
                PrefabBrick b = brick.GetComponent <PrefabBrick> ();
                b.activateColorChanging();
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.CompareTag("Brick"))
                {
                    PrefabBrick hitBrick = hit.transform.GetComponent <PrefabBrick> ();
                    Debug.Log("Hit a " + hitBrick.getMyColor() + " brick");
                    hitBrick.goByeBye();
//        } else {
//          Debug.Log ("Did not hit a brick");
                }
            }
        }
    }
    void doMatchLogic()
    {
        // If stuff hasn't moved yet, just return
        if (!stuffHasMoved)
        {
            return;
        }
        // We will set up a two dimensional array with the colors of the bricks
        PrefabBrick[,] brickProxy = new PrefabBrick [rows, cols];
        bool[,] deleteQueue       = new bool[rows, cols];
        foreach (PrefabBrick brick in getAllChildBlocks())
        {
            int row = brick.getMyRow();
            int col = brick.getMyCol();
            brickProxy [row - 1, col - 1] = brick;
        }
        // We also want to set up a checkBlackList so we can be
        // a little more efficient about checking things.
        checkBlackList = new bool[rows, cols];
        // Now that we've built that up, let's compare colors
        List <int[]> brickList;

        for (int i = rows - 1; i >= 0; i--)
        {
            for (int j = cols - 1; j >= 0; j--)
            {
                if (checkBlackList [i, j] == true)
                {
                    continue;
                }
                brickList = new List <int[]> ();
                brickList = checkNeighbors(brickList, brickProxy, brickProxy [i, j].getMyColor(), i, j);
                // Remove any duplicate entries from the bricklist.
                brickList = brickList.Distinct().ToList();
                // Print out some info about the bricklist.
                String foo = "";
                foreach (int[] thing in brickList)
                {
                    foo = foo + "[" + thing [0] + "," + thing [1] + "]=";
                }
                Debug.LogWarning("After doing check that started with [" + i + "," + j + "], the brickList was " + brickList.Count + " elements long: " + foo);
                // Okay, we should have a proper brickAry with all matched brick locations
                // If the array is larger than the match threshold, add them to the delete queue
                if (brickList.Count >= matchThreshold)
                {
                    Debug.LogError("brickList was long enough. Adding those bricks to the deleteQueue");
                    // Add these to the delete queue if we got enough.
                    foreach (int[] entry in brickList)
                    {
                        int x = entry [0];
                        int y = entry [1];
                        deleteQueue [x, y] = true;
                    }
                    foo = "Delete queue is: ";

                    //    return;
                    // TODO: SOMETHING IS MESSED UP HERE IN THE CHECK!!!!
                    // TODO: Somehow deleteQueue is getting out of this loop without us detecting things properly
                    // TODO: and printing out its contents.  Something to look at another day
                    for (int k = 0; i < deleteQueue.GetUpperBound(0); k++)
                    {
                        for (int l = 0; j < deleteQueue.GetUpperBound(1); l++)
                        {
                            if (deleteQueue [k, l] == true)
                            {
                                foo = foo + "[" + k + "," + l + "]=";
                            }
                        }
                    }
                    Debug.LogWarning(foo);
                }
//        brickList.ForEach ((int[,]) => {
//          int x =
//          int y = decodeYFromPoint (intPoint);
//          checkBlackList [x, y] = true;
//          if (startDeleting) {
//            deleteQueue [x, y] = true;
//          }
//        });
            }
        }

        String frack = "Delete queue is: ";

//    return;
        for (int i = 0; i < deleteQueue.GetUpperBound(0); i++)
        {
            for (int j = 0; j < deleteQueue.GetUpperBound(1); j++)
            {
                if (deleteQueue [i, j])
                {
                    frack = frack + "[" + i + "," + j + "]=";
                    brickProxy [i, j].goByeBye();
                }
            }
        }
        Debug.LogWarning(frack);
    }