IEnumerator DestroyColoredTiles() { // float offsetSize = Mathf.Abs(Board[0, 0].LocalPosition.x - Board[0, 1].LocalPosition.x) / 2f; if (OnTriggerColorBombTile != null) { OnTriggerColorBombTile(this); } if (destroyColor == TileColorType.None) { destroyColor = RuleEntry.genericColors[Random.Range(0, Match3BoardRenderer.maxNumBoardColors)]; } for (int i = 0; i < Board.NumRows; i++) { for (int j = 0; j < Board.NumColumns; j++) { Match3Tile tile = Board[i, j].Tile as Match3Tile; // if (tile != null && !(tile is DropTile) && tile.TileColor == destroyColor) if (IsValidTarget(tile, destroyColor)) { tilesToDestroy.Add(tile); if (iceTrailEffect != null) { Transform effectInstance = (Instantiate(iceTrailEffect) as GameObject).transform; effectInstance.position = WorldPosition; // + new Vector3(0f, 0f, -5f); effectInstance.parent = cachedTransform.parent; effectInstance.LookAt(tile.cachedTransform); tile.IsUserMoveable = false; StartCoroutine(MoveTargetTo(effectInstance, tile.cachedTransform, tilesDestroyEffect.destroyTileTime)); // HOTween.To(effectInstance, tilesDestroyEffect.destroyTileTime, "localPosition", Board[i, j].LocalPosition); Destroy(effectInstance.gameObject, tilesDestroyEffect.lifeTime * 1.5f); } } } } yield return(new WaitForSeconds(tilesDestroyEffect.destroyTileTime)); for (int i = 0; i < tilesToDestroy.Count; i++) { if (tilesToDestroy[i]) { tilesToDestroy[i].IsMatched = true; tilesToDestroy[i].Destroy(); } } if (tilesDestroyEffect.destroyTileTime < animation["effect_winterchill_idle"].length) { yield return(new WaitForSeconds(animation["effect_winterchill_idle"].length - tilesDestroyEffect.destroyTileTime)); } base.TileDestroy(false); Match3BoardGameLogic.Instance.TryCheckStableBoard(); }
public static Color Convert(TileColorType _color) { switch (_color) { case TileColorType.WHITE: return(Color.white); case TileColorType.GRAY: return(Color.gray); case TileColorType.BLACK: return(Color.black); case TileColorType.RED: return(Color.red); case TileColorType.YELLOW: return(Color.yellow); case TileColorType.GREEN: return(Color.green); case TileColorType.CYAN: return(Color.cyan); case TileColorType.BLUE: return(Color.blue); case TileColorType.MAGENTA: return(Color.magenta); default: Debug.LogWarning("Unknown TileColorType" + _color + ". Return black."); return(Color.black); } }
protected TileColorType[] ComputeIgnoreColorListFromNeighbors(Match3BoardPiece startPiece) { ignoreCount = 0; for (int i = 0; i < colorsToIgnore.Length; i++) { colorsToIgnore[i] = false; } LookupMatchingColors(startPiece, LookupDirection.Vertical); LookupMatchingColors(startPiece, LookupDirection.Horizontal); if (ignoreCount == 0) { return(null); } else { // Prepare lookup results. (an array of colors to ignore when picking a new random color for the current tile (on the "startPiece" board piece). TileColorType[] result = new TileColorType[ignoreCount]; int resultIdx = 0; for (int i = 1; i < colorsToIgnore.Length; i++) { if (colorsToIgnore[i]) { result[resultIdx++] = (TileColorType)i; } } return(result); } }
public void SetColor(TileColorType _color) { if (renderer_) { renderer_.color = TileDatabase.Convert(_color); } }
public RuleEntry(TileSpawnType _spawnType, TileColorType _spawnColor, ColorSelectionMethod _colorSelection, bool _randomColor) { spawnType = _spawnType; spawnColor = _spawnColor; colorSelection = _colorSelection; randomColor = _randomColor; }
public void AssignMaterialsForColor(TileColorType colorType) { for(int i = 0; i < freezeEffectMaterials.Length; i++) { if(freezeEffectMaterials[i].name.Equals(Enum.GetName(typeof(TileColorType), colorType))) { normalModel.material = freezeEffectMaterials[i].normalMat; cutoffModel.material = freezeEffectMaterials[i].cutoffMat; break; } } }
public void UpdateMaterial(TileColorType tileColor) { int index = (int)tileColor - 1; if (index >= 0 && index < coloredMaterials.Length) { UpdateMaterial(coloredMaterials[index]); } else { UpdateMaterial(null); } }
//Picks and sets the destroyColor property randomly ( excluding colorException ) public TileColorType SetRandomDestroyColor(TileColorType colorException) { int returnValue = Random.Range(1, (int)TileColorType.Count-1); if(returnValue == (int)colorException) { returnValue = Random.Range(0,1) == 0 ? Random.Range(1, (int)colorException-1) : Random.Range((int)colorException+1, (int)TileColorType.Count-1); } destroyColor = (TileColorType) returnValue; return (TileColorType)returnValue; }
public bool HasTileType(System.Type tileType, TileColorType tileColor) { if ( !tilesDictionary.ContainsKey(tileType) ) { return false; } Match3Tile[] tiles = tilesDictionary[tileType]; if (tiles != null) { return tiles[(int)tileColor] != null; } else { return false; } }
//Picks and sets the destroyColor property randomly ( excluding colorException ) public TileColorType SetRandomDestroyColor(TileColorType colorException) { int returnValue = Random.Range(1, (int)TileColorType.Count - 1); if (returnValue == (int)colorException) { returnValue = Random.Range(0, 1) == 0 ? Random.Range(1, (int)colorException - 1) : Random.Range((int)colorException + 1, (int)TileColorType.Count - 1); } destroyColor = (TileColorType)returnValue; return((TileColorType)returnValue); }
protected int AddToIgnoreList(TileColorType tileColor) { if (tileColor == TileColorType.None || colorsToIgnore[(int)tileColor]) { return(ignoreCount); } else { colorsToIgnore[(int)tileColor] = true; return(ignoreCount + 1); } }
/// <summary> /// Finds the first possible match. This is the main method from this class that needs to be called. /// </summary> /// <returns> /// The first possible match. /// </returns> public bool FindFirstPossibleMatch() { numFoundPossibleMatches = 0; lastFoundIsolatedTile = null; foundPossibleMatch[0] = foundPossibleMatch[1] = foundPossibleMatch[2] = null; foundPossibleMatchColor = TileColorType.None; ClearPartialMatchesBuffers(); // Start searching for the first possible match Board.ApplyCancellableActionToAll(FindMatchingBoardPiecesAround); // Check if we previously found a possible match and store the result separatelly. if (foundPossibleMatchColor != TileColorType.None) { List <Match3Tile> foundPossibleMatchList = partialTileMatchesLists[(int)foundPossibleMatchColor]; // if (debugEnabled) { // Debug.Log(Time.frameCount + " normal possible match found: "); // } for (int i = 0; i < 3; i++) { foundPossibleMatch[i] = foundPossibleMatchList[i]; // if (debugEnabled) { // Debug.Log("Match tile: " + i + ": " + foundPossibleMatch[i]); // } } numFoundPossibleMatches = 3; return(true); } else if (triggerTileMatchFound.Count >= 2) { // if (debugEnabled) { // Debug.Log(Time.frameCount + " trigger tiles possible match found: "); // } for (int i = 0; i < triggerTileMatchFound.Count; i++) { foundPossibleMatch[i] = triggerTileMatchFound[i]; // if (debugEnabled) { // Debug.Log("Match tile: " + i + ": " + foundPossibleMatch[i]); // } } numFoundPossibleMatches = triggerTileMatchFound.Count; return(true); } return(false); }
public void AssignMaterialsForColor(TileColorType colorType) { for (int i = 0; i < freezeEffectMaterials.Length; i++) { if (freezeEffectMaterials[i].name.Equals(Enum.GetName(typeof(TileColorType), colorType))) { normalModel.material = freezeEffectMaterials[i].normalMat; cutoffModel.material = freezeEffectMaterials[i].cutoffMat; break; } } }
public void UpdateMaterial(TileColorType tileColor) { int index = (int)tileColor - 1; if (index >= 0 && index < tileColorMaterials.Length) { UpdateMaterial(tileColorMaterials[index]); } else { UpdateMaterial(null); } }
public Match3Tile SpawnSpecificTile(System.Type tileType, TileColorType prefabDefaultColor, bool isBoardSetup = false) { Match3Tile newTile = (Instantiate(tilesDictionary[tileType, prefabDefaultColor].gameObject) as GameObject).GetComponent <Match3Tile>(); newTile.cachedTransform.parent = cachedTransform; newTile.BoardRenderer = this; if (!isBoardSetup) { newTile.InitComponent(); } return(newTile); }
public static TileColorType GetRandomTileColorDifferentFrom(TileColorType ignoreTileColor) { List <TileColorType> randomBag = new List <TileColorType>(Match3BoardRenderer.maxNumBoardColors); // Fill bag with all available tile colors different from the ignore tile color for (int i = 0; i < Match3BoardRenderer.maxNumBoardColors; i++) { if (RuleEntry.genericColors[i] != ignoreTileColor) { randomBag.Add(RuleEntry.genericColors[i]); } } return(randomBag[Random.Range(0, randomBag.Count)]); }
public Match3Tile this[System.Type tileType, TileColorType tileColor] { get { return tilesDictionary[tileType][(int)tileColor]; } set { Match3Tile[] tiles; if (tilesDictionary.TryGetValue(tileType, out tiles) == false) { tiles = new Match3Tile[(int)TileColorType.Count]; } tiles[(int)tileColor] = value; tilesDictionary[tileType] = tiles; } }
public Match3Tile this[System.Type tileType, TileColorType tileColor] { get { return(tilesDictionary[tileType][(int)tileColor]); } set { Match3Tile[] tiles; if (tilesDictionary.TryGetValue(tileType, out tiles) == false) { tiles = new Match3Tile[(int)TileColorType.Count]; } tiles[(int)tileColor] = value; tilesDictionary[tileType] = tiles; } }
public bool HasTileType(System.Type tileType, TileColorType tileColor) { if (!tilesDictionary.ContainsKey(tileType)) { return(false); } Match3Tile[] tiles = tilesDictionary[tileType]; if (tiles != null) { return(tiles[(int)tileColor] != null); } else { return(false); } }
public static Color Convert(TileColorType _color) { switch (_color) { case TileColorType.WHITE: return Color.white; case TileColorType.GRAY: return Color.gray; case TileColorType.BLACK: return Color.black; case TileColorType.RED: return Color.red; case TileColorType.YELLOW: return Color.yellow; case TileColorType.GREEN: return Color.green; case TileColorType.CYAN: return Color.cyan; case TileColorType.BLUE: return Color.blue; case TileColorType.MAGENTA: return Color.magenta; default: Debug.LogWarning("Unknown TileColorType" + _color + ". Return black."); return Color.black; } }
protected void AddToImmediateSpawnList(TileColorType dropTileColor) { TileSpawnRule tileSpawnRule = new TileSpawnRule(); tileSpawnRule.numberOfExecutions = 1; tileSpawnRule.ownerList = immediateSpawnList; RuleEntry ruleEntry = tileSpawnRule.ruleEntries[0]; ruleEntry.RuleTileType = typeof(DropTile); ruleEntry.ColorSelection = ColorSelectionMethod.ColorBased; ruleEntry.RuleTileColor = dropTileColor; ruleEntry.randomColor = false; immediateSpawnList.Add(tileSpawnRule); // Debug.LogError("[AddToImmediateSpawnList()]"); }
/// <summary> /// Determines whether this tile instance is a valid target for colorBombInteraction /// </summary> /// <returns> /// <c>true</c> if this instance is valid target; otherwise, <c>false</c>. /// </returns> public bool IsValidTarget(AbstractTile tile, TileColorType destroyColor) { NormalTile target = tile as NormalTile; // if (target != null && // target.IsDestructible && // target.TileColor == destroyColor) // { // return true; // } // return false; // return(target != null && target.IsDestructible && target.TileColor == destroyColor && !target.IsDestroying && !(target is SnowTile) && !target.IsFrozen()); }
public override void RaiseEventTileSwitchAnimBegan(Match3Tile _neighborTile) { base.RaiseEventTileSwitchAnimBegan(_neighborTile); //One of the few cases were the color bomb swipe is invalid and a switchback is required if (!lastNeighborTile.IsDestructible) { SwitchBackOnMatchFail = true; return; } destroyColor = lastNeighborTile.TileColor; // Disable colliders for this tile and it's neighbor tile if the neighbor is a ColorBomb tile. // Because these will do a combine effect and they shouldn't be picked up by other destroy sensors in the meantime. if (lastNeighborTile is ColorBombTile) { DisableTileLogic(); lastNeighborTile.DisableTileLogic(); } // Cached the "TappedFirst" property here for this tile because it will be reset in "RaiseEventTileSwitchAnimEnded" event. wasFirstTapped = TappedFirst; if (lastNeighborTile is DirectionalDestroyTile) { lastNeighborTile.CanBeMatched = false; } if (lastNeighborTile is BombTile) { lastNeighborTile.CanBeMatched = false; } if (_neighborTile.GetType() == typeof(NormalTile) /* && wasFirstTapped*/) { (_neighborTile as NormalTile).CanBeMatched = false; if (!wasFirstTapped) { Match3BoardGameLogic.Instance.loseConditions.NewMove(); } } }
/// <summary> /// Spawns the new tile. /// </summary> /// <param name='targetPiece'> /// Target piece. /// </param> public Match3Tile SpawnNewTile(bool isBoardSetup = false) { Match3Tile tileResult = null; // Early out if rule if(ruleEntries == null || ruleEntries.Count == 0) { return tileResult; } if (numberOfExecutions == 0) { EndSpawnRule(); return tileResult; } //Select random rule entry and acquire its info spawnedEntry = ruleEntries[Random.Range(0, ruleEntries.Count)]; spawnedType = spawnedEntry.RuleTileType; spawnedColor = spawnedEntry.RuleTileColor; if(ownerList != null && ownerList.Count > 0) { numberOfExecutions--; } // bool offBoard = false; // // if(ownerList != null) // { // if (ownerList.Count == 0) // { // offBoard = false; // } // else // { // offBoard = true; // numberOfExecutions--; // } // } //Spawn tile as described by the spawn rule // Debug.LogWarning("[SpawnRule] Spawning [" + spawnedType.ToString() + "] [" + spawnedColor.ToString() + "] [offboard:" + offBoard + "]"); if (typeof(BombTile) == spawnedType) { BombTile spawnedTile = Match3BoardRenderer.Instance.SpawnSpecificTile(spawnedType, TileColorType.None, isBoardSetup) as BombTile; // BombTile spawnedTile = Match3BoardRenderer.Instance.SpawnSpecificTileAt(targetPiece.BoardPosition, spawnedType, TileColorType.None, offBoard, isBoardSetup) as BombTile; spawnedTile.TileColor = spawnedColor; spawnedTile.UpdateMaterial(); tileResult = spawnedTile; } else if (typeof(DirectionalDestroyTile).IsAssignableFrom(spawnedType)) { DirectionalDestroyTile spawnedTile = Match3BoardRenderer.Instance.SpawnSpecificTile(spawnedType, TileColorType.None, isBoardSetup) as DirectionalDestroyTile; // DirectionalDestroyTile spawnedTile = Match3BoardRenderer.Instance.SpawnSpecificTileAt(targetPiece.BoardPosition, spawnedType, TileColorType.None, offBoard, isBoardSetup) as DirectionalDestroyTile; spawnedTile.TileColor = spawnedColor; spawnedTile.UpdateMaterial(); tileResult = spawnedTile; } else { // tileResult = Match3BoardRenderer.Instance.SpawnSpecificTileAt(targetPiece.BoardPosition, spawnedType, spawnedColor, offBoard, isBoardSetup); tileResult = Match3BoardRenderer.Instance.SpawnSpecificTile(spawnedType, spawnedColor, isBoardSetup); } if (tileResult != null) { tileResult.IsTileIgnoredByAntiMatchSystems = isTileIgnoredByAntiMatchSystems; } return tileResult; }
public void ColorTile(Tile tile, TileColorType colorType) { if (tile.entityPresent == Tile.EntityType.None) { switch (colorType) { case TileColorType.Movable: tile.graphics.GetComponent <Renderer>().material.color = traversableColor; break; case TileColorType.Unmovable: tile.graphics.GetComponent <Renderer>().material.color = neutralColor; break; case TileColorType.CurrentPath: tile.graphics.GetComponent <Renderer>().material.color = currentPathColor; break; case TileColorType.Hill: tile.graphics.GetComponent <Renderer>().material.color = hillColor; break; case TileColorType.HillTraversable: tile.graphics.GetComponent <Renderer>().material.color = hillTraversableColor; break; case TileColorType.HillPath: tile.graphics.GetComponent <Renderer>().material.color = hillPathColor; break; case TileColorType.Grass: tile.graphics.GetComponent <Renderer>().material.color = grassColor; break; case TileColorType.GrassPath: tile.graphics.GetComponent <Renderer>().material.color = grassPathColor; break; case TileColorType.GrassTraversable: tile.graphics.GetComponent <Renderer>().material.color = grassTraversableColor; break; case TileColorType.CurrentPathDestination: tile.graphics.GetComponent <Renderer>().material.color = currentPathColor; break; case TileColorType.MeleeRange: tile.graphics.GetComponent <Renderer>().material.color = meleeRangeColor; break; case TileColorType.IntimidationRange: tile.graphics.GetComponent <Renderer>().material.color = intimidationRangeColor; break; } } else if (tile.entityPresent == Tile.EntityType.Rock) { tile.graphics.GetComponent <Renderer>().material.color = unwalkableColor; } else { tile.graphics.GetComponent <Renderer>().material.color = neutralColor; } }
protected bool HasFoundPossibleMatchForColor(TileColorType tileColor) { int lastTriggerTileIdx = triggerTileMatchFound.Count - 1; // Check first if we found at least 2 trigger tiles that can be combined. // If thereis a ColorBomb in this list then it can be combined with any user moveable tile(ex:NormalTile) or any other trigger tile. if (triggerTileMatchFound.Count >= 2) { lastFoundIsolatedTile = triggerTileMatchFound[lastTriggerTileIdx]; // Debug.LogWarning("[PossibleMatchesFinder] lastFoundIsolatedTile = " + lastFoundIsolatedTile); return true; } // Check if we found a possible match. if (partialTileMatchesLists[(int)tileColor].Count == 3) { List<Match3Tile> isolatedTiles = isolatedTilesLists[(int)tileColor]; lastFoundIsolatedTile = null; // Usually in the isolated tiles list for a certain tile color, only one tile is left because the other 2 are adjacent. // In case there are more than 1 tiles left (usually all 3 are left) is because it means that none of them is adjacent to the other // and we have to see which 2 tiles are collinear (are on the same line horizontal/vertical) so we know that the 3rd tile is isolated. if (isolatedTiles.Count > 1) { // Search the 2 tiles that are collinear and mark them null so the list is left only with the isolated tile. for(int i = 0; i < isolatedTiles.Count - 1; i++) { Match3Tile tile = isolatedTiles[i]; for(int j = i + 1; j < isolatedTiles.Count; j++) { Match3Tile other = isolatedTiles[j]; if ( tile.BoardPiece.IsCollinearWith(other.BoardPiece) ) { // We found the 2 (and only possible) collinear tiles. // Mark them as null so we are left only with the isolated tile. Don't remove them because it's slower in this case. isolatedTiles[i] = null; isolatedTiles[j] = null; goto FinishedSearch; } } } FinishedSearch: // Find the remaining isolated tile for(int i = 0; i < isolatedTiles.Count; i++) { if (isolatedTiles[i] != null) { lastFoundIsolatedTile = isolatedTiles[i]; break; } } } else { lastFoundIsolatedTile = isolatedTiles[0]; } // Validate the isolated tile for this possible match group. if (lastFoundIsolatedTile == null) { // Debug.LogWarning("[PossibleMatchesFinder] For some reason the isolated tile wasn't found for a possible match! This shouldn't happen!"); // for(int i = 0; i < partialTileMatchesLists[(int)tileColor].Count; i++) // { // Debug.LogWarning(partialTileMatchesLists[(int)tileColor][i].name + ", "); // } } else if ( !lastFoundIsolatedTile.IsUserMoveable ) { // This tile is not user moveable. This possible match group is not valid. ClearPartialMatchesBuffers(); return false; } // isolatedTile.cachedTransform.localScale *= 1.25f; // Debug.Log("[PossibleMatchesFinder] The valid isolated tile is: " + lastFoundIsolatedTile.name); // Store the color type of the possible match. Stop the search here. foundPossibleMatchColor = tileColor; // Debug.LogWarning("We found a possible match: " + foundPossibleMatchColor); return true; } return false; }
/// <summary> /// Finds the first possible match. This is the main method from this class that needs to be called. /// </summary> /// <returns> /// The first possible match. /// </returns> public bool FindFirstPossibleMatch() { numFoundPossibleMatches = 0; lastFoundIsolatedTile = null; foundPossibleMatch[0] = foundPossibleMatch[1] = foundPossibleMatch[2] = null; foundPossibleMatchColor = TileColorType.None; ClearPartialMatchesBuffers(); // Start searching for the first possible match Board.ApplyCancellableActionToAll(FindMatchingBoardPiecesAround); // Check if we previously found a possible match and store the result separatelly. if (foundPossibleMatchColor != TileColorType.None) { List<Match3Tile> foundPossibleMatchList = partialTileMatchesLists[(int)foundPossibleMatchColor]; // if (debugEnabled) { // Debug.Log(Time.frameCount + " normal possible match found: "); // } for(int i = 0; i < 3; i++) { foundPossibleMatch[i] = foundPossibleMatchList[i]; // if (debugEnabled) { // Debug.Log("Match tile: " + i + ": " + foundPossibleMatch[i]); // } } numFoundPossibleMatches = 3; return true; } else if (triggerTileMatchFound.Count >= 2) { // if (debugEnabled) { // Debug.Log(Time.frameCount + " trigger tiles possible match found: "); // } for(int i = 0; i < triggerTileMatchFound.Count; i++) { foundPossibleMatch[i] = triggerTileMatchFound[i]; // if (debugEnabled) { // Debug.Log("Match tile: " + i + ": " + foundPossibleMatch[i]); // } } numFoundPossibleMatches = triggerTileMatchFound.Count; return true; } return false; }
public void SetColor(TileColorType _color) { if (renderer_) renderer_.color = TileDatabase.Convert(_color); }
public RuleEntry(System.Type _type, TileColorType _spawnColor) { RuleTileType = _type; spawnColor = _spawnColor; // spawnTileType = cachedTypeList[(int)spawnType]; }
protected int AddToIgnoreList(TileColorType tileColor) { if (tileColor == TileColorType.None || colorsToIgnore[(int)tileColor]) { return ignoreCount; } else { colorsToIgnore[(int)tileColor] = true; return ignoreCount + 1; } }
public static TileColorType GetRandomTileColorDifferentFrom(TileColorType[] ignoreTileColors) { if (ignoreTileColors.Length >= Match3BoardRenderer.maxNumBoardColors) { // Debug.LogWarning("This shouldn't happen!!! Trying to ignore all available colors for new random tile color! WTF!"); } List<TileColorType> randomBag = new List<TileColorType>(Match3BoardRenderer.maxNumBoardColors); // Fill bag with maximum available tile colors different from ignored tile colors. for(int i = 0; i < Match3BoardRenderer.maxNumBoardColors; i++) { bool validColor = true; for(int j = 0; j < ignoreTileColors.Length; j++) { if (RuleEntry.genericColors[i] == ignoreTileColors[j]) { validColor = false; break; } } if (validColor) { randomBag.Add(RuleEntry.genericColors[i]); } } if (randomBag.Count > 0) { return randomBag[Random.Range(0, randomBag.Count)]; } else { return TileColorType.None; } }
public Match3Tile SpawnSpecificTile(System.Type tileType, TileColorType prefabDefaultColor, bool isBoardSetup = false) { Match3Tile newTile = (Instantiate(tilesDictionary[tileType, prefabDefaultColor].gameObject) as GameObject).GetComponent<Match3Tile>(); newTile.cachedTransform.parent = cachedTransform; newTile.BoardRenderer = this; if ( !isBoardSetup ) { newTile.InitComponent(); } return newTile; }
public static TileColorType GetRandomTileColorDifferentFrom(TileColorType ignoreTileColor) { List<TileColorType> randomBag = new List<TileColorType>(Match3BoardRenderer.maxNumBoardColors); // Fill bag with all available tile colors different from the ignore tile color for(int i = 0; i < Match3BoardRenderer.maxNumBoardColors; i++) { if (RuleEntry.genericColors[i] != ignoreTileColor) { randomBag.Add(RuleEntry.genericColors[i]); } } return randomBag[Random.Range(0, randomBag.Count)]; }
/// <summary> /// Determines whether this tile instance is a valid target for colorBombInteraction /// </summary> /// <returns> /// <c>true</c> if this instance is valid target; otherwise, <c>false</c>. /// </returns> public bool IsValidTarget(AbstractTile tile, TileColorType destroyColor) { NormalTile target = tile as NormalTile; // if (target != null && // target.IsDestructible && // target.TileColor == destroyColor) // { // return true; // } // return false; // return target != null && target.IsDestructible && target.TileColor == destroyColor && !target.IsDestroying && !(target is SnowTile) && !target.IsFrozen(); }
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); }
public override void RaiseEventTileSwitchAnimBegan(Match3Tile _neighborTile) { base.RaiseEventTileSwitchAnimBegan(_neighborTile); //One of the few cases were the color bomb swipe is invalid and a switchback is required if(!lastNeighborTile.IsDestructible) { SwitchBackOnMatchFail = true; return; } destroyColor = lastNeighborTile.TileColor; // Disable colliders for this tile and it's neighbor tile if the neighbor is a ColorBomb tile. // Because these will do a combine effect and they shouldn't be picked up by other destroy sensors in the meantime. if (lastNeighborTile is ColorBombTile) { DisableTileLogic(); lastNeighborTile.DisableTileLogic(); } // Cached the "TappedFirst" property here for this tile because it will be reset in "RaiseEventTileSwitchAnimEnded" event. wasFirstTapped = TappedFirst; if(lastNeighborTile is DirectionalDestroyTile) { lastNeighborTile.CanBeMatched = false; } if(lastNeighborTile is BombTile) { lastNeighborTile.CanBeMatched = false; } if(_neighborTile.GetType() == typeof(NormalTile)/* && wasFirstTapped*/) { (_neighborTile as NormalTile).CanBeMatched = false; if ( !wasFirstTapped ) { Match3BoardGameLogic.Instance.loseConditions.NewMove(); } } }
public bool GenerateMatch(bool _isBoardSetup) { isBoardSetup = _isBoardSetup; normalTiles.Clear(); for (int i = 0; i < tilesBuffers.Length; i++) { tilesBuffers[i].Clear(); } // tileBufferIndices.Clear(); possibleMatchSlots.Clear(); // Collect all normal tiles and create tile buffers for each color. Board.ApplyActionToAll((boardPiece) => { if (boardPiece.Tile != null && boardPiece.Tile.GetType() == typeof(NormalTile) && (!isBoardSetup || !(boardPiece.Tile as NormalTile).IsTileIgnoredByAntiMatchSystems)) { Match3Tile tile = boardPiece.Tile as Match3Tile; normalTiles.Add(tile); // Add tile to corresponding color buffer. tilesBuffers[(int)tile.TileColor].Add(tile); } }); // No tiles allowed to be overriden by possible match generator if (normalTiles.Count == 0) { // Debug.LogWarning("[PossibleMatchGenerator] No normal tiles allowed to be touched by PossibleMatchGenerator..."); return(false); } // for(int i = 1; i < tilesBuffers.Length; i++) // { // Debug.LogWarning((TileColorType)i + " => " + tilesBuffers[i].Count); // } // Sort tile buffer indices descending. // After sorting the tile buffers the first tile buffer will contain the tiles that have the biggest count on the board. // So tileBuffers[0] won't represent the colored tiles buffer of the TileColorType.None anymore. (which was an empty buffer anyway) SortTilesBuffersCountDescending(); if (tilesBuffers[0].Count < 3) { TileColorType tileColorNeeded = tilesBuffers[0][0].TileColor; // Debug.LogWarning("[PossibleMatchGenerator] The color we need to generate: " + tileColorNeeded); // Go through each tile buffer and convert tiles into the color we need above to get at least 3 tiles of the same color // so we can create a possible match on the board. for (int i = 1; i < tilesBuffers.Length && tilesBuffers[0].Count < 3; i++) { int numAvailableTiles = tilesBuffers[i].Count; for (int j = 0; j < numAvailableTiles && tilesBuffers[0].Count < 3; j++) { Match3BoardPiece tilePiece = tilesBuffers[i][j].BoardPiece as Match3BoardPiece; // Destroy old tiles GameObject.DestroyImmediate(tilePiece.Tile.gameObject); tilesBuffers[i][j] = null; // Create new tile of the color we need. Match3Tile newTile = Match3BoardRenderer.Instance.SpawnSpecificTileAt(tilePiece.BoardPosition, typeof(NormalTile), tileColorNeeded, false, isBoardSetup); // Do any customization to new tiles spawned by this system. if (OnNewTileSpawned != null) { OnNewTileSpawned(newTile); } tilesBuffers[0].Add(newTile); } } } // Debug.LogWarning("[PossibleMatchGenerator] After repopulating with tiles:"); // for(int i = 0; i < tilesBuffers.Length; i++) // { // Debug.Log((TileColorType)i + " => " + tilesBuffers[i].Count); // } // Find a location on the board where to place the 3 tiles from the tile buffer 0 to create a possible match. if (FindPossibleMatchLocation()) { // Create possible match on the board for (int i = 0; i < possibleMatchSlots.Count; i++) { Match3Tile tempTile = possibleMatchSlots[i].Tile as Match3Tile; Match3BoardPiece targetPiece = tilesBuffers[0][i].BoardPiece as Match3BoardPiece; if (tempTile != targetPiece.Tile) { possibleMatchSlots[i].Tile = tilesBuffers[0][i]; targetPiece.Tile = tempTile; targetPiece.ResetTilePosition(); possibleMatchSlots[i].ResetTilePosition(); } } return(true); } return(false); // else // { // Debug.LogWarning("No possible match location found!!!"); // } }
public Match3Tile SpawnSpecificTileAt(int rowIdx, int columnIdx, System.Type tileType, TileColorType prefabDefaultColor, bool offBoardTile = false, bool isBoardSetup = false) { // Debug.LogWarning("[SpawnSpecificTileAt] " + tileType.ToString() + " " + prefabDefaultColor); // Spawn the specified tile Match3Tile newTile = SpawnSpecificTile(tileType, prefabDefaultColor, isBoardSetup); newTile.name = string.Format("[{0},{1}] {2}", rowIdx, columnIdx, newTile.name); // Assign the tile to the specified BoardPiece. AttachTileToBoardAt(rowIdx, columnIdx, newTile, offBoardTile, isBoardSetup); return(newTile); }
protected TileColorType[] ComputeIgnoreColorListFromNeighbors(Match3BoardPiece startPiece) { ignoreCount = 0; for(int i = 0; i < colorsToIgnore.Length; i++) { colorsToIgnore[i] = false; } LookupMatchingColors(startPiece, LookupDirection.Vertical); LookupMatchingColors(startPiece, LookupDirection.Horizontal); if (ignoreCount == 0) { return null; } else { // Prepare lookup results. (an array of colors to ignore when picking a new random color for the current tile (on the "startPiece" board piece). TileColorType[] result = new TileColorType[ignoreCount]; int resultIdx = 0; for(int i = 1; i < colorsToIgnore.Length; i++) { if ( colorsToIgnore[i]) { result[resultIdx++] = (TileColorType)i; } } return result; } }
public Match3Tile SpawnSpecificTileAt(int rowIdx, int columnIdx, System.Type tileType, TileColorType prefabDefaultColor, bool offBoardTile = false, bool isBoardSetup = false) { // Debug.LogWarning("[SpawnSpecificTileAt] " + tileType.ToString() + " " + prefabDefaultColor); // Spawn the specified tile Match3Tile newTile = SpawnSpecificTile(tileType, prefabDefaultColor, isBoardSetup); newTile.name = string.Format("[{0},{1}] {2}", rowIdx, columnIdx, newTile.name); // Assign the tile to the specified BoardPiece. AttachTileToBoardAt(rowIdx, columnIdx, newTile, offBoardTile, isBoardSetup); return newTile; }
protected bool HasFoundPossibleMatchForColor(TileColorType tileColor) { int lastTriggerTileIdx = triggerTileMatchFound.Count - 1; // Check first if we found at least 2 trigger tiles that can be combined. // If thereis a ColorBomb in this list then it can be combined with any user moveable tile(ex:NormalTile) or any other trigger tile. if (triggerTileMatchFound.Count >= 2) { lastFoundIsolatedTile = triggerTileMatchFound[lastTriggerTileIdx]; // Debug.LogWarning("[PossibleMatchesFinder] lastFoundIsolatedTile = " + lastFoundIsolatedTile); return(true); } // Check if we found a possible match. if (partialTileMatchesLists[(int)tileColor].Count == 3) { List <Match3Tile> isolatedTiles = isolatedTilesLists[(int)tileColor]; lastFoundIsolatedTile = null; // Usually in the isolated tiles list for a certain tile color, only one tile is left because the other 2 are adjacent. // In case there are more than 1 tiles left (usually all 3 are left) is because it means that none of them is adjacent to the other // and we have to see which 2 tiles are collinear (are on the same line horizontal/vertical) so we know that the 3rd tile is isolated. if (isolatedTiles.Count > 1) { // Search the 2 tiles that are collinear and mark them null so the list is left only with the isolated tile. for (int i = 0; i < isolatedTiles.Count - 1; i++) { Match3Tile tile = isolatedTiles[i]; for (int j = i + 1; j < isolatedTiles.Count; j++) { Match3Tile other = isolatedTiles[j]; if (tile.BoardPiece.IsCollinearWith(other.BoardPiece)) { // We found the 2 (and only possible) collinear tiles. // Mark them as null so we are left only with the isolated tile. Don't remove them because it's slower in this case. isolatedTiles[i] = null; isolatedTiles[j] = null; goto FinishedSearch; } } } FinishedSearch: // Find the remaining isolated tile for (int i = 0; i < isolatedTiles.Count; i++) { if (isolatedTiles[i] != null) { lastFoundIsolatedTile = isolatedTiles[i]; break; } } } else { lastFoundIsolatedTile = isolatedTiles[0]; } // Validate the isolated tile for this possible match group. if (lastFoundIsolatedTile == null) { // Debug.LogWarning("[PossibleMatchesFinder] For some reason the isolated tile wasn't found for a possible match! This shouldn't happen!"); // for(int i = 0; i < partialTileMatchesLists[(int)tileColor].Count; i++) // { // Debug.LogWarning(partialTileMatchesLists[(int)tileColor][i].name + ", "); // } } else if (!lastFoundIsolatedTile.IsUserMoveable) { // This tile is not user moveable. This possible match group is not valid. ClearPartialMatchesBuffers(); return(false); } // isolatedTile.cachedTransform.localScale *= 1.25f; // Debug.Log("[PossibleMatchesFinder] The valid isolated tile is: " + lastFoundIsolatedTile.name); // Store the color type of the possible match. Stop the search here. foundPossibleMatchColor = tileColor; // Debug.LogWarning("We found a possible match: " + foundPossibleMatchColor); return(true); } return(false); }
public Match3Tile SpawnSpecificTileAt(BoardCoord spawnPos, System.Type tileType, TileColorType prefabDefaultColor, bool offBoardTile, bool isBoardSetup) { return SpawnSpecificTileAt(spawnPos.row, spawnPos.col, tileType, prefabDefaultColor, offBoardTile, isBoardSetup); }
/// <summary> /// Initializes the random generic colors list from the <see cref="RuleEntry"/> class to allow /// <see cref="TileSpawnRule"/> classes to correctly pick unique random generic colors each time the level is restarted. /// </summary> public void InitializeRandomGenericColors() { // Get the needed colors from the win condition List <TileColorType> neededColors = new List <TileColorType>(); WinDestroyTiles winDestroy = winConditions as WinDestroyTiles; if (winDestroy) { foreach (DestroyTilesPair pair in winDestroy.destroyTiles) { if (pair.type.TileColor != TileColorType.None) { neededColors.Add(pair.type.TileColor); } } } // Init colors bag with all colors. List <TileColorType> allColors = new List <TileColorType>((int)TileColorType.Count - 1); for (int i = 1; i < (int)TileColorType.Count; i++) { if (neededColors.Contains((TileColorType)i)) { allColors.Insert(0, (TileColorType)i); } else { allColors.Add((TileColorType)i); } } // Shuffle the colors list. for (int i = 0; i < allColors.Count; i++) { int randomIdx; if (i < neededColors.Count) { randomIdx = Random.Range(0, neededColors.Count); } else { randomIdx = Random.Range(neededColors.Count, allColors.Count); } // Switch current color position to new randomIdx. TileColorType curColor = allColors[i]; allColors[i] = allColors[randomIdx]; allColors[randomIdx] = curColor; } // Initialize the generic colors list for (int i = 0; i < (int)GenericColorType.Count; i++) { RuleEntry.genericColors[i] = allColors[i]; } if (OnRandomGenericColorInitialized != null) { OnRandomGenericColorInitialized(); } }
/// <summary> /// Spawns the new tile. /// </summary> /// <param name='targetPiece'> /// Target piece. /// </param> public Match3Tile SpawnNewTile(bool isBoardSetup = false) { Match3Tile tileResult = null; // Early out if rule if (ruleEntries == null || ruleEntries.Count == 0) { return(tileResult); } if (numberOfExecutions == 0) { EndSpawnRule(); return(tileResult); } //Select random rule entry and acquire its info spawnedEntry = ruleEntries[Random.Range(0, ruleEntries.Count)]; spawnedType = spawnedEntry.RuleTileType; spawnedColor = spawnedEntry.RuleTileColor; if (ownerList != null && ownerList.Count > 0) { numberOfExecutions--; } // bool offBoard = false; // // if(ownerList != null) // { // if (ownerList.Count == 0) // { // offBoard = false; // } // else // { // offBoard = true; // numberOfExecutions--; // } // } //Spawn tile as described by the spawn rule // Debug.LogWarning("[SpawnRule] Spawning [" + spawnedType.ToString() + "] [" + spawnedColor.ToString() + "] [offboard:" + offBoard + "]"); if (typeof(BombTile) == spawnedType) { BombTile spawnedTile = Match3BoardRenderer.Instance.SpawnSpecificTile(spawnedType, TileColorType.None, isBoardSetup) as BombTile; // BombTile spawnedTile = Match3BoardRenderer.Instance.SpawnSpecificTileAt(targetPiece.BoardPosition, spawnedType, TileColorType.None, offBoard, isBoardSetup) as BombTile; spawnedTile.TileColor = spawnedColor; spawnedTile.UpdateMaterial(); tileResult = spawnedTile; } else if (typeof(DirectionalDestroyTile).IsAssignableFrom(spawnedType)) { DirectionalDestroyTile spawnedTile = Match3BoardRenderer.Instance.SpawnSpecificTile(spawnedType, TileColorType.None, isBoardSetup) as DirectionalDestroyTile; // DirectionalDestroyTile spawnedTile = Match3BoardRenderer.Instance.SpawnSpecificTileAt(targetPiece.BoardPosition, spawnedType, TileColorType.None, offBoard, isBoardSetup) as DirectionalDestroyTile; spawnedTile.TileColor = spawnedColor; spawnedTile.UpdateMaterial(); tileResult = spawnedTile; } else { // tileResult = Match3BoardRenderer.Instance.SpawnSpecificTileAt(targetPiece.BoardPosition, spawnedType, spawnedColor, offBoard, isBoardSetup); tileResult = Match3BoardRenderer.Instance.SpawnSpecificTile(spawnedType, spawnedColor, isBoardSetup); } if (tileResult != null) { tileResult.IsTileIgnoredByAntiMatchSystems = isTileIgnoredByAntiMatchSystems; } return(tileResult); }
public Match3Tile SpawnSpecificTileAt(BoardCoord spawnPos, System.Type tileType, TileColorType prefabDefaultColor, bool offBoardTile, bool isBoardSetup) { return(SpawnSpecificTileAt(spawnPos.row, spawnPos.col, tileType, prefabDefaultColor, offBoardTile, isBoardSetup)); }
IEnumerator DestroyColoredTiles() { // float offsetSize = Mathf.Abs(Board[0, 0].LocalPosition.x - Board[0, 1].LocalPosition.x) / 2f; if (OnTriggerColorBombTile != null) { OnTriggerColorBombTile(this); } if (destroyColor == TileColorType.None) { destroyColor = RuleEntry.genericColors[Random.Range(0, Match3BoardRenderer.maxNumBoardColors)]; } for (int i = 0; i < Board.NumRows; i++) { for (int j = 0; j < Board.NumColumns; j ++) { Match3Tile tile = Board[i, j].Tile as Match3Tile; // if (tile != null && !(tile is DropTile) && tile.TileColor == destroyColor) if (IsValidTarget(tile, destroyColor)) { tilesToDestroy.Add(tile); if (iceTrailEffect != null) { Transform effectInstance = (Instantiate(iceTrailEffect) as GameObject).transform; effectInstance.position = WorldPosition;// + new Vector3(0f, 0f, -5f); effectInstance.parent = cachedTransform.parent; effectInstance.LookAt(tile.cachedTransform); tile.IsUserMoveable = false; StartCoroutine(MoveTargetTo(effectInstance, tile.cachedTransform, tilesDestroyEffect.destroyTileTime)); // HOTween.To(effectInstance, tilesDestroyEffect.destroyTileTime, "localPosition", Board[i, j].LocalPosition); Destroy(effectInstance.gameObject, tilesDestroyEffect.lifeTime * 1.5f); } } } } yield return new WaitForSeconds(tilesDestroyEffect.destroyTileTime); for(int i = 0; i < tilesToDestroy.Count; i++) { if (tilesToDestroy[i]) { tilesToDestroy[i].IsMatched = true; tilesToDestroy[i].Destroy(); } } if (tilesDestroyEffect.destroyTileTime < animation["effect_winterchill_idle"].length) { yield return new WaitForSeconds(animation["effect_winterchill_idle"].length - tilesDestroyEffect.destroyTileTime); } base.TileDestroy(false); Match3BoardGameLogic.Instance.TryCheckStableBoard(); }