public void RaiseBoardShuffleRequiredEvent() { Match3BoardGameLogic.Instance.unstableLock++; IsBoardReshuffling = true; if (OnBoardShuffleRequired != null) { OnBoardShuffleRequired(); } OnReshuffleRequired.RaiseEvent(); // Debug.LogWarning("[BoardShuffleController] RaiseBoardShuffleRequiredEvent -> No more possible matches on the board..."); board = Match3BoardGameLogic.Instance.boardData; // Collect all board pieces containing a normal tile to prepare for shuffling. board.ApplyActionToAll((boardPiece) => { // Only re-shuffle normal tiles if (boardPiece.Tile != null && boardPiece.Tile.GetType() == typeof(NormalTile) && !boardPiece.Tile.IsDestroying) { piecesToReshuffle.Add(boardPiece as Match3BoardPiece); // Disable the tiles logic before starting the re-shuffle boardPiece.Tile.enabled = false; } }); // Disable tile switching input TileSwitchInput.Instance.DisableInput(); StartReshuffleTilesAnim(); }
IEnumerator DestroyAllTriggerTiles() { List <TriggerTile> allTriggerTiles = new List <TriggerTile>(65); bool keepLooking = true; while (keepLooking || !IsBoardStable) { allTriggerTiles.Clear(); boardData.ApplyActionToAll((boardPiece) => { TriggerTile tile = boardPiece.Tile as TriggerTile; if (tile != null && tile.IsDestructible && !tile.IsDestroying) { allTriggerTiles.Add(tile); } }); if (allTriggerTiles.Count > 0) { if (callFreeFallEvent) { callFreeFallEvent = false; OnFreeFall.RaiseEvent(); yield return(new WaitForSeconds(2f)); } int index = Random.Range(0, allTriggerTiles.Count); TriggerTile chosenTile = allTriggerTiles[index]; allTriggerTiles.RemoveAt(index); chosenTile.Destroy(); IsBoardStable = false; TryCheckStableBoard(); yield return(new WaitForSeconds(1.5f)); keepLooking = true; } else { keepLooking = false; yield return(null); } } }
protected void FreeFallFinished() { OnStableBoard -= FreeFallFinished; freeFalling = false; SendEndGameAnalytics(); WinLoseRaiseEvent.RaiseEvent(); }
public void OnLoseChecked() { OnLosePending.RaiseEvent(); IsBoardStable = false; TryCheckStableBoard(); OnStableBoard += StableBoardLose; IsGameOver = true; }
public void OnWinChecked() { loseConditions.Pause(true); OnWinPending.RaiseEvent(); IsBoardStable = false; TryCheckStableBoard(); OnStableBoard += StableBoardWin; IsGameOver = true; }
protected void StableBoardLose() { levelWon = false; OnStableBoard -= StableBoardLose; WinLoseRaiseEvent = OnLoseFinished; if (winConditions.GetType() == typeof(WinScore)) { callFreeFallEvent = true; StartCoroutine(FreeFall()); } else { SendEndGameAnalytics(); OnLoseFinished.RaiseEvent(); } }
//TODO: temporary test method for intro anim public void StartIntroAnim() { // Tweener lastTweener = null; // for(int i = 0; i < boardData.NumColumns; i++) { // boardData.ApplyActionToColumn(i, (boardPiece) => { // Vector3 animateToPos = boardPiece.LocalPosition; // if (boardPiece.Tile != null) { // boardPiece.Tile.cachedTransform.Translate(0f, 20f, 0); // boardPiece.Tile.enabled = false; // (boardPiece.Tile as Match3Tile).GravityEnabled = false; // // lastTweener = HOTween.To(boardPiece.Tile.cachedTransform, 1.5f, // new TweenParms().Prop("localPosition", animateToPos) // .Ease(EaseType.EaseOutElastic, 0f, 1.3f).Delay(i / 7.5f)); // } // }); // } // // if (lastTweener == null) { // Debug.LogError("No tiles to animate!"); // } else { // lastTweener.ApplyCallback(CallbackType.OnComplete, () => { // boardData.ApplyActionToAll((boardPiece) => { // if (boardPiece.Tile != null) { // boardPiece.Tile.enabled = true; // (boardPiece.Tile as Match3Tile).GravityEnabled = true; // } // }); // //// (lastTweener.target as Transform).GetComponent<AbstractTile>().enabled = true; // Debug.Log("Finished Intro Anim!"); // if (OnIntroAnimFinished != null) { OnIntroAnimFinished(this); } OnBoardIntroAnimFinished.RaiseEvent(); // }); // } }
protected void ReshuffleTiles() { // Re-shuffle tiles for (int i = 0; i < piecesToReshuffle.Count; i++) { int randomIdx = Random.Range(0, piecesToReshuffle.Count); if (randomIdx != i) { // Switch tiles Match3Tile tempTile = piecesToReshuffle[i].Tile as Match3Tile; piecesToReshuffle[i].Tile = piecesToReshuffle[randomIdx].Tile; piecesToReshuffle[randomIdx].Tile = tempTile; } } int numTries = 0; matchesUndoer.OnNewTileSpawned = (newTile) => { newTile.tileModelTransform.localScale = Vector3.zero; newTile.enabled = false; }; possibleMatchGenerator.OnNewTileSpawned = (newTile) => { newTile.tileModelTransform.localScale = Vector3.zero; newTile.enabled = false; }; matchFailed = true; while ((numTries++) < 10 && (matchesUndoer.FindMatchesAndUndo(false) || numTries == 1)) { // Debug.Log("Board shuffle re-tries: " + numTries); matchFailed = !possibleMatchesFinder.FindFirstPossibleMatch(); if (matchFailed) { // Debug.LogWarning("Forcing a rematch because re-shuffle failed."); matchFailed = !possibleMatchGenerator.GenerateMatch(false); } } matchesUndoer.OnNewTileSpawned = null; possibleMatchGenerator.OnNewTileSpawned = null; // Show hidden tiles. Match3Tile tile = null; Tweener lastTween = null; // if(piecesToReshuffle.Count == 0) { // Debug.LogWarning("[piecesToReshuffle.Count] " + piecesToReshuffle.Count); // } for (int i = 0; i < piecesToReshuffle.Count; i++) { tile = piecesToReshuffle[i].Tile as Match3Tile; piecesToReshuffle[i].ResetTilePosition(); if (tile != null) { // Position the effect // effectReshuffle.position = tile.cachedTransform.position; //cachedParticleSystem.Emit(Random.Range(minNumParticles, maxNumParticles)); lastTween = HOTween.To(tile.tileModelTransform, 0.5f, new TweenParms() .Prop("localScale", Vector3.one) .Ease(EaseType.EaseOutQuad)); // if (lastTween == null) { // Debug.LogWarning("Last tween is NULL!!!"); // } } // else { // Debug.LogWarning("[ReshuffleTiles] In show tiles anim Boardpiece has NULL tile = " + piecesToReshuffle[i]); // } } if (lastTween != null) { lastTween.ApplyCallback(CallbackType.OnComplete, () => { RaiseBoardShuffleFinishedEvent(); OnReshuffleFinished.RaiseEvent(); }); } else { RaiseBoardShuffleFinishedEvent(); OnReshuffleFinished.RaiseEvent(); // Debug.LogWarning("[StartReshuffleTilesAnim] Error lastTween is NULL"); } }