コード例 #1
0
        private bool QueryMaps(Bubble bubble, Tile tile)
        {
            if (t2b.ContainsKey(tile))
            {
                return(false); //cannot insert, tile taken
            }

            //free old tile
            Detach(bubble);

            b2t.Add(bubble, tile);
            t2b.Add(tile, bubble);
            return(true);
        }
コード例 #2
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);
            }
        }
コード例 #3
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);
        }
コード例 #4
0
 public Tile Get(Bubble bubble) => Get(b2t, bubble);
コード例 #5
0
        public List <Bubble> BubblesInRange(Bubble center, int range)
        {
            var tiles = grid.TilesInRange(Get(center), range);

            return(BubblesToTiles(tiles));
        }
コード例 #6
0
        public Bubble Neighbour(Bubble bubble, HexDirection direction)
        {
            var tile = Neighbour(Get(bubble), direction);

            return(Get(tile));
        }
コード例 #7
0
 public void Pretend(Bubble other)
 {
     view.Refresh(other.Score);
     movement.Teleport(other.transform.position);
 }
コード例 #8
0
 public HashSet <Bubble> ScoreNeighbours(Bubble bubble)
 {
     return(ScoreNeighbours(bubble, new HashSet <Bubble>()));
 }
コード例 #9
0
        //public FakeBubble Create(Bubble bubble) {
        //return fakeBubblePool.Spawn(bubble);
        //}

        public void Return(Bubble bubble)
        {
            bubblePool.Despawn(bubble);
        }