public void SwitchTiles(AbstractTile src, AbstractTile dst) { AbstractBoardPiece dstBoardPiece = dst.BoardPiece; src.BoardPiece.Tile = dst; dstBoardPiece.Tile = src; }
/// <summary> /// Finds the matching board pieces around the specified "boardPiece", looking at all neighbors in the 4 directions of this board piece /// and caches the pairs of colors found in the partial matches buffers "partialTileMatches". /// If any color type buffer from the "partialTileMatches" reaches a count of 3 then we found a possible match for this board piece. /// This method /// </summary> /// <returns> /// <c>true</c> if the method allows the processing to continue to the next board piece. /// </returns> /// <param name='boardPiece'> /// The current board piece being processed. /// </param> protected bool FindMatchingBoardPiecesAround(AbstractBoardPiece boardPiece) { Match3BoardPiece curPiece = boardPiece as Match3BoardPiece; // Skip this board piece. if (curPiece.Tile == null || curPiece.IsBlocked /*|| !(curPiece.Tile as Match3Tile).CanBeMatched*/ || !curPiece.Tile.IsUserMoveable || curPiece.Tile.IsDestroying || (curPiece.Tile as NormalTile).IsTileSwitching || (curPiece.Tile as NormalTile).IsFrozen()) { return(true); } // Clear partial matches buffers ClearPartialMatchesBuffers(); // If the current board piece we're on is a special trigger tile, add it to the trigger tiles bag in case we find another one around it. if (curPiece.Tile is TriggerTile) { triggerTileMatchFound.Add(curPiece.Tile as Match3Tile); } // Go to maximum 2 recursive neighbors (in each of the 4 directions) and check if they match. // If the first neighbor in the current direction doesn't match the next neighbor then don't add the 2nd neighbor in the // "partialTileMatches" buffer and only add the first one. Otherwise, add them both if they match. for (int i = 0; i < dirIndices.Length; i++) { if (!FindMatchingNeighborPiecesFor(curPiece, dirIndices[i])) { return(false); } } return(true); }
protected void RaiseOnNewBoardPieceSelected(AbstractBoardPiece boardPiece, CustomInput.TouchInfo touchInfo) { if (OnNewBoardPieceSelected != null) { OnNewBoardPieceSelected(boardPiece, touchInfo); } }
public void OnNeighborDestroy(AbstractBoardPiece sender, AbstractTile neighbor) { if (neighbor && (neighbor as NormalTile).IsMatched) { NumLayers--; } }
protected void RaiseOnNewBoardPieceSelected(AbstractBoardPiece boardPiece, CustomInput.TouchInfo touchInfo) { if(OnNewBoardPieceSelected != null) { OnNewBoardPieceSelected(boardPiece, touchInfo); } }
protected void OnTileDestroyedAction(AbstractBoardPiece sender, AbstractTile destroyedTile) { //Early out for those scenarios in witch you would not want to pop a frost tile if (destroyedTile is LockedTile || destroyedTile is SnowTile || destroyedTile is FreezerTile) { return; } NumLayers--; }
public override bool CanMoveAt(AbstractBoardPiece targetBoardPiece) { bool canMove = base.CanMoveAt(targetBoardPiece) && !IsFrozen(); // if ( !canMove ) { // Debug.LogWarning(this.name + " tile can't be moved to: " + targetBoardPiece); // } return(canMove); }
protected void OnNewBoardPieceSelected(AbstractBoardPiece boardPiece, CustomInput.TouchInfo touchInfo) { if (isRunning || BoardShuffleController.Instance.IsBoardReshuffling) { return; } bool isLinked = false; AbstractBoardPiece lastSelection = null; //Cache reference to the last selection if (selectionList.Count > 0) { lastSelection = selectionList[selectionList.Count - 1]; } // if(boardPiece.GetType() != typeof(EmptyBoardPiece)) // { //Undo selection if (selectionList.Count >= 2 && selectionList[selectionList.Count - 2] == boardPiece) { RemoveSelection(selectionList.Count - 1); return; } //Check link between new and last selection if (lastSelection) { isLinked = lastSelection.IsAdjacentTo(boardPiece); } //Add current tile to the selection or start a new one if (selectionCount < maxNumberOfSelections) // && !selectionList.Contains(boardPiece) { if (!isLinked) { if (selectionList.Contains(boardPiece)) { return; } RemoveAllSelections(); } AddSelection(boardPiece); } if (selectionCount == maxNumberOfSelections || selectionList.Count == critNumberOfSelections) { touchController.StopInputController(); StartCoroutine(DoItemCoroutine()); isRunning = true; } // } }
protected void OnTileChanged(AbstractBoardPiece sender, AbstractTile tile) { if (tile is DropTile) { DropTile dropTile = tile as DropTile; if (!dropTile.isSwitching && !dropTile.isDropping) { StartCoroutine(dropTile.Drop()); } } }
public void OnNeighborDestroy(AbstractBoardPiece sender, AbstractTile neighbor) { if(neighbor && (neighbor as NormalTile).IsMatched) { Destroy (); FreezerController.Instance.freezerDestroyedThisTurn = true; FreezerController.Instance.allFreezers.Remove(this); //Tile release //BoardPiece.Tile = null; } }
protected void OnTileChanged(AbstractBoardPiece sender, AbstractTile tile) { if(tile is DropTile) { DropTile dropTile = tile as DropTile; if(!dropTile.isSwitching && !dropTile.isDropping) { StartCoroutine(dropTile.Drop()); } } }
public void OnNeighborDestroy(AbstractBoardPiece sender, AbstractTile neighbor) { if (neighbor && (neighbor as NormalTile).IsMatched) { Destroy(); FreezerController.Instance.freezerDestroyedThisTurn = true; FreezerController.Instance.allFreezers.Remove(this); //Tile release //BoardPiece.Tile = null; } }
protected void OnBoardPieceTileChanged(AbstractBoardPiece sender, AbstractTile newTile) { if ((sender as Match3BoardPiece).IsBlocked) { StartCoroutine(RaiseTileSpawnEventNextFrame(sender, newTile)); return; } // Check if the new tile of the board piece is null. if (newTile != null) { return; } if (OnTileSpawnerPieceEmpty != null) { OnTileSpawnerPieceEmpty(this); } // Debug.Log(name + " => at frame: " + Time.frameCount); // Execute the next spawn rule from the list. if (immediateSpawnList.Count > 0 && Match3BoardRenderer.minDelayForceSpawnRules + lastImmediateRuleSpawnTime < Time.time) { // Debug.LogError("ImediateSpawnList has " + immediateSpawnList.Count + " items!"); for (int i = 0; i < immediateSpawnList.Count; i++) { // Debug.LogError("Checking for [i] = " + i); for (int j = 0; j < boardPiece.eligibleSpawnList.Count; j++) { // Debug.LogError("Checking for [i][j]" + i + " " + j); if (immediateSpawnList[i].ruleEntries[0].Equals(boardPiece.eligibleSpawnList[j])) { SpawnImmediateRule(i); return; } } } } // if (tileSpawnRules.Count > 0) { // tileSpawnRules[currentSpawnRuleIdx++].SpawnNewTile(); SpawnNewTileInQueue(tileSpawnRules[currentSpawnRuleIdx++]); if (currentSpawnRuleIdx >= tileSpawnRules.Count) { currentSpawnRuleIdx = 0; } } }
/// <summary> /// Determines whether this board piece is adjacent only in the 4 directions (top, bottom, left, right) to the specified target board piece. /// </summary> /// <returns> /// <c>true</c> if this instance is adjacent to the specified targetBoardPiece; otherwise, <c>false</c>. /// </returns> /// <param name='targetBoardPiece'> /// If set to <c>true</c> target board piece. /// </param> public bool IsAdjacentTo(AbstractBoardPiece targetBoardPiece) { if (targetBoardPiece == null) { return(false); } BoardCoord offset = BoardPosition - targetBoardPiece.BoardPosition; offset.row = Mathf.Abs(offset.row); offset.col = Mathf.Abs(offset.col); return(offset.row == 0 && offset.col == 1 || offset.row == 1 && offset.col == 0); }
protected override void DoItem() { if (tileToDestroy) { AbstractBoardPiece BoardPiece = tileToDestroy.BoardPiece; BoardPiece.Tile = (boardLogic.boardRenderer as Match3BoardRenderer).SpawnSpecificTileAt(BoardPiece.BoardPosition.row, BoardPiece.BoardPosition.col, typeof(ColorBombTile), TileColorType.None); glacierTile = BoardPiece.Tile as ColorBombTile; //glacierTile.StartCoroutine(glacierTile.StartIdleAnim()); tileToDestroy.tileModelRenderer.enabled = false; // tileToDestroy.AddScore(); } WaitAndDestroyTile(); }
protected void OnNewBoardPieceSelected(AbstractBoardPiece boardPiece, CustomInput.TouchInfo touchInfo) { // Debug.LogWarning("[OnNewBoardPieceSelect]"); if (BoardShuffleController.Instance.IsBoardReshuffling) { return; } if (startPosition == Vector3.zero) { startPosition = boardPiece.cachedTransform.position; } else { endPosition = boardPiece.cachedTransform.position; } }
protected void CheckBoardTouch(Vector3 position, CustomInput.TouchInfo touchInfo) { boardCoord = ConvertToBoardCoord(position); if (boardCoord.row < 0 || boardCoord.row >= Match3BoardRenderer.Instance.Board.NumRows || boardCoord.col < 0 || boardCoord.col >= Match3BoardRenderer.Instance.Board.NumColumns) { return; } CustomInput.TouchInfo modifiedTouchInfo = new CustomInput.TouchInfo(touchInfo); modifiedTouchInfo.position = position; if (prevBoardCoord != boardCoord) { boardPiece = Match3BoardRenderer.Instance.Board[boardCoord.row, boardCoord.col]; RaiseOnNewBoardPieceSelected(boardPiece, modifiedTouchInfo); prevBoardCoord = boardCoord; } }
public virtual bool CanMoveTile(AbstractTile tile, AbstractBoardPiece targetBoardPiece) { // In case we're trying to do a switch with the same tile. (failed input or reached board margin) if (tile.BoardPiece == targetBoardPiece) { // Debug.LogWarning("[Match3BoardGameLogic] Trying to move tile " + tile.name + " in the same board piece as the tile: " + targetBoardPiece); return(false); } // Safety-check in case we might try to move a tile to a board piece which has no tile on it to switch with. // In case we will want this mechanic later in the game we will let the tile decide if it can move to an empty board piece or not. if (targetBoardPiece.Tile == null) { // Debug.LogError("[Match3BoardGameLogic] In method CanMoveTile: " + tile.name + " error: targetBoardPiece doesn't have any tile to switch with!"); return(false); } // Check if tiles can switch positions. return(tile.CanMoveAt(targetBoardPiece) && targetBoardPiece.Tile.CanMoveAt(tile.BoardPiece)); }
public void WriteToStream(System.IO.BinaryWriter writeStream) { writeStream.Write(NumRows); writeStream.Write(NumColumns); for (int rowIdx = 0; rowIdx < NumRows; rowIdx++) { for (int colIdx = 0; colIdx < NumColumns; colIdx++) { // Write board piece class type AbstractBoardPiece boardPiece = grid[rowIdx, colIdx]; if (boardPiece != null) { boardPiece.WriteToStream(writeStream); } else { writeStream.Write(AbstractBoardPiece.EmptyPieceTag); } } } }
/// <summary> /// Determines whether this tile is adjacent to the specified targetBoardPiece. /// This method can be made virtual so other tiles can "fool" the game into thinking that a tile could "jump-switch" with /// another tile further from it. /// </summary> /// <returns> /// <c>true</c> if this tile is adjacent to the specified targetBoardPiece; otherwise, <c>false</c>. /// </returns> /// <param name='targetBoardPiece'> /// If set to <c>true</c> target board piece. /// </param> // public bool IsAdjacentTo(AbstractBoardPiece targetBoardPiece) { // return BoardPiece.IsAdjacentTo(targetBoardPiece); // } /// <summary> /// Determines whether this tile can move at the specified targetBoardPiece. /// </summary> /// <returns> /// <c>true</c> if this instance can move at the specified targetBoardPiece; otherwise, <c>false</c>. /// </returns> /// <param name='targetBoardPiece'> /// If set to <c>true</c> target board piece. /// </param> public virtual bool CanMoveAt(AbstractBoardPiece targetBoardPiece) { if (Board == null) { Debug.LogError("Tile " + name + " has no BoardData reference!"); } if (targetBoardPiece == null) { return(false); } // BoardCoord targetBoardPos = targetBoardPiece.BoardPosition; // // // Do board coordinates sanity check first. // if (targetBoardPos.row < 0 || targetBoardPos.col < 0 || targetBoardPos.row >= Board.NumRows || targetBoardPos.col >= Board.NumColumns) { // return false; // } bool canMove = !IsMoving && IsUserMoveable && BoardPiece.IsAdjacentTo(targetBoardPiece) && !IsDestroying; return(canMove); }
protected void AddSelection(AbstractBoardPiece boardPiece) { Transform selection = null; // Debug.LogWarning("Add selection: " + boardPiece.BoardPosition.row + " " + boardPiece.BoardPosition.col); if (!selectionList.Contains(boardPiece)) { selection = (GameObject.Instantiate(prefabSelectionEffect) as GameObject).transform; selection.parent = boardPiece.cachedTransform; selection.localPosition = new Vector3(0f, 0f, -1f); selection.animation["effect_nextitem3"].speed = selectionAnimationSpeed; if (!(boardPiece is EmptyBoardPiece)) { selectionCount++; } } selectionEffectList.Add(selection); selectionList.Add(boardPiece); }
public void OnNewBoardPieceSelected(AbstractBoardPiece boardPiece, CustomInput.TouchInfo touchInfo) { if(BoardShuffleController.Instance.IsBoardReshuffling) { return; } bool selectionSucces = false; selectedBoardPiece = boardPiece; tileToDestroy = boardPiece.Tile as Match3Tile; effectPosition = boardPiece.cachedTransform; //Decide wether this selection is icepick worthy or not if(boardPiece.Tile == null) { if(boardPiece is LayeredBoardPiece && (boardPiece as LayeredBoardPiece).NumLayers > 0 ) { selectionSucces = true; } } else if (!tileToDestroy.IsMoving && tileToDestroy.IsDestructible && !tileToDestroy.IsDestroying && !(tileToDestroy as NormalTile).IsFrozen()) { selectionSucces = true; } if(selectionSucces) { SoundManager.Instance.PlayOneShot("icepick_sfx"); touchController.StopInputController(); touchController.OnNewBoardPieceSelected -= OnNewBoardPieceSelected; StartItemEffects(); } }
public void OnNewBoardPieceSelected(AbstractBoardPiece boardPiece, CustomInput.TouchInfo touchInfo) { if (BoardShuffleController.Instance.IsBoardReshuffling) { return; } bool selectionSucces = false; selectedBoardPiece = boardPiece; tileToDestroy = boardPiece.Tile as Match3Tile; effectPosition = boardPiece.cachedTransform; //Decide wether this selection is icepick worthy or not if (boardPiece.Tile == null) { if (boardPiece is LayeredBoardPiece && (boardPiece as LayeredBoardPiece).NumLayers > 0) { selectionSucces = true; } } else if (!tileToDestroy.IsMoving && tileToDestroy.IsDestructible && !tileToDestroy.IsDestroying && !(tileToDestroy as NormalTile).IsFrozen()) { selectionSucces = true; } if (selectionSucces) { SoundManager.Instance.PlayOneShot("icepick_sfx"); touchController.StopInputController(); touchController.OnNewBoardPieceSelected -= OnNewBoardPieceSelected; StartItemEffects(); } }
protected void OnBoardPieceTileChanged(AbstractBoardPiece sender, AbstractTile newTile) { if ((sender as Match3BoardPiece).IsBlocked) { StartCoroutine(RaiseTileSpawnEventNextFrame(sender, newTile)); return; } // Check if the new tile of the board piece is null. if (newTile != null) { return; } if (OnTileSpawnerPieceEmpty != null) { OnTileSpawnerPieceEmpty(this); } // Debug.Log(name + " => at frame: " + Time.frameCount); // Execute the next spawn rule from the list. if( immediateSpawnList.Count > 0 && Match3BoardRenderer.minDelayForceSpawnRules + lastImmediateRuleSpawnTime < Time.time) { // Debug.LogError("ImediateSpawnList has " + immediateSpawnList.Count + " items!"); for(int i = 0; i < immediateSpawnList.Count; i++) { // Debug.LogError("Checking for [i] = " + i); for(int j = 0; j < boardPiece.eligibleSpawnList.Count; j++) { // Debug.LogError("Checking for [i][j]" + i + " " + j); if ( immediateSpawnList[i].ruleEntries[0].Equals(boardPiece.eligibleSpawnList[j]) ) { SpawnImmediateRule(i); return; } } } } // if (tileSpawnRules.Count > 0) { // tileSpawnRules[currentSpawnRuleIdx++].SpawnNewTile(); SpawnNewTileInQueue(tileSpawnRules[currentSpawnRuleIdx++]); if (currentSpawnRuleIdx >= tileSpawnRules.Count) { currentSpawnRuleIdx = 0; } } }
protected IEnumerator RaiseTileSpawnEventNextFrame(AbstractBoardPiece sender, AbstractTile newtile) { yield return null; OnBoardPieceTileChanged(sender, newtile); }
protected void OnNewBoardPieceSelected(AbstractBoardPiece boardPiece, CustomInput.TouchInfo touchInfo) { if(isRunning || BoardShuffleController.Instance.IsBoardReshuffling) { return; } bool isLinked = false; AbstractBoardPiece lastSelection = null; //Cache reference to the last selection if(selectionList.Count > 0) { lastSelection = selectionList[selectionList.Count-1]; } // if(boardPiece.GetType() != typeof(EmptyBoardPiece)) // { //Undo selection if(selectionList.Count >= 2 && selectionList[selectionList.Count-2] == boardPiece) { RemoveSelection(selectionList.Count-1); return; } //Check link between new and last selection if(lastSelection) { isLinked = lastSelection.IsAdjacentTo(boardPiece); } //Add current tile to the selection or start a new one if(selectionCount < maxNumberOfSelections) // && !selectionList.Contains(boardPiece) { if(!isLinked) { if(selectionList.Contains(boardPiece)) { return; } RemoveAllSelections(); } AddSelection(boardPiece); } if(selectionCount == maxNumberOfSelections || selectionList.Count == critNumberOfSelections) { touchController.StopInputController(); StartCoroutine(DoItemCoroutine()); isRunning = true; } // } }
/// <summary> /// Finds the matching board pieces around the specified "boardPiece", looking at all neighbors in the 4 directions of this board piece /// and caches the pairs of colors found in the partial matches buffers "partialTileMatches". /// If any color type buffer from the "partialTileMatches" reaches a count of 3 then we found a possible match for this board piece. /// This method /// </summary> /// <returns> /// <c>true</c> if the method allows the processing to continue to the next board piece. /// </returns> /// <param name='boardPiece'> /// The current board piece being processed. /// </param> protected bool FindMatchingBoardPiecesAround(AbstractBoardPiece boardPiece) { Match3BoardPiece curPiece = boardPiece as Match3BoardPiece; // Skip this board piece. if ( curPiece.Tile == null || curPiece.IsBlocked /*|| !(curPiece.Tile as Match3Tile).CanBeMatched*/ || !curPiece.Tile.IsUserMoveable || curPiece.Tile.IsDestroying || (curPiece.Tile as NormalTile).IsTileSwitching || (curPiece.Tile as NormalTile).IsFrozen() ) { return true; } // Clear partial matches buffers ClearPartialMatchesBuffers(); // If the current board piece we're on is a special trigger tile, add it to the trigger tiles bag in case we find another one around it. if (curPiece.Tile is TriggerTile) { triggerTileMatchFound.Add(curPiece.Tile as Match3Tile); } // Go to maximum 2 recursive neighbors (in each of the 4 directions) and check if they match. // If the first neighbor in the current direction doesn't match the next neighbor then don't add the 2nd neighbor in the // "partialTileMatches" buffer and only add the first one. Otherwise, add them both if they match. for(int i = 0; i < dirIndices.Length; i++) { if ( !FindMatchingNeighborPiecesFor(curPiece, dirIndices[i]) ) { return false; } } return true; }
protected void AddSelection(AbstractBoardPiece boardPiece) { Transform selection = null; // Debug.LogWarning("Add selection: " + boardPiece.BoardPosition.row + " " + boardPiece.BoardPosition.col); if(!selectionList.Contains(boardPiece)) { selection = (GameObject.Instantiate(prefabSelectionEffect) as GameObject).transform; selection.parent = boardPiece.cachedTransform; selection.localPosition = new Vector3(0f, 0f, -1f); selection.animation["effect_nextitem3"].speed = selectionAnimationSpeed; if (!(boardPiece is EmptyBoardPiece)) { selectionCount++; } } selectionEffectList.Add(selection); selectionList.Add(boardPiece); }
/// <summary> /// Find and mark the board pieces that are the border of the current board. /// </summary> public void MarkBoardBounds() { int halfNumCols = (int)(NumColumns * 0.5f); int halfNumRows = (int)(NumRows * 0.5f); bool foundLeftBorder = false; bool foundRightBorder = false; bool[] foundTopRowBorder = new bool[NumColumns]; bool[] foundBottomRowBorder = new bool[NumColumns]; for (int i = 0; i < NumColumns; i++) { foundTopRowBorder[i] = foundBottomRowBorder[i] = false; } // Determine the border pieces of the level in one sweep of the grid. // Horizontal search for border tiles. for (int rowIdx = 0; rowIdx < NumRows; rowIdx++) { // Assume we didn't find any new horizontal border pieces on the current row. foundLeftBorder = foundRightBorder = false; int bottomRowIdx = NumRows - rowIdx - 1; // Debug.Log("bottomRowIdx = " + bottomRowIdx); // Horizontal search columns on the current row for the first non-empty board piece and mark it as a border piece. for (int colIdx = 0; colIdx < NumColumns; colIdx++) { int rightColIdx = NumColumns - colIdx - 1; if (rightColIdx < halfNumCols) { rightColIdx = halfNumCols; } AbstractBoardPiece leftBoardPiece = grid[rowIdx, colIdx]; AbstractBoardPiece rightBoardPiece = grid[rowIdx, rightColIdx]; if (!foundLeftBorder && !leftBoardPiece.IsEmpty) { // Mark that we've found a new left border piece on the current column. leftBoardPiece.IsBorderPiece = true; foundLeftBorder = true; } if (!foundRightBorder && !rightBoardPiece.IsEmpty) { // Mark that we've found a right border piece on the current column. rightBoardPiece.IsBorderPiece = true; foundRightBorder = true; } if (!foundTopRowBorder[colIdx] && rowIdx <= halfNumRows && !leftBoardPiece.IsEmpty) { // Mark that we've found a new top border piece on the current column. foundTopRowBorder[colIdx] = true; leftBoardPiece.IsBorderPiece = true; } if (!foundBottomRowBorder[colIdx] && bottomRowIdx > halfNumRows && !leftBoardPiece.IsEmpty) { // Mark that we've found a new bottom border piece on the current column. foundBottomRowBorder[colIdx] = true; grid[bottomRowIdx, colIdx].IsBorderPiece = true; } } } }
/// <summary> /// Determines whether this board piece is on the same row/column with the other specified board piece. /// </summary> /// <returns> /// <c>true</c> if this instance is collinear with the specified other; otherwise, <c>false</c>. /// </returns> /// <param name='other'> /// If set to <c>true</c> other. /// </param> public bool IsCollinearWith(AbstractBoardPiece other) { return(BoardPosition.row == other.BoardPosition.row || BoardPosition.col == other.BoardPosition.col); }
public void MoveTileTo(AbstractBoardPiece dstBoardPiece) { dstBoardPiece.Tile = Tile; Tile = null; }
public override bool CanMoveAt(AbstractBoardPiece targetBoardPiece) { bool canMove = base.CanMoveAt(targetBoardPiece) && !IsFrozen(); // if ( !canMove ) { // Debug.LogWarning(this.name + " tile can't be moved to: " + targetBoardPiece); // } return canMove; }
/// <summary> /// Determines whether this tile is adjacent to the specified targetBoardPiece. /// This method can be made virtual so other tiles can "fool" the game into thinking that a tile could "jump-switch" with /// another tile further from it. /// </summary> /// <returns> /// <c>true</c> if this tile is adjacent to the specified targetBoardPiece; otherwise, <c>false</c>. /// </returns> /// <param name='targetBoardPiece'> /// If set to <c>true</c> target board piece. /// </param> // public bool IsAdjacentTo(AbstractBoardPiece targetBoardPiece) { // return BoardPiece.IsAdjacentTo(targetBoardPiece); // } /// <summary> /// Determines whether this tile can move at the specified targetBoardPiece. /// </summary> /// <returns> /// <c>true</c> if this instance can move at the specified targetBoardPiece; otherwise, <c>false</c>. /// </returns> /// <param name='targetBoardPiece'> /// If set to <c>true</c> target board piece. /// </param> public virtual bool CanMoveAt(AbstractBoardPiece targetBoardPiece) { if (Board == null) { Debug.LogError("Tile " + name + " has no BoardData reference!"); } if (targetBoardPiece == null) { return false; } // BoardCoord targetBoardPos = targetBoardPiece.BoardPosition; // // // Do board coordinates sanity check first. // if (targetBoardPos.row < 0 || targetBoardPos.col < 0 || targetBoardPos.row >= Board.NumRows || targetBoardPos.col >= Board.NumColumns) { // return false; // } bool canMove = !IsMoving && IsUserMoveable && BoardPiece.IsAdjacentTo(targetBoardPiece) && !IsDestroying; return canMove; }
protected IEnumerator RaiseTileSpawnEventNextFrame(AbstractBoardPiece sender, AbstractTile newtile) { yield return(null); OnBoardPieceTileChanged(sender, newtile); }
protected void CheckBoardTouch(Vector3 position, CustomInput.TouchInfo touchInfo) { boardCoord = ConvertToBoardCoord(position); if(boardCoord.row < 0 || boardCoord.row >= Match3BoardRenderer.Instance.Board.NumRows || boardCoord.col < 0 || boardCoord.col >= Match3BoardRenderer.Instance.Board.NumColumns) { return; } CustomInput.TouchInfo modifiedTouchInfo = new CustomInput.TouchInfo(touchInfo); modifiedTouchInfo.position = position; if(prevBoardCoord != boardCoord) { boardPiece = Match3BoardRenderer.Instance.Board[boardCoord.row, boardCoord.col]; RaiseOnNewBoardPieceSelected(boardPiece, modifiedTouchInfo); prevBoardCoord = boardCoord; } }
protected void OnNewBoardPieceSelected(AbstractBoardPiece boardPiece, CustomInput.TouchInfo touchInfo) { // Debug.LogWarning("[OnNewBoardPieceSelect]"); if(BoardShuffleController.Instance.IsBoardReshuffling) { return; } if(startPosition == Vector3.zero) { startPosition = boardPiece.cachedTransform.position; } else { endPosition = boardPiece.cachedTransform.position; } }
public virtual bool CanMoveTile(AbstractTile tile, AbstractBoardPiece targetBoardPiece) { // In case we're trying to do a switch with the same tile. (failed input or reached board margin) if (tile.BoardPiece == targetBoardPiece) { // Debug.LogWarning("[Match3BoardGameLogic] Trying to move tile " + tile.name + " in the same board piece as the tile: " + targetBoardPiece); return false; } // Safety-check in case we might try to move a tile to a board piece which has no tile on it to switch with. // In case we will want this mechanic later in the game we will let the tile decide if it can move to an empty board piece or not. if (targetBoardPiece.Tile == null) { // Debug.LogError("[Match3BoardGameLogic] In method CanMoveTile: " + tile.name + " error: targetBoardPiece doesn't have any tile to switch with!"); return false; } // Check if tiles can switch positions. return tile.CanMoveAt(targetBoardPiece) && targetBoardPiece.Tile.CanMoveAt(tile.BoardPiece); }
/// <summary> /// Determines whether this board piece is on the same row/column with the other specified board piece. /// </summary> /// <returns> /// <c>true</c> if this instance is collinear with the specified other; otherwise, <c>false</c>. /// </returns> /// <param name='other'> /// If set to <c>true</c> other. /// </param> public bool IsCollinearWith(AbstractBoardPiece other) { return BoardPosition.row == other.BoardPosition.row || BoardPosition.col == other.BoardPosition.col; }
/// <summary> /// Determines whether this board piece is adjacent in any of the 8 directions to the specified target board piece. /// </summary> /// <returns> /// <c>true</c> if this instance is area adjacent to the specified targetBoardPiece; otherwise, <c>false</c>. /// </returns> /// <param name='targetBoardPiece'> /// If set to <c>true</c> target board piece. /// </param> public bool IsAreaAdjacentTo(AbstractBoardPiece targetBoardPiece) { if (targetBoardPiece == null) { return false; } BoardCoord offset = BoardPosition - targetBoardPiece.BoardPosition; offset.row = Mathf.Abs(offset.row); offset.col = Mathf.Abs(offset.col); return offset.row == 0 && offset.col == 1 || offset.row == 1 && offset.col == 0 || offset.row == 1 && offset.col == 1; }