예제 #1
0
    public void ClearAdjacentTiles(Tile tile, TileSearchCondition condition)
    {
        int x = tile.X;
        int y = tile.Y;

        if (x < BOARD_WIDTH - 1 && condition(_board[x + 1, y]))
        {
            if (!TileIsMatched(_board[x + 1, y]))
            {
                ClearTile(_board[x + 1, y]);
            }
        }
        if (x > 0 && condition(_board[x - 1, y]))
        {
            if (!TileIsMatched(_board[x - 1, y]))
            {
                ClearTile(_board[x - 1, y]);
            }
        }
        if (y < BOARD_HEIGHT - 1 && condition(_board[x, y + 1]))
        {
            if (!TileIsMatched(_board[x, y + 1]))
            {
                ClearTile(_board[x, y + 1]);
            }
        }
        if (y > 0 && condition(_board[x, y - 1]))
        {
            if (!TileIsMatched(_board[x, y - 1]))
            {
                ClearTile(_board[x, y - 1]);
            }
        }
    }
예제 #2
0
    public List <Tile> FindNRandomTiles(int n, TileSearchCondition condition)
    {
        List <Tile> eligibleTiles = new List <Tile>();

        for (int x = 0; x < BOARD_WIDTH; x++)
        {
            for (int y = 0; y < BOARD_HEIGHT; y++)
            {
                if (_board[x, y] == null)
                {
                    continue;
                }

                if (condition == null || (condition != null && condition(_board[x, y])))
                {
                    eligibleTiles.Add(_board[x, y]);
                }
            }
        }

        return(eligibleTiles);
    }
예제 #3
0
    public void ReplaceNRandomTiles(int n, BaseTileData data, TileSearchCondition condition)
    {
        // first find a set of tiles that do not match the tiledata passed in
        List <Tile> eligibleTiles = FindNRandomTiles(n, condition);

        // pick n tiles out of the list to replace
        int numReplaced = 0;

        while (eligibleTiles.Count > 0 && numReplaced < n)
        {
            int  randIndex = UnityEngine.Random.Range(0, eligibleTiles.Count);
            Tile tile      = eligibleTiles[randIndex];
            tile.Initialize(data, tile.X, tile.Y);

            numReplaced++;
            eligibleTiles.RemoveAt(randIndex);

            if (!_dirtyTiles.Contains(tile))
            {
                _dirtyTiles.Add(tile);
            }
        }
    }
예제 #4
0
    public void ClearNRandomTiles(int n, TileSearchCondition condition)
    {
        // first find a set of tiles that do not match the tiledata passed in
        List <Tile> eligibleTiles = FindNRandomTiles(n, condition);


        // pick n tiles out of the list to replace
        int numReplaced = 0;

        while (eligibleTiles.Count > 0 && numReplaced < n)
        {
            int  randIndex = UnityEngine.Random.Range(0, eligibleTiles.Count);
            Tile tile      = eligibleTiles[randIndex];

            if (!TileIsMatched(tile))
            {
                ClearTile(tile);
            }

            numReplaced++;
            eligibleTiles.RemoveAt(randIndex);
        }
    }