Exemple #1
0
        public Bubble Attached(Bubble bubble)
        {
            var toJoin = collector.ScoreNeighbours(bubble);

            if (toJoin.Count <= 1)
            {
                CheckRowCount();
                return(null); //nothing to join
            }

            IBubbleScore score    = calculator.CalculateScore(bubble.Score, toJoin.Count);
            Tile         bestTile = collector.SelectBestTile(toJoin, score);

            //detach old bubbles
            foreach (var bb in toJoin)
            {
                bb.Movement.MoveTowards(bestTile.transform.position);
                bb.StartCoroutine(DelayReturn(bb, DelayReturnTime));
            }

            //create new bubble
            var newBubble = spawner.Create(score);

            #if UNITY_EDITOR
            UnityEditor.EditorGUIUtility.PingObject(newBubble.gameObject);
            #endif

            grid.Insert(newBubble, bestTile);

            foreach (var toDrop in FindLooseBubbles(toJoin))
            {
                toDrop.Movement.Drop();
                toDrop.StartCoroutine(DelayReturn(toDrop, DelayReturnTime));
            }

            Debug.Log($"Collected {score.PointsString} points");

            if (newBubble.Score.Exponent > scoreRange.ExplosionExponent)
            {
                exploder.Explode(newBubble);
                CheckRowCount();
                return(null);
            }
            else
            {
                //continue chain
                return(newBubble);
            }
        }
Exemple #2
0
        public IBubbleScore CalculateScore(IBubbleScore score, int count)
        {
            var expScore = score.Exponent + count - 1;
            var exponent = expScore;
            var points   = 2.Pow(exponent) * data.Multiplier;

            data.Points += points;
            while (pointsToNextLevel < data.Points)
            {
                pointsCurrentLevel = pointsToNextLevel;
                data.Level++;
                scoreRange.BaseExponent = data.Level / IncrementBaseEveryLevels;
                pointsToNextLevel       = PointsToReach(data.Level);
            }
            dataManager.Save(data);
            return(new BubbleScore(expScore, data.Multiplier));
        }
Exemple #3
0
        public void Refresh(IBubbleScore score)
        {
            current          = config.Get(score.Exponent);
            background.color = outline.color = current.Background;
            var valueStr   = Mathf.Pow(2, score.Exponent % 10).ToString("0");
            var textConf   = font[valueStr];
            var suffixConf = GetSuffix(score);

            text.sprite   = textConf.Sprite;
            suffix.sprite = suffixConf.Sprite;

            Vector3 textPosition = Vector3.right * -suffixConf.Width / 2f;
            Vector3 suffixOffset = Vector3.right * (textConf.Width + suffixConf.Width) / 2f;

            text.transform.localPosition = textPosition;
            suffix.transform.position    = text.transform.position + suffixOffset;// + suffixOffset;
            ShowOutline(score.Exponent);
        }
Exemple #4
0
        private Tile BestTile(HashSet <Bubble> toJoin, IBubbleScore score)
        {
            int  bestCount = 0;
            Tile bestTile  = null;

            foreach (var bb in toJoin)
            {
                var newToJoin = new HashSet <Bubble>();
                //candidates with value matching new score
                ScoreNeighbours(bb, newToJoin, score);
                if (newToJoin.Count > bestCount)
                {
                    bestTile  = grid.Get(bb);
                    bestCount = newToJoin.Count;
                }
            }

            return(bestTile);
        }
Exemple #5
0
        private SpriteFontItem GetSuffix(IBubbleScore score)
        {
            var    check = score.Exponent / 10;
            string suffix;

            if (check < 1)
            {
                suffix = null;
            }
            else if (check < 2)
            {
                suffix = "k";
            }
            else if (check < 3)
            {
                suffix = "M";
            }
            else if (check < 4)
            {
                suffix = "G";
            }
            else if (check < 5)
            {
                suffix = "T";
            }
            else if (check < 6)
            {
                suffix = "P";
            }
            else
            {
                suffix = "*";
            }

            return(font[suffix]);
        }
Exemple #6
0
 //TODO
 public Tile SelectBestTile(HashSet <Bubble> toJoin, IBubbleScore score)
 {
     return(BestTile(toJoin, score));
 }
Exemple #7
0
        private HashSet <Bubble> ScoreNeighbours(Bubble bubble, HashSet <Bubble> result, IBubbleScore score = null)
        {
            if (score == null)
            {
                score = bubble.Score;
            }

            result.Add(bubble);
            Bubble[] scoreNeighbours = grid.Neighbours(bubble)
                                       .Where(n => n != null && !result.Contains(n) && n.Score.Exponent.Equals(score.Exponent)).ToArray();
            foreach (var neighbour in scoreNeighbours)
            {
                if (result.Contains(neighbour))
                {
                    continue;                             // already checked
                }
                foreach (var childNeighbour in ScoreNeighbours(neighbour, result))
                {
                    result.Add(childNeighbour);
                }
            }

            return(result);
        }
Exemple #8
0
        public Bubble Create(IBubbleScore score)
        {
            var bubble = bubblePool.Spawn(score);

            return(bubble);
        }
Exemple #9
0
 private void SetScore(IBubbleScore score)
 {
     this.score = score;
     view.Refresh(score);
 }