Exemplo n.º 1
0
        /// <summary>
        /// Change result of level (number of stars)
        /// </summary>
        /// <param name="btnGO"></param>
        /// <param name="resultPassing"></param>
        private void ChangeLevelButtonResult(GameObject btnGO, Level.ResultPassing resultPassing)
        {
            //Text btnText = btnGO.GetComponentInChildren<Text>();
            //btnText.text = resultPassing.ToString();

            LevelButton levelButton = btnGO.GetComponent <LevelButton>();

            switch (resultPassing)
            {
            case Level.ResultPassing.Low:
                levelButton.SetLevelStars(1);
                //Debug.Log("Low");
                break;

            case Level.ResultPassing.Middle:
                levelButton.SetLevelStars(2);
                //Debug.Log("Middle");
                break;

            case Level.ResultPassing.High:
                levelButton.SetLevelStars(3);
                //Debug.Log("High");
                break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Save result of current level, update UI and unlock next level (use after finish) and etc.
        /// </summary>
        private void FinishLevel()
        {
            Level.ResultPassing oldResult = currentLevel.currentResult;
            Level.ResultPassing newResult = GetResult();

            if (oldResult < newResult) // the newest result is better than old
            {
                currentLevel.currentResult = newResult;
                GameObject btnGO = levelBox.Find(currentLevel.levelName).gameObject;
                ChangeLevelButton(btnGO, currentLevel.currentResult);
            }

            SaveLevel(currentLevel);

            Level nextLevel = FindNextLevel(currentLevel);

            if (nextLevel != null)
            {
                if (nextLevel.currentState == Level.LevelState.Locked)
                {
                    UnlockLevel(nextLevel);
                    UnlockButton(nextLevel);
                }

                PlayerData.Instance.currentLevel = nextLevel.levelName;
                PlayerData.Instance.Save();
            }
            else
            {
                Debug.Log("The last level was finished! There is not a new next level");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Save result of current level, update UI and unlock next level (use after finish) and etc.
        /// </summary>
        public void FinishLevel(Level.ResultPassing newResult)
        {
            // getting old result
            Level.ResultPassing oldResult = currentLevel.currentResult;

            // if the newest result is better than old - change the level button and current result for the current level
            if (oldResult < newResult)
            {
                currentLevel.currentResult = newResult;

                if (useAutoGeneration)
                {
                    GameObject btnGO = levelBox.Find(currentLevel.Name).gameObject;
                    ChangeLevelButtonResult(btnGO, currentLevel.currentResult);
                }
                else
                {
                    ChangeLevelButtonResult(currentLevel.ButtonGO, currentLevel.currentResult);
                }
            }

            // save level
            SaveLevel(currentLevel);

            // call onFinished event
            onFinished?.Invoke(newResult);

            // lookinf for the next level
            Level nextLevel = FindNextLevelByName(playerLevelList, currentLevel.Name);

            // if the next level was found - to unlock it and save as current level
            if (nextLevel != null)
            {
                if (nextLevel.currentState == Level.LevelState.Locked)
                {
                    UnlockLevel(nextLevel);
                    UnlockButton(nextLevel);
                }

                LevelData.Instance.currentLevel = nextLevel.Name;
                LevelData.Instance.Save();
            }
            else
            {
                // if the next level is not found (currrent level was final), call the event (curLevelIsFinal)
                curLevelIsFinal?.Invoke();
                Debug.Log("The last level was finished! There is not a new next level");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Check the player's parameters and determine the current result by them
        /// </summary>
        /// <returns></returns>
        private Level.ResultPassing GetResult()
        {
            Level.ResultPassing result = Level.ResultPassing.Low;

            if (PlayerController.Instance.Steps >= 2)
            {
                result = Level.ResultPassing.High;
            }
            else if (PlayerController.Instance.Steps == 1)
            {
                result = Level.ResultPassing.Middle;
            }

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Set stars for level button
        /// </summary>
        /// <param name="button"></param>
        /// <param name="currentResult"></param>
        private void SetButtonCurrentResult(LevelButton button, Level.ResultPassing currentResult)
        {
            switch (currentResult)
            {
            case Level.ResultPassing.NotPassed:
                //Debug.Log("NotPassed");
                break;

            case Level.ResultPassing.Low:
                button.SetLevelStars(1);
                //Debug.Log("Low");
                break;

            case Level.ResultPassing.Middle:
                button.SetLevelStars(2);
                //Debug.Log("Middle");
                break;

            case Level.ResultPassing.High:
                button.SetLevelStars(3);
                //Debug.Log("High");
                break;
            }
        }