void Start() { longestMatchFinder.board = board; matches = new PieceMatches(); board.OnBoardStateChanged += OnTurn; board.OnBoardStateChanged += EvaluateFailState; }
// instantly remove all pieces in the given match set public void RemovePieces(PieceMatches matches) { foreach (MatchData match in matches) { RemovePiece(match); } }
// Remove a set of pieces from the board in a timed sequence IEnumerator RemoveSequenceCoroutine(PieceMatches matches) { int i = 0; int scoreIndex = 0; foreach (MatchData match in matches) { Debug.Assert(match.piece != null); // inform game of this so that scores can be added etc. game.OnPiecePopped(match.piece, scoreIndex); int x = match.x; int y = match.y; Debug.Assert(tiles[x, y].contents != null); // return the piece to the pile - it'll get deactivated here, and reset when next requested piecesPool.Return(tiles[x, y].contents.gameObject); // tile no longer contains a piece tiles[x, y].contents = null; // To cause the particles to burst again they need to be stopped / moved / started particles.Stop(false, ParticleSystemStopBehavior.StopEmitting); particles.transform.position = tiles[x, y].transform.position; particles.Play(); // pop sound randomPitchSources.GetRandom().PlayOneShot(pieceExplodeSound, popVolume); yield return(removeTileDelayWaiters[i]); // wait gets shorter with each pop so it speeds up i = Mathf.Min(i + 1, removeWaiterArraySize - 1); // next score scoreIndex++; } // drop all the floating pieces now ShuffleDown(true); // all done - let whoever wants to know know if (OnBoardStateChanged != null) { OnBoardStateChanged.Invoke(); } if (OnRemovePiecesSequenceComplete != null) { OnRemovePiecesSequenceComplete.Invoke(); } }
public void RemoveSequence(PieceMatches matches) { StartCoroutine(RemoveSequenceCoroutine(matches)); }