public void OnTilesSwitchAnimFinished(AbstractBoardAnimations sender, AbstractTile srcTile, AbstractTile dstTile) { // Debug.Log("Switch anim finished!"); // Update the board positions of the animated tiles (update the board logic after the animation finishes). boardData.SwitchTiles(srcTile, dstTile); Match3Tile srcMatch3Tile = srcTile as Match3Tile; Match3Tile dstMatch3Tile = dstTile as Match3Tile; bool foundMatches = matchesFinder.FindMatches(); if ((!foundMatches || (!srcMatch3Tile.IsMatched && !dstMatch3Tile.IsMatched)) && (srcMatch3Tile.SwitchBackOnMatchFail && dstMatch3Tile.SwitchBackOnMatchFail)) { if (OnUserTilesSwitchBad != null) { OnUserTilesSwitchBad(srcMatch3Tile, dstMatch3Tile); } srcMatch3Tile.IsTileSwitching = true; dstMatch3Tile.IsTileSwitching = true; BoardAnimations.SwitchTilesAnim(false, srcMatch3Tile, dstMatch3Tile, (_sender, _srcTile, _dstTile) => { boardData.SwitchTiles(_srcTile, _dstTile); _srcTile.IsTileSwitching = false; _dstTile.IsTileSwitching = false; } ); srcMatch3Tile.RaiseEventSwitchBackOnFail(dstMatch3Tile); dstMatch3Tile.RaiseEventSwitchBackOnFail(srcMatch3Tile); } else if (srcMatch3Tile.IsMatched || dstMatch3Tile.IsMatched) { srcMatch3Tile.IsTileSwitching = false; dstMatch3Tile.IsTileSwitching = false; loseConditions.NewMove(); srcMatch3Tile.RaiseEventSwitchSuccess(dstMatch3Tile); dstMatch3Tile.RaiseEventSwitchSuccess(srcMatch3Tile); } else if (!srcMatch3Tile.SwitchBackOnMatchFail || !dstMatch3Tile.SwitchBackOnMatchFail) { // Reset the "IsTileSwitching" property for tiles that don't switch back on match fail because they finished their switch animation. srcMatch3Tile.IsTileSwitching = false; dstMatch3Tile.IsTileSwitching = false; } DestroyLastFoundMatches(); }
public bool FindMatchesAndUndo(bool isBoardSetup) { // Debug.Log("[MatchesUndoer] FindMatchesAndUndo called..."); // Look for any tile matches on the given board data. if (matchesFinder.FindMatches()) { List <Match3Tile> lastMatches = matchesFinder.lastFoundMatches; lastMatchedBoardPieces.Clear(); // Cache the board pieces from the last matched tiles found. for (int i = 0; i < lastMatches.Count; i++) { // When "isBoardSetup" = true we must undo matches made by all tiles that can have color and that can be matched (so we undo initial locked tiles matches). if ((!isBoardSetup || !lastMatches[i].IsTileIgnoredByAntiMatchSystems) && (lastMatches[i].GetType() == typeof(NormalTile) || isBoardSetup && lastMatches[i].canHaveColor && lastMatches[i].CanBeMatched && !(lastMatches[i] is TriggerTile))) { lastMatchedBoardPieces.Add(lastMatches[i].BoardPiece as Match3BoardPiece); } } // Undo all the matches found by looking at the board positions the matches were found. // Debug.Log("Initial matches found: " + lastMatches.Count); for (int i = 0; i < lastMatchedBoardPieces.Count; i++) { // Check if this board piece has an initial spawn rule that contains at least one "randomColor" based RuleEntry List <RuleEntry> ruleEntries = lastMatchedBoardPieces[i].initialTileSpawnRule.ruleEntries; bool tileCanBeChanged = false; for (int j = 0; j < ruleEntries.Count; j++) { if (ruleEntries[j].randomColor) { tileCanBeChanged = true; break; } } if (!tileCanBeChanged) { continue; } TileColorType[] ignoreTileColors = ComputeIgnoreColorListFromNeighbors(lastMatchedBoardPieces[i]); if (ignoreTileColors != null) { TileColorType newTileColor = TileSpawnRule.GetRandomTileColorDifferentFrom(ignoreTileColors); if (newTileColor == TileColorType.None) { // Debug.LogWarning("[MatchesUndoer] Couldn't find a color to replace tile for match undo: " + lastMatchedBoardPieces[i].Tile); } else { // Debug.Log("Changing tile: " + lastMatchedBoardPieces[i].Tile); System.Type lastTileType = lastMatchedBoardPieces[i].Tile.GetType(); GameObject.DestroyImmediate(lastMatchedBoardPieces[i].Tile.gameObject); // Spawn new tile of the same type but random color different from the ones computed above with "ComputeIgnoreTilesListFromNeighbors". Match3Tile newTile = Match3BoardRenderer.Instance.SpawnSpecificTileAt(lastMatchedBoardPieces[i].BoardPosition, lastTileType, newTileColor, false, isBoardSetup); if (OnNewTileSpawned != null) { OnNewTileSpawned(newTile); } // Debug.Log("with tile: " + newTile); } } } return(true); } return(false); }
protected IEnumerator DoPossibleMatchesCheck() { while (!enabled || Match3BoardGameLogic.Instance.IsGameOver || Match3BoardGameLogic.Instance.IsCheckingStableBoard || IsBoardReshuffling) { //Debug.LogWarning("[BoardShuffleController] Waiting until possible matches checking can be done..."); yield return(waitPollTime); } // Check if there's at least one possible match on the board. If there's no possible match, check for safety if there's a pending match on the board. bool boardHasPendingMatch = false; if (!possibleMatchesFinder.FindFirstPossibleMatch() && (!(boardHasPendingMatch = matchesFinder.FindMatches()))) { // Debug.LogWarning("[BoardShuffleController] No more possible matches! Re-shuffling..."); // Debug.Break(); RaiseBoardShuffleRequiredEvent(); } else { // Debug.Log("[BoardShuffleController] Board still has possible matches (boardHasPendingMatch = " + boardHasPendingMatch + ")..."); } hasPossibleMatchesCheckPending = false; }