/// <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); } }
/// <summary> Returns the number of elements matched towards top </summary> public static int CheckUpperNeighboursForMatches(int collum, int row, BoardElement[, ] positions) { int numberOfElem = 0; if (row - 1 > -1) { 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.CheckUpperNeighboursForMatches(collum, row - 1, positions); } } return(numberOfElem); }