示例#1
0
        private Tile SelectNeighbour(RaycastHit hit)
        {
            var          offset = hit.point.x - hit.transform.position.x;
            var          offsetY = hit.point.y - hit.transform.position.y;
            HexDirection dir, dir2nd;

            if (offset < 0f)
            {
                if (offsetY < 0f)
                {
                    dir    = HexDirection.SE;
                    dir2nd = HexDirection.SE;
                }
                else
                {
                    dir    = HexDirection.E;
                    dir2nd = HexDirection.SE;
                }
            }
            else
            {
                if (offsetY < 0f)
                {
                    dir    = HexDirection.SW;
                    dir2nd = HexDirection.SW;
                }
                else
                {
                    dir    = HexDirection.W;
                    dir2nd = HexDirection.SW;
                }
            }

            //top
            if (hit.transform.CompareTag(FirstRowTag))
            {
                return(grid.Nearest(hit.point));
            }
            //bubble hit
            var bubble  = hit.transform.GetComponentInParent <Bubble>();
            var tileHit = grid.Get(bubble);
            var newTile = grid.Neighbour(tileHit, dir);

            if (grid.Get(newTile))
            {
                newTile = grid.Neighbour(tileHit, dir2nd);
            }

            if (grid.Get(newTile))
            {
                return(null);
            }

            return(newTile);
        }
示例#2
0
        bool IsAttached(Bubble bubble, HashSet <Bubble> alreadyChecked = null)
        {
            if (bubble == null)
            {
                return(false);
            }
            if (alreadyChecked == null)
            {
                alreadyChecked = new HashSet <Bubble>();
            }
            alreadyChecked.Add(bubble);
            //check self
            var cubeIndex = grid.Get(bubble).Index;

            if (cubeIndex.y == 0)
            {
                // verified
                return(true);
            }

            //check others
            foreach (var direction in looseCheck)
            {
                var checkBubble = grid.Neighbour(bubble, direction);
                if (!alreadyChecked.Contains(checkBubble) && IsAttached(checkBubble, alreadyChecked))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#3
0
 private void OnDrawGizmos()
 {
     if (Application.isPlaying)
     {
         foreach (var bubble in grid.Bubbles)
         {
             var tile = grid.Get(bubble);
             DrawTile(tile);
             DrawBubble(bubble);
             DrawConnection(tile, bubble);
         }
     }
 }
示例#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);
        }