Example #1
0
    public bool CheckMatch()
    {
        bool check = false;

        board.matchedTiles = new HashSet <SpriteRenderer>();
        board.matchedPos   = new HashSet <Vector2Int>();
        for (int column = 0; column < board.dimension; column++)
        {
            for (int row = 0; row < board.dimension; row++)
            {
                if (board.GetSpriteAt(column, row) != board.sprites[5])
                {
                    SpriteRenderer        current           = board.GetSpriteRendererAt(column, row);
                    List <SpriteRenderer> horizontalMatches = FindColumnMatchForTile(column, row, current.sprite);
                    if (horizontalMatches.Count >= 2)
                    {
                        int count = 0;
                        check = true;
                        board.matchedTiles.UnionWith(horizontalMatches);
                        board.matchedTiles.Add(current);
                        while (count <= horizontalMatches.Count)
                        {
                            board.matchedPos.Add(new Vector2Int(column + count, row));
                            count++;
                        }
                    }
                    List <SpriteRenderer> verticalMatches = FindRowMatchForTile(column, row, current.sprite);
                    if (verticalMatches.Count >= 2)
                    {
                        int count = 0;
                        check = true;
                        board.matchedTiles.UnionWith(verticalMatches);
                        board.matchedTiles.Add(current);
                        while (count <= verticalMatches.Count)
                        {
                            board.matchedPos.Add(new Vector2Int(column, row + count));
                            count++;
                        }
                    }
                }
            }
        }
        return(check);
    }