public void OnAnimationFinished(Chuzzle chuzzle) { chuzzle.Real = chuzzle.Current = chuzzle.MoveTo; chuzzle.AnimationFinished -= OnAnimationFinished; AnimatedChuzzles.Remove(chuzzle); if (isAlreadyChangedState) { Debug.LogWarning("Finished in CRNC state "); } if (!AnimatedChuzzles.Any() && !isAlreadyChangedState) { Gamefield.Level.UpdateActive(); var combinations = GamefieldUtility.FindCombinations(Gamefield.Level.ActiveChuzzles); if (combinations.Count > 0) { Gamefield.SwitchStateTo(Gamefield.CheckSpecialState); } else { if (!Gamefield.GameMode.IsWin && !Gamefield.GameMode.IsGameOver) { Gamefield.SwitchStateTo(Gamefield.FieldState); } else { Gamefield.GameMode.Check(); } } isAlreadyChangedState = true; } }
public bool CreateNew() { var hasNew = Gamefield.NewTilesInColumns.Any(x => x > 0); if (!hasNew) { Gamefield.SwitchStateTo(Gamefield.CheckSpecialState); return(false); } //check if need create new tiles for (var x = 0; x < Gamefield.NewTilesInColumns.Length; x++) { var newInColumn = Gamefield.NewTilesInColumns[x]; if (newInColumn > 0) { for (var j = 0; j < newInColumn; j++) { //create new tiles var chuzzle = TilesFactory.Instance.CreateChuzzle(Gamefield.Level.GetCellAt(x, Gamefield.Level.Height + j)); chuzzle.Current.IsTemporary = true; } } } //move tiles to fill positions for (var x = 0; x < Gamefield.NewTilesInColumns.Length; x++) { var newInColumn = Gamefield.NewTilesInColumns[x]; if (newInColumn > 0) { for (var y = 0; y < Gamefield.Level.Height; y++) { var cell = Gamefield.Level.GetCellAt(x, y, false); if (Gamefield.Level.At(x, y) == null && cell.Type != CellTypes.Block) { while (cell != null) { var chuzzle = Gamefield.Level.At(cell.x, cell.y); if (chuzzle != null) { chuzzle.MoveTo = chuzzle.MoveTo.GetBottomWithType(); //Level.GetCellAt(chuzzle.MoveTo.x, chuzzle.MoveTo.y - 1); } cell = cell.Top; } } } } } foreach (var c in Gamefield.Level.Chuzzles) { if (c.MoveTo.y != c.Current.y) { c.AnimateMoveTo(c.MoveTo.Position); } } return(true); }
public void OnAnimationFinished(Chuzzle chuzzle) { chuzzle.AnimationFinished -= OnAnimationFinished; AnimatedChuzzles.Remove(chuzzle); if (!AnimatedChuzzles.Any()) { Gamefield.SwitchStateTo(Gamefield.WinCreateNewChuzzlesState); } }
private void OnAnimationFinished(Chuzzle chuzzle) { chuzzle.AnimationFinished -= OnAnimationFinished; AnimatedChuzzles.Remove(chuzzle); chuzzle.Destroy(true, false); if (!AnimatedChuzzles.Any()) { Gamefield.SwitchStateTo(Gamefield.WinCreateNewChuzzlesState); } }
public override void OnEnter() { AnimatedChuzzles.Clear(); Chuzzle.DropEventHandlers(); Chuzzle.AnimationStarted += OnAnimationStarted; var combinations = GamefieldUtility.FindCombinations(Gamefield.Level.ActiveChuzzles); if (!CheckForSpecial(combinations)) { Gamefield.SwitchStateTo(Gamefield.WinRemoveCombinationState); } }
IEnumerator CreateNewPowerUps(List <Chuzzle> newPowerUps) { yield return(new WaitForSeconds(1f)); foreach (Chuzzle ch in newPowerUps) { ch.Explosion = TileReplaceEffect; ch.Destroy(false); yield return(new WaitForSeconds(0.5f)); TilesFactory.Instance.CreateBomb(ch.Current); } Gamefield.SwitchStateTo(Gamefield.WinRemoveCombinationState); }
public override void OnEnter() { AnimatedChuzzles.Clear(); Chuzzle.DropEventHandlers(); Chuzzle.AnimationStarted += OnAnimationStarted; var anyCombination = GamefieldUtility.FindOnlyOneCombination(Gamefield.Level.ActiveChuzzles); if (anyCombination.Any()) { StartCoroutine(RemoveCombinations()); } else { Gamefield.SwitchStateTo(Gamefield.FieldState); } }
public void CheckCombinations() { var combinations = GamefieldUtility.FindCombinations(Gamefield.Level.ActiveChuzzles); if (combinations.Any() && (!Tutorial.isActive || (Tutorial.isActive && CurrentChuzzle != null && Tutorial.instance.IsTargetCell(CurrentChuzzle.Real)))) { foreach (var c in Gamefield.Level.Chuzzles) { c.MoveTo = c.Current = c.Real; } Gamefield.SwitchStateTo(Gamefield.CheckSpecialState); Reset(); } else { if (CurrentChuzzle != null) { StartReturn(); } } }
public void OnAnimationFinished(Chuzzle chuzzle) { chuzzle.Real = chuzzle.Current = chuzzle.MoveTo; chuzzle.AnimationFinished -= OnAnimationFinished; AnimatedChuzzles.Remove(chuzzle); if (!AnimatedChuzzles.Any()) { Gamefield.Level.UpdateActive(); var combinations = GamefieldUtility.FindCombinations(Gamefield.Level.ActiveChuzzles); if (combinations.Count > 0) { Gamefield.SwitchStateTo(Gamefield.WinCheckSpecialState); } else { Gamefield.SwitchStateTo(Gamefield.WinRemoveCombinationState); } } }
private IEnumerator RemoveCombinations() { var powerUpCombination = GamefieldUtility.FindOnlyOneCombinationWithCondition(Gamefield.Chuzzles, GamefieldUtility.IsPowerUp); //if has any powerups if (powerUpCombination.Any()) { //destroy step by step PowerUpDestroyManager.Instance.Destroy(powerUpCombination); if (!AnimatedChuzzles.Any()) { Gamefield.SwitchStateTo(Gamefield.CreateNewChuzzlesState); } } else { var combinations = GamefieldUtility.FindCombinations(Gamefield.Chuzzles); //remove combinations foreach (var combination in combinations) { Gamefield.InvokeCombinationDestroyed(combination); foreach (var chuzzle in combination) { chuzzle.Destroy(true); } if (!AnimatedChuzzles.Any()) { Gamefield.SwitchStateTo(Gamefield.CreateNewChuzzlesState); } yield return(new WaitForSeconds(0.05f)); } } yield return(new WaitForEndOfFrame()); }
public override void OnEnter() { Gamefield.Reset(); Gamefield.InvokeGameStarted(); Gamefield.SwitchStateTo(Gamefield.CheckSpecialState); }