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); }
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); } }
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); }
public Tile Get(Bubble bubble) => Get(b2t, bubble);
public List <Bubble> BubblesInRange(Bubble center, int range) { var tiles = grid.TilesInRange(Get(center), range); return(BubblesToTiles(tiles)); }
public Bubble Neighbour(Bubble bubble, HexDirection direction) { var tile = Neighbour(Get(bubble), direction); return(Get(tile)); }
public void Pretend(Bubble other) { view.Refresh(other.Score); movement.Teleport(other.transform.position); }
public HashSet <Bubble> ScoreNeighbours(Bubble bubble) { return(ScoreNeighbours(bubble, new HashSet <Bubble>())); }
//public FakeBubble Create(Bubble bubble) { //return fakeBubblePool.Spawn(bubble); //} public void Return(Bubble bubble) { bubblePool.Despawn(bubble); }