Example #1
0
    /// <summary> Flags positions that belong to a match </summary>
    /// <param name="shouldFlag"> if false, elements wont be marked as matched (usefull when want to check possible matches)</param>
    /// <returns>returns an array where:
    /// position 0: number of matches that create a cross
    /// position 1: number of matches create a bomb
    /// position 2: number of matches create a bell</returns>
    public static int CheckElementForMatches(int startCollum, int startRow, BoardElement[, ] positions, ref bool[, ] matchedElemPositions, int collumsNumber, int rowsNumber, bool shouldFlag = true)
    {
        int upperMatches  = BoardFunctions.CheckUpperNeighboursForMatches(startCollum, startRow, positions);
        int bottomMatches = BoardFunctions.CheckBottomNeighboursForMatches(startCollum, startRow, positions, rowsNumber);
        int leftMatches   = BoardFunctions.CheckLeftNeighboursForMatches(startCollum, startRow, positions);
        int rightMatches  = BoardFunctions.CheckRightNeighboursForMatches(startCollum, startRow, positions, collumsNumber);

        if (shouldFlag)
        {
            // if more than 2 element matches, add vertical mathced elements
            if (upperMatches + bottomMatches >= 2)
            {
                matchedElemPositions[startCollum, startRow] = true;
                for (int row = startRow - upperMatches; row <= startRow + bottomMatches; row++)
                {
                    matchedElemPositions[startCollum, row] = true;
                    // AlexDebugger.GetInstance().AddMessage(positions[startCollum, row].GetAttachedGameObject().name + "is an " + ((row < startRow) ? " on top" : "on bottom") + " match of " + positions[startCollum, row].GetAttachedGameObject().name, AlexDebugger.tags.Matches);
                }
                if (upperMatches > 0)
                {
                    //AlexDebugger.GetInstance().AddMessage("Upper matches for element: " + GetTransformByIndex(positions[startCollum, startRow].GetTransformIndex()) + " are: " + upperMatches, AlexDebugger.tags.Matches);
                }
                if (bottomMatches > 0)
                {
                    //AlexDebugger.GetInstance().AddMessage("Bottom matches for element: " + GetTransformByIndex(positions[startCollum, startRow].GetTransformIndex()) + " are: " + bottomMatches, AlexDebugger.tags.Matches);
                }
            }
            // if more than 2 element matches, add horizontal mathced elements
            if (leftMatches + rightMatches >= 2)
            {
                matchedElemPositions[startCollum, startRow] = true;
                for (int collum = startCollum - leftMatches; collum <= startCollum + rightMatches; collum++)
                {
                    matchedElemPositions[collum, startRow] = true;
                }
                if (leftMatches > 0)
                {
                    //AlexDebugger.GetInstance().AddMessage("Left matches for element: " + GetTransformByIndex(positions[startCollum, startRow].GetTransformIndex()) + " are: " + leftMatches, AlexDebugger.tags.Matches);
                }
                if (rightMatches > 0)
                {
                    //AlexDebugger.GetInstance().AddMessage("Bottom matches for element: " + GetTransformByIndex(positions[startCollum, startRow].GetTransformIndex()) + " are: " + rightMatches, AlexDebugger.tags.Matches);
                }
            }
            if (upperMatches + bottomMatches >= 2 || leftMatches + rightMatches >= 2)
            {
                //AlexDebugger.GetInstance().AddMessage("Total matches found for: " + GetTransformByIndex(positions[startCollum, startRow].GetTransformIndex()) + " are: " + (upperMatches + bottomMatches + leftMatches + rightMatches).ToString(), AlexDebugger.tags.Matches);
            }
        }
        if (upperMatches + bottomMatches >= 2 || leftMatches + rightMatches >= 2)
        {
            return(upperMatches + bottomMatches + leftMatches + rightMatches);
        }
        else
        {
            return(0);
        }
    }
Example #2
0
    /// <summary> Returns the number of elements matched towards bottom </summary>
    public static int CheckBottomNeighboursForMatches(int collum, int row, BoardElement[, ] positions, int rowsNumbers)
    {
        int numberOfElem = 0;

        if (row + 1 < rowsNumbers)
        {
            if (positions[collum, row + 1].GetElementClassType() != typeof(BoardElement) && positions[collum, row + 1].GetElementClassType() != typeof(CrossBoardElement))
            {
                return(0);
            }
            if (positions[collum, row].GetElementValue() == positions[collum, row + 1].GetElementValue())
            {
                numberOfElem++;
                numberOfElem += BoardFunctions.CheckBottomNeighboursForMatches(collum, row + 1, positions, rowsNumbers);
            }
        }
        return(numberOfElem);
    }