示例#1
0
        private void SetScore(ScoreItemModel model, ScoreType type, int score)
        {
            switch (type)
            {
            case ScoreType.Crown:
                model.highestCrown = score;
                RefreshMetric();
                break;

            case ScoreType.Score:
                model.highestScore = score;
                break;

            case ScoreType.Star:
                model.highestStar = score;
                RefreshMetric();
                break;
            }


            //HACKATHON used to speed up programming
            //save game state right after update highscore
            //if (type == ScoreType.Score) {
            //    GameManager.Instance.SaveGameData();
            //}
        }
示例#2
0
        private int GetScore(ScoreItemModel model, ScoreType type)
        {
            switch (type)
            {
            case ScoreType.Crown:
                return(model.highestCrown);

            case ScoreType.Score:
                return(model.highestScore);

            case ScoreType.Star:
                return(model.highestStar);

            default:
                return(0);
            }
        }
示例#3
0
        public bool UpdateHighScore(string levelName, int scoreValue, ScoreType type = ScoreType.Score)
        {
            //print("Updating high score for level " + levelName + " type: " + type + " value: " + scoreValue);
            if (isInit)
            {
                bool res = false;

                foreach (ScoreItemModel item in listHighscore)
                {
                    if (item.itemName.Equals(levelName))
                    {
                        int currentScore = GetScore(item, type);
                        if (currentScore >= scoreValue)
                        {
                            res = false;
                        }
                        else
                        {
                            SetScore(item, type, scoreValue);
                            res = true;
                        }

                        //print(string.Format("Item found for level {0}, score type {1}, need update = {2}", levelName, type, res));
                        return(res);
                    }
                }

                //if we reached this point, it's mean the item is not existed. We shall create one
                ScoreItemModel scoreitem = new ScoreItemModel();
                scoreitem.itemName = levelName;
                listHighscore.Add(scoreitem);
                SetScore(scoreitem, type, scoreValue);
                //print(string.Format("Create new highscore for level {0}, score type {1}, value = {2}", levelName, type, scoreValue));
                return(true);
            }

            return(false);
        }