/// <summary> /// запустить взрыв шаров одного и того же типа /// </summary> /// <param name="startBall"></param> public void StartPopSequence(BallConnected startBall) { HashSet <BallConnected> ballsToPop = new HashSet <BallConnected>(); //находим все шары, которые надо лопнуть foreach (var ball in GetConnectedBlockSameType(startBall, null)) { ballsToPop.Add(ball); } if (ballsToPop.Count > 1) { //лопаем шары foreach (var ball in ballsToPop) { if (allBalls.Values.Contains(ball)) { ball.PopBall(); RemoveBall(ball); } } DropUnHangBalls(); } else { startBall.HangUp(); } }
/// <summary> /// Создать поле шаров /// </summary> /// <returns></returns> public Dictionary <Vector2Int, BallConnected> GenerateBalls() { allBalls = new Dictionary <Vector2Int, BallConnected>(); var textFile = Resources.Load <TextAsset>(levelName); List <string> lines = new List <string>(textFile.text.Split('\n')); for (int l = 0; l < lines.Count; l++) { string line = lines[l]; for (int i = 0; i < line.Length; i++) { if (Char.GetNumericValue(line[i]) >= 0) { BallConnected newBall = Instantiate(ballPref, GetOffsetByGridPos(new Vector2Int(i, l)), Quaternion.identity, startSpawn); newBall.name = i + "," + l; Vector2Int gridPos = new Vector2Int(i, l); newBall.SetOnGrid(gridPos); if (l == 0) { newBall.HangUp(); minHangBalls++; } newBall.ChangeType(loadBallTypes[Int32.Parse(line[i].ToString())]); allBalls.Add(gridPos, newBall); } } } foreach (var ball in allBalls) { if (FindNeighboors(ball.Value.GridPos).Any(b => b.Hanging)) { ball.Value.HangUp(); } } minHangBalls *= 0.3f; return(allBalls); }