Beispiel #1
0
    private void Update()
    {
        if (!ELSingleton <PopUpManager> .Instance.IsActiveAndEnabled() && UnityEngine.Input.GetKeyDown(KeyCode.Escape))
        {
            BackButton();
        }
        if (delay <= 0f)
        {
            switch (state)
            {
            case State.LoadNormal:
            case State.ReloadNormal:
                LoadLevel(LevelType.Normal);
                if (!isMusicPlaying)
                {
                    ELSingleton <MusicManager> .Instance.PlayGameNormal();

                    isMusicPlaying = true;
                }
                background.Reset(LevelType.Normal, pack.index);
                if (state == State.LoadNormal)
                {
                    if (IsHowToPlayPopUp)
                    {
                        IsHowToPlayPopUp = false;
                        ELSingleton <HowToPlayPopUp> .Instance.ShowPopUp(0.5f);

                        ELSingleton <ApplicationSettings> .Instance.Save();

                        SetState(State.Idle);
                    }
                    else
                    {
                        SetState(State.ShowLoadNormal);
                    }
                }
                else
                {
                    SetState(State.ShowReloadNormal);
                }
                ELSingleton <AnalyticsManager> .Instance.LevelStart((level.number + 1).ToString());

                ELSingleton <NotificationsManager> .Instance.RegisterNotifications(pack.index, level.index);

                break;

            case State.ShowLoadNormal:
                board.Enable(2.5f);
                board.ShowFill(2f);
                board.ShowWords(2.1f);
                board.ShowIcon(2.2f);
                board.wordText.Show(2.3f);
                if (!isLevelCompleted && background.HasLadyBug())
                {
                    ladybug.Show();
                }
                else
                {
                    ladybug.Reset();
                }
                levelText.Show(2.5f);
                categoryText.Show(0.2f);
                backButton.Enable(2.5f);
                backButton.Show(2.5f);
                shopButton.Enable(2.5f);
                shopButton.Show(2.5f);
                if (!level.isCompleted)
                {
                    extraWordsButton.Enable(2.5f);
                    extraWordsButton.Show(2.5f);
                    perfectMeter.Show(2.5f);
                }
                hintBar.Set(level);
                if (ELSingleton <HintManager> .Instance.IsHintAvailable(LevelHint.GoodStart, level.number))
                {
                    goodStartButton.Enable(2.5f);
                    goodStartButton.Show(2.5f);
                }
                if (ELSingleton <HintManager> .Instance.IsHintAvailable(LevelHint.StartAndFinish, level.number))
                {
                    startAndFinishButton.Enable(2.5f);
                    startAndFinishButton.Show(2.5f);
                }
                if (ELSingleton <HintManager> .Instance.IsHintAvailable(LevelHint.Expose, level.number))
                {
                    exposeButton.Enable(2.5f);
                    exposeButton.Show(2.5f);
                }
                if (ELSingleton <HintManager> .Instance.IsHintAvailable(LevelHint.Tip, level.number))
                {
                    tipButton.Enable(2.5f);
                    tipButton.Show(2.5f);
                }
                SetState(State.Play, 2.5f);
                break;

            case State.ShowReloadNormal:
                board.Enable(2.5f);
                board.ShowFill(2f);
                board.ShowWords(2.1f);
                board.ShowIcon(2.2f);
                board.wordText.Show(2.3f);
                levelText.Show(2.5f);
                categoryText.Show(0.2f);
                backButton.Enable();
                shopButton.Enable(2.5f);
                if (!level.isCompleted)
                {
                    extraWordsButton.Enable(2.5f);
                    perfectMeter.Show(2.5f);
                }
                hintBar.Set(level, 2.2f);
                if (ELSingleton <HintManager> .Instance.IsHintAvailable(LevelHint.GoodStart, level.number))
                {
                    goodStartButton.Enable(2.5f);
                    goodStartButton.Show(2.5f);
                }
                if (ELSingleton <HintManager> .Instance.IsHintAvailable(LevelHint.StartAndFinish, level.number))
                {
                    startAndFinishButton.Enable(2.5f);
                    startAndFinishButton.Show(2.5f);
                }
                if (ELSingleton <HintManager> .Instance.IsHintAvailable(LevelHint.Expose, level.number))
                {
                    exposeButton.Enable(2.5f);
                    exposeButton.Show(2.5f);
                }
                if (ELSingleton <HintManager> .Instance.IsHintAvailable(LevelHint.Tip, level.number))
                {
                    tipButton.Enable(2.5f);
                    tipButton.Show(2.5f);
                }
                SetState(State.Play, 2.5f);
                break;

            case State.LoadBonusRound:
                LoadLevel(LevelType.BonusRound);
                if (!isMusicPlaying)
                {
                    ELSingleton <MusicManager> .Instance.PlayGameSpecial();

                    isMusicPlaying = true;
                }
                background.Reset(LevelType.BonusRound, -1);
                ladybug.Reset();
                levelText.Hide();
                categoryText.Hide();
                extraWordsButton.Disable();
                extraWordsButton.Hide();
                extraWordsButton.FullParticleStop();
                perfectMeter.Hide();
                goodStartButton.Disable();
                goodStartButton.Hide();
                startAndFinishButton.Disable();
                startAndFinishButton.Hide();
                exposeButton.Disable();
                exposeButton.Hide();
                tipButton.Disable();
                tipButton.Hide();
                tipText.Hide();
                specialWelcome.Show(LevelType.BonusRound, 0.5f);
                SetState(State.Idle);
                ELSingleton <AnalyticsManager> .Instance.LevelStart("bonus_round");

                break;

            case State.ShowBonusRound:
                board.Enable(1f);
                board.ShowFill(0.5f);
                board.ShowWords(0.6f);
                board.ShowIcon(0.7f);
                board.wordText.Show(0.8f);
                levelText.Show(1f);
                backButton.Enable(1f);
                backButton.Show(1f);
                shopButton.Enable(1f);
                shopButton.Show(1f);
                timeMeter.Show(1f);
                SetState(State.Play, 1f);
                break;

            case State.LoadDailyPuzzle:
                LoadLevel(LevelType.DailyPuzzle);
                if (!isMusicPlaying)
                {
                    ELSingleton <MusicManager> .Instance.PlayGameSpecial();

                    isMusicPlaying = true;
                }
                background.Reset(LevelType.DailyPuzzle, -2);
                ladybug.Reset();
                specialWelcome.Show(LevelType.DailyPuzzle, 0.5f);
                SetState(State.Idle);
                ELSingleton <AnalyticsManager> .Instance.LevelStart("daily_puzzle");

                break;

            case State.ShowDailyPuzzle:
                board.Enable(2.5f);
                board.ShowFill(2f);
                board.ShowWords(2.1f);
                board.ShowIcon(2.2f);
                board.wordText.Show(2.3f);
                levelText.Show(2.5f);
                categoryText.Show(0.2f);
                backButton.Enable(2.5f);
                backButton.Show(2.5f);
                shopButton.Enable(2.5f);
                shopButton.Show(2.5f);
                if (!level.isCompleted)
                {
                    extraWordsButton.Enable(2.5f);
                    extraWordsButton.Show(2.5f);
                    perfectMeter.Show(2.5f);
                }
                hintBar.Set(level);
                if (ELSingleton <HintManager> .Instance.IsHintAvailable(LevelHint.GoodStart, level.number))
                {
                    goodStartButton.Enable(2.5f);
                    goodStartButton.Show(2.5f);
                }
                if (ELSingleton <HintManager> .Instance.IsHintAvailable(LevelHint.StartAndFinish, level.number))
                {
                    startAndFinishButton.Enable(2.5f);
                    startAndFinishButton.Show(2.5f);
                }
                if (ELSingleton <HintManager> .Instance.IsHintAvailable(LevelHint.Expose, level.number))
                {
                    exposeButton.Enable(2.5f);
                    exposeButton.Show(2.5f);
                }
                if (ELSingleton <HintManager> .Instance.IsHintAvailable(LevelHint.Tip, level.number))
                {
                    tipButton.Enable(2.5f);
                    tipButton.Show(2.5f);
                }
                SetState(State.Play, 2.5f);
                break;

            case State.Play:
                if (categoryText.IsShowEnded && Time.timeScale > 1f)
                {
                    Time.timeScale = 1f;
                }
                if (!ELSingleton <PopUpManager> .Instance.IsActiveAndEnabled())
                {
                    Tutorial tutorial = ELSingleton <TutorialManager> .Instance.CheckTrigger(level.type, level.number, level.stats.isPerfect&& level.stats.valid > 0, board.wordText.IsDictionary, board.Result == Board.WordCheckResult.ExtraWord);

                    if (tutorial != null)
                    {
                        ELSingleton <TutorialWindow> .Instance.Show(tutorial, (tutorial.type == TutorialType.GoodStart)?(hintBar.transform.localPosition + goodStartButton.PositionTarget) : ((tutorial.type == TutorialType.StartAndFinish) ? (hintBar.transform.localPosition + startAndFinishButton.PositionTarget) : ((tutorial.type == TutorialType.Expose) ? (hintBar.transform.localPosition + exposeButton.PositionTarget) : ((tutorial.type == TutorialType.Tip) ? (hintBar.transform.localPosition + tipButton.PositionTarget) : ((tutorial.type == TutorialType.Perfect) ? perfectMeter.transform.localPosition : ((tutorial.type == TutorialType.Dictionary) ? (board.transform.localPosition + board.wordText.transform.localPosition * board.transform.localScale.x) : ((tutorial.type == TutorialType.Shop) ? shopButton.transform.localPosition : ((tutorial.type == TutorialType.ExtraWord) ? extraWordsButton.transform.localPosition : Vector3.zero))))))));
                    }
                }
                if (level.type == LevelType.Normal && board.IsComplete())
                {
                    board.Disable();
                    backButton.Disable();
                    shopButton.Disable();
                    extraWordsButton.Disable();
                    goodStartButton.Disable();
                    startAndFinishButton.Disable();
                    exposeButton.Disable();
                    tipButton.Disable();
                    tipText.Hide();
                    if (!isLevelCompleted)
                    {
                        if (isLastLevelInPack)
                        {
                            ELSingleton <CoinsManager> .Instance.AddCoins(ELSingleton <XmlSettings> .Instance.coinsConfig.pack);
                        }
                        isPerfect = level.stats.isPerfect;
                        if (level.stats.isPerfect)
                        {
                            ELSingleton <CoinsManager> .Instance.AddCoins(ELSingleton <XmlSettings> .Instance.coinsConfig.perfect);
                        }
                    }
                    LevelStats levelStats = new LevelStats(level.stats);
                    ELSingleton <LevelSuccessPopUp> .Instance.ShowPopUp(level.type, level.stats, isLastLevelInPack, isLevelCompleted, levelStats, board.HasCoins()? 1.5f : 0.5f);

                    ELSingleton <LevelsSettings> .Instance.levelSet.CompleteLevel(aIsCompleteLevel : true);

                    ELSingleton <AnalyticsManager> .Instance.LevelComplete((level.number + 1).ToString(), new Dictionary <string, object>
                    {
                        {
                            "extra_words",
                            levelStats.pointsExtra
                        }
                    });

                    SetState(State.Idle);
                }
                else if (level.type == LevelType.BonusRound && timeMeter.TimeCurrent <= 0f)
                {
                    board.Disable();
                    board.HideWords();
                    board.wordText.Hide(0.3f);
                    board.HideFill(0.5f);
                    board.HideIcon(0.5f);
                    shopButton.Disable();
                    extraWordsButton.Disable();
                    goodStartButton.Disable();
                    startAndFinishButton.Disable();
                    exposeButton.Disable();
                    tipButton.Disable();
                    tipText.Hide();
                    LevelStats levelStats2 = new LevelStats(level.stats);
                    ELSingleton <LevelSuccessPopUp> .Instance.ShowPopUp(level.type, level.stats, aIsLastLevelInPack : false, aIsLevelCompleted : false, levelStats2, 0.5f);

                    ELSingleton <AnalyticsManager> .Instance.LevelComplete("bonus_round", new Dictionary <string, object>
                    {
                        {
                            "extra_words",
                            levelStats2.pointsExtra
                        }
                    });

                    SetState(State.Idle);
                }
                else if (level.type == LevelType.DailyPuzzle && board.IsComplete())
                {
                    board.Disable();
                    board.HideWords();
                    board.wordText.Hide(0.3f);
                    board.HideFill(0.5f);
                    board.HideIcon(0.5f);
                    shopButton.Disable();
                    extraWordsButton.Disable();
                    goodStartButton.Disable();
                    startAndFinishButton.Disable();
                    exposeButton.Disable();
                    tipButton.Disable();
                    tipText.Hide();
                    LevelStats levelStats3 = new LevelStats(level.stats);
                    ELSingleton <LevelSuccessPopUp> .Instance.ShowPopUp(level.type, level.stats, aIsLastLevelInPack : false, aIsLevelCompleted : false, levelStats3, 0.5f);

                    ELSingleton <AnalyticsManager> .Instance.LevelComplete("daily_puzzle", new Dictionary <string, object>
                    {
                        {
                            "extra_words",
                            levelStats3.pointsExtra
                        }
                    });

                    SetState(State.Idle);
                }
                else if (board.IsWordValid)
                {
                    if (level.type == LevelType.Normal || level.type == LevelType.DailyPuzzle)
                    {
                        switch (board.CheckWordNormal(level.isCompleted))
                        {
                        case Board.WordCheckResult.Valid:
                            StatsAddValid();
                            if (!isLevelCompleted)
                            {
                                StatsAddPointsNormal(1);
                                ELSingleton <PointsManager> .Instance.AddPoints(1);
                            }
                            ELSingleton <AudioManager> .Instance.PlaySfx(soundWordValid);

                            break;

                        case Board.WordCheckResult.Invalid:
                            if (board.wordText.Text.Length >= 3)
                            {
                                StatsSetPerfect(aIsPerfect: false);
                            }
                            ELSingleton <AudioManager> .Instance.PlaySfx(soundWordInvalid);

                            break;

                        case Board.WordCheckResult.Repeat:
                            ELSingleton <AudioManager> .Instance.PlaySfx(soundWordRepeat);

                            break;

                        case Board.WordCheckResult.ExtraWord:
                            if (!ELSingleton <ExtraWordsManager> .Instance.IsFull)
                            {
                                coinPod.ReleaseExtraWord(board.wordText.transform.position, extraWordsButton.coinTarget.transform.position, 2.5f);
                                ELSingleton <ExtraWordsManager> .Instance.AddWords(1);
                            }
                            if (!isLevelCompleted)
                            {
                                StatsAddPointsExtra(1);
                                ELSingleton <PointsManager> .Instance.AddPoints(1);
                            }
                            ELSingleton <AudioManager> .Instance.PlaySfx(soundWordExtra);

                            break;
                        }
                    }
                    else if (level.type == LevelType.BonusRound)
                    {
                        switch (board.CheckWordSpecial())
                        {
                        case Board.WordCheckResult.Valid:
                            StatsAddValid();
                            StatsAddPointsNormal(1);
                            ELSingleton <PointsManager> .Instance.AddPoints(1);

                            if (level.stats.valid % 4 == 0 && specialLevelRound > 0)
                            {
                                specialLevelRound--;
                                board.SetSpecialLevelRound(specialLevelRound, aIsScaleForce: false);
                                ELSingleton <AudioManager> .Instance.PlaySfx(soundSpecialLevelRound);
                            }
                            ELSingleton <AudioManager> .Instance.PlaySfx(soundWordValid);

                            break;

                        case Board.WordCheckResult.Invalid:
                            ELSingleton <AudioManager> .Instance.PlaySfx(soundWordInvalid);

                            break;
                        }
                    }
                    board.IsWordValid = false;
                }
                if (level.type == LevelType.Normal || level.type == LevelType.DailyPuzzle)
                {
                    perfectMeter.Setup();
                }
                if (level.type == LevelType.BonusRound)
                {
                    timeMeter.Setup();
                }
                break;

            case State.ResetNormal:
                board.Reset();
                perfectMeter.Reset();
                if (isLastLevelInPack && !isLevelCompleted)
                {
                    isMusicPlaying = false;
                    SetState(State.LoadBonusRound);
                }
                else
                {
                    SetState(State.ReloadNormal);
                }
                break;

            case State.HideBonusRound:
                board.wordText.Hide(0.3f);
                board.HideFill(0.5f);
                board.HideIcon(0.5f);
                categoryText.Hide(0.5f);
                backButton.Enable();
                timeMeter.Hide(0.5f);
                SetState(State.ResetBonusRound, 1f);
                break;

            case State.ResetBonusRound:
                board.Reset();
                specialWelcome.Reset();
                SetState(State.LoadBonusRound);
                break;

            case State.HideDailyPuzzle:
                board.wordText.Hide(0.3f);
                board.HideFill(0.5f);
                board.HideIcon(0.5f);
                categoryText.Hide(0.5f);
                backButton.Enable();
                extraWordsButton.Hide(0.5f);
                goodStartButton.Hide(0.5f);
                startAndFinishButton.Hide(0.5f);
                exposeButton.Hide(0.5f);
                tipButton.Hide(0.5f);
                tipText.Hide();
                perfectMeter.Hide(0.5f);
                SetState(State.ResetDailyPuzzle, 1f);
                break;

            case State.ResetDailyPuzzle:
                board.Reset();
                perfectMeter.Reset();
                specialWelcome.Reset();
                SetState(State.LoadDailyPuzzle);
                break;
            }
        }
        delay -= Time.deltaTime;
    }