Exemple #1
0
    private void RemoveTest()
    {
        for (int x = 0; x < mapXZ; x++)
        {
            for (int z = 0; z < mapXZ; z++)
            {
                if (cubeTable[new Vector3(x, 0, z)] != null)
                {
                    //DestroyImmediate(cubeTable[new Vector3(x, 0, z)]);
                    //Destroy(cubeTable[new Vector3(x, 0, z)]);
                    ChildCube cc = cubeTable[new Vector3(x, 0, z)];
                    cubeTable[new Vector3(x, 0, z)] = null;
                    cc.DestroyWhenRemove();

                    //Debug.Log(cubeTable[new Vector3(x, 0, z)].name);
                }
            }
        }

        for (int y = 1; y < MAP_HEIGHT_NUM; y++)
        {
            for (int x = 0; x < mapXZ; x++)
            {
                for (int z = 0; z < mapXZ; z++)
                {
                    if (cubeTable[new Vector3(x, y, z)] != null && cubeTable[new Vector3(x, y, z)].transform.parent.name == "LandPool")
                    {
                        cubeTable[new Vector3(x, y, z)].LocalPos += new Vector3(0, -1, 0);
                    }
                }
            }
        }
    }
Exemple #2
0
    public void RemoveLayer()
    {
        HashSet <int> layers = new HashSet <int>();


        for (int i = 0; i < MAP_HEIGHT_NUM - 1; i++)
        {
            layers.Add(i);
        }

        foreach (Vector3 pos in cubeTable.Keys)
        {
            if (cubeTable[pos] == null)
            {
                layers.Remove((int)pos.y);

                if (layers.Count == 0)
                {
                    return;
                }
            }
        }

        //Destroy cubes in a full layers
        foreach (int layer in layers)
        {
            for (int x = 0; x < mapXZ; x++)
            {
                for (int z = 0; z < mapXZ; z++)
                {
                    if (cubeTable[new Vector3(x, layer, z)] != null)
                    {
                        //Destroy(cubeTable[new Vector3(x, layer, z)]);

                        ChildCube cc = cubeTable[new Vector3(x, layer, z)];
                        cubeTable[new Vector3(x, layer, z)] = null;
                        cc.DestroyWhenRemove();
                    }
                }
            }

            for (int i = 1; i <= layers.Count; i++)
            {
                score += 100 * i;
            }

            scoreText.text = "Score: " + score.ToString();

            //Move down all cubes above the full layers
            for (int y = layer + 1; y < MAP_HEIGHT_NUM; y++)
            {
                for (int x = 0; x < mapXZ; x++)
                {
                    for (int z = 0; z < mapXZ; z++)
                    {
                        if (cubeTable[new Vector3(x, y, z)] != null && cubeTable[new Vector3(x, y, z)].transform.parent.name == "LandPool")
                        {
                            cubeTable[new Vector3(x, y, z)].LocalPos += new Vector3(0, -1, 0);
                        }
                    }
                }
            }
        }
    }