Пример #1
0
    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;
        }
    }
Пример #2
0
    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);
    }
Пример #3
0
 public void OnAnimationFinished(Chuzzle chuzzle)
 {
     chuzzle.AnimationFinished -= OnAnimationFinished;
     AnimatedChuzzles.Remove(chuzzle);
     if (!AnimatedChuzzles.Any())
     {
         Gamefield.SwitchStateTo(Gamefield.WinCreateNewChuzzlesState);
     }
 }
Пример #4
0
    private void OnAnimationFinished(Chuzzle chuzzle)
    {
        chuzzle.AnimationFinished -= OnAnimationFinished;
        AnimatedChuzzles.Remove(chuzzle);

        chuzzle.Destroy(true, false);

        if (!AnimatedChuzzles.Any())
        {
            Gamefield.SwitchStateTo(Gamefield.WinCreateNewChuzzlesState);
        }
    }
Пример #5
0
    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);
        }
    }
Пример #6
0
    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);
    }
Пример #7
0
    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);
        }
    }
Пример #8
0
    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);
            }
        }
    }
Пример #10
0
    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());
    }
Пример #11
0
 public override void OnEnter()
 {
     Gamefield.Reset();
     Gamefield.InvokeGameStarted();
     Gamefield.SwitchStateTo(Gamefield.CheckSpecialState);
 }