public override IEnumerator ProcessMatch(List <MatchPiece> matches, List <Tile> matchTiles, Board board) { bool destroyedFire = false; var adjacentTiles = board.GetAdjacentTiles(matchTiles, false); foreach (Tile tile in adjacentTiles) { if (!tile.HasContents) { continue; } MatchPiece piece = tile.Contents.GetComponent <MatchPiece>(); if (piece.Matches(typeof(FirePiece))) { tile.PushContents(null); if (!AnimatorUtils.Trigger(piece.gameObject, "DestroyWithWater")) { Destroy(piece.gameObject); } destroyedFire = true; } } if (destroyedFire) { AudioManager.Instance.PlaySound("DestroyWithWater"); yield return(new WaitForSeconds(destroyFireWaitTime)); } bool bloomed = false; foreach (Tile tile in adjacentTiles) { if (!tile.HasContents) { continue; } MatchPiece piece = tile.Contents.GetComponent <MatchPiece>(); if (piece.Matches(typeof(SeedPiece))) { var flowerPrefab = ((SeedPiece)piece).FlowerPrefab.gameObject; tile.PushContentsFromPrefab(flowerPrefab); if (!AnimatorUtils.Trigger(piece.gameObject, "Bloom")) { Destroy(piece.gameObject); } bloomed = true; } } if (bloomed) { AudioManager.Instance.PlaySound("BloomWithWater"); yield return(new WaitForSeconds(bloomWaitTime)); } }
private List <Tile> GetAdjacentMatchesRecursive(List <Tile> result, Board board, Tile tile, bool ignoreCanMatch) { MatchPiece piece = tile.Contents.GetComponent <MatchPiece>(); if (piece == null) { return(result); } List <Tile> adjacentTiles = board.GetAdjacentTiles(tile, false); foreach (Tile adjacentTile in adjacentTiles) { MatchPiece adjacentPiece = adjacentTile.HasContents ? adjacentTile.Contents.GetComponent <MatchPiece>() : null; if (adjacentPiece && (ignoreCanMatch || (piece.CanMatch && adjacentPiece.CanMatch)) && piece.Matches(adjacentPiece) && !result.Contains(adjacentTile)) { result.Add(adjacentTile); GetAdjacentMatchesRecursive(result, board, adjacentTile, ignoreCanMatch); } } return(result); }
public bool Matches(MatchPiece otherPiece) { return(piecePrefab.Matches(otherPiece)); }