Ejemplo n.º 1
0
    // Find the match that this hexagon piece is part of (implementation)
    private void GetMatchingPiecesAt(HexagonPiece piece, HexagonMatch match)
    {
        bool isPieceAddedToMatch = false;

        // Iterate over each possible tuple that is formed with this hexagon piece and see if that tuple is a match
        for (int i = 0; i < 6; i++)
        {
            HexagonTuple tuple = GetTupleAtCorner(piece.X, piece.Y, (HexagonPiece.Corner)i);
            if (!tuple.IsEmpty && tuple.IsMatching)
            {
                if (!isPieceAddedToMatch)
                {
                    match.Add(piece);
                    isPieceAddedToMatch = true;
                }

                if (matchesOnGridSet.Add(tuple.piece1))
                {
                    GetMatchingPiecesAt(tuple.piece1, match);
                }
                if (matchesOnGridSet.Add(tuple.piece2))
                {
                    GetMatchingPiecesAt(tuple.piece2, match);
                }
                if (matchesOnGridSet.Add(tuple.piece3))
                {
                    GetMatchingPiecesAt(tuple.piece3, match);
                }
            }
        }
    }
Ejemplo n.º 2
0
        // Find the match that this hexagon piece is part of (implementation)
        private void TryGetMatchingPiecesAt(HexagonPiece piece, HexagonMatch match)
        {
            bool isPieceAddedToMatch = false;

            // Iterate over each possible group that is formed with this hexagon piece and see if that group is a match
            for (int i = 0; i < 6; i++)
            {
                HexagonGroup _group = GetGroupAtCorner(piece.GridPos.x, piece.GridPos.y, (HexagonPiece.Edge)i);
                if (_group.IsEmpty || !_group.IsMatching)
                {
                    continue;
                }
                if (!isPieceAddedToMatch)
                {
                    match.Add(piece);
                    isPieceAddedToMatch = true;
                }
                if (matchesOnGridSet.Add(_group.Piece1))
                {
                    TryGetMatchingPiecesAt(_group.Piece1, match);
                }
                if (matchesOnGridSet.Add(_group.Piece2))
                {
                    TryGetMatchingPiecesAt(_group.Piece2, match);
                }
                if (matchesOnGridSet.Add(_group.Piece3))
                {
                    TryGetMatchingPiecesAt(_group.Piece3, match);
                }
            }
        }