protected void LookupMatchingColors(Match3BoardPiece startPiece, LookupDirection lookupDir) { int lookupOffset = (int)lookupDir; int numPatterns = baseLookupPattern.GetLength(0); for (int i = 0; i < numPatterns; i++) { Match3BoardPiece.LinkType lookupDirA = (Match3BoardPiece.LinkType)((int)baseLookupPattern[i, 0] + lookupOffset); Match3BoardPiece.LinkType lookupDirB = (Match3BoardPiece.LinkType)((int)baseLookupPattern[i, 1] + lookupOffset); ignoreCount = AddToIgnoreList(GetMatchingColorBetweenDirections(startPiece, lookupDirA, lookupDirB)); } }
/// <summary> /// Find the neighbor pieces of the specified "currentPiece" in the direction "direction" that match between them. /// This method is called by <see cref="ProcessBoardPiece(AbstractBoardPiece boardPiece)"/>. /// </summary> /// <returns> /// The neighbor pieces for. /// </returns> /// <param name='currentPiece'> /// If set to <c>true</c> current piece. /// </param> /// <param name='direction'> /// If set to <c>true</c> direction. /// </param> protected bool FindMatchingNeighborPiecesFor(Match3BoardPiece currentPiece, Match3BoardPiece.LinkType direction) { Match3BoardPiece prevPiece = null; // // Reference to the piece who's neighbors we're about to process. // Match3BoardPiece originPiece = currentPiece; // Look at the next 2 neighbors in the specified "direction". for (int i = 0; i < 2; i++) { currentPiece = currentPiece.GetNeighbor(direction); // If this board piece is invalid or contains an invalid tile, stop the current neighbor lookup for the "currentPiece" // but continue the search with the next board pieces. if (currentPiece == null || currentPiece.Tile == null || currentPiece.Tile.IsDestroying || (currentPiece.Tile as NormalTile).IsTileSwitching || (currentPiece.Tile as NormalTile).IsFrozen() || !(currentPiece.Tile as Match3Tile).CanBeMatched && !(currentPiece.Tile is TriggerTile) || (currentPiece.Tile is TriggerTile) && !currentPiece.Tile.IsUserMoveable) { return(true); } Match3Tile currentTile = currentPiece.Tile as Match3Tile; if (prevPiece != null) { Match3Tile prevTile = prevPiece.Tile as Match3Tile; if (prevTile.IsMatchWith(currentTile)) { // Add this tile because it matches the previous one. AddNewPossibleMatchTile(currentTile); if (HasFoundPossibleMatchForColor(currentTile.TileColor)) { // Stop looking for other possible matches. return(false); } } } else { // int lastTriggerTileIdx = triggerTileMatchFound.Count - 1; // if (lastTriggerTileIdx >= 0 && triggerTileMatchFound[lastTriggerTileIdx] is ColorBombTile) { // Debug.LogWarning("[PossibleMatchesFinder] originalPiece = " + originalPiece + "\n -> search direction: " + direction + "\n -> " + " currentTile = " + currentTile); // } // Add this tile to the partial matches buffer because it's the first one AddNewPossibleMatchTile(currentTile); if (HasFoundPossibleMatchForColor(currentTile.TileColor)) { // Stop looking for other possible matches. return(false); } } prevPiece = currentPiece; } // Can continue to the next board piece. return(true); }
protected TileColorType GetMatchingColorBetweenDirections(Match3BoardPiece startPiece, Match3BoardPiece.LinkType dirA, Match3BoardPiece.LinkType dirB) { Match3BoardPiece pieceDirA = startPiece.GetNeighbor(dirA); Match3BoardPiece pieceDirB = null; if (dirA != dirB) { pieceDirB = startPiece.GetNeighbor(dirB); } else if (pieceDirA != null) { pieceDirB = pieceDirA.GetNeighbor(dirA); } if (pieceDirA != null && pieceDirB != null) { Match3Tile tileDirA = pieceDirA.Tile as Match3Tile; Match3Tile tileDirB = pieceDirB.Tile as Match3Tile; if (tileDirA != null && tileDirB != null && tileDirA.CanBeMatched && tileDirB.CanBeMatched && tileDirA.IsMatchWith(tileDirB)) { return(tileDirA.TileColor); } } return(TileColorType.None); }