Beispiel #1
0
    public void StartRound()
    {
        grid            = new GridElement[Grid.PlayWidth, Grid.PlayHeight];
        matchChecks     = new List <MatchCheck>(BlockManager.BlockCapacity);
        topOccupiedRow  = 0;
        topEffectiveRow = 0;

        for (int x = 0; x < PlayWidth; x++)
        {
            for (int y = 0; y < PlayHeight; y++)
            {
                grid[x, y]         = new GridElement();
                grid[x, y].State   = GridElement.ElementState.Empty;
                grid[x, y].Type    = GridElement.ElementType.Empty;
                grid[x, y].Element = null;
            }
        }

        int shortColumn = Random.Range(0, PlayWidth);

        for (int x = PlayWidth - 1; x >= 0; x--)
        {
            int height = (shortColumn == x ? 2 : 7) + Random.Range(0, 2);

            if (height - 1 > topOccupiedRow)
            {
                topOccupiedRow = height - 1;
            }

            for (int y = height - 1; y >= 1; y--)
            {
                int type;
                do
                {
                    type = Random.Range(0, Block.TypeCount);

                    if (!(StateAt(x, y + 1) == GridElement.ElementState.Empty) &&
                        BlockAt(x, y + 1).Type == type)
                    {
                        continue;
                    }

                    if (x == Grid.PlayWidth - 1)
                    {
                        break;
                    }

                    if (!(StateAt(x + 1, y) == GridElement.ElementState.Empty) &&
                        BlockAt(x + 1, y).Type == type)
                    {
                        continue;
                    }

                    break;
                } while (true);

                // setup creep creation state
                if (y == 2)
                {
                    BlockManager.SecondToLastRowCreepTypes[x] = type;
                }

                if (y == 1)
                {
                    BlockManager.LastRowCreepTypes[x] = type;
                }

                // create the block
                BlockManager.CreateIdleBlock(x, y, type);
            }
        }

        topEffectiveRow = topOccupiedRow;
    }