void IsPoping() { int j = 1; Ball.BallColor tempColor = Ball.BallColor.NULL; for (int i = 0; i < managerScript.ballsInLine.Count; i++) { Ball a = managerScript.ballsInLine[i].GetComponent <Ball>(); if (tempColor == a.ballColor) { j++; if ((managerScript.ballsInLine.Count - 1 == i && j >= 3)) { managerScript.state = LevelManager.GameState.Poping; Pop(i - j + 1, i); return; } } else if ((tempColor != a.ballColor && j >= 3)) { managerScript.state = LevelManager.GameState.Poping; Pop(i - j, i - 1); return; } else { tempColor = a.ballColor; j = 1; } } managerScript.state = LevelManager.GameState.Normal; }
private void PopulateListOfAdjacentBalls(Ball ball, string previousDirection) { if (ball.IsUsed) { return; } ball.IsUsed = true; int i = ball.X; int j = ball.Y; Ball.BallColor color = ball.color; Ball leftBall = null; Ball upBall = null; Ball rightBall = null; Ball downBall = null; if (i != 0) { leftBall = ballMatrix[i - 1, j]; } if (j != 0) { upBall = ballMatrix[i, j - 1]; } if (i != numberOfColumns - 1) { rightBall = ballMatrix[i + 1, j]; } if (j != numberOfRows - 1) { downBall = ballMatrix[i, j + 1]; } //If not, we will check adjacents and see if they are good to remove if (leftBall != null && leftBall.color == color && previousDirection != "right") { PopulateListOfAdjacentBalls(leftBall, "left"); } if (rightBall != null && rightBall.color == color && previousDirection != "left") { PopulateListOfAdjacentBalls(rightBall, "right"); } if (upBall != null && upBall.color == color && previousDirection != "down") { PopulateListOfAdjacentBalls(upBall, "up"); } if (downBall != null && downBall.color == color && previousDirection != "up") { PopulateListOfAdjacentBalls(downBall, "down"); } lastPopulatedListOfBalls.Add(ball); }
private void GetAllPieceOfSameColorAlignedAtSlot(BallSlot ballSlot, Ball.BallColor color, List <BallSlot> slots) { Ball ball = GetBallAtSlot(ballSlot.RowIndex, ballSlot.ColumnIndex); if (ball != null && ball.Color == color && !slots.Contains(ballSlot)) { slots.Add(ballSlot); GetAllAdjacentSlots(ballSlot).ForEach(slot => GetAllPieceOfSameColorAlignedAtSlot(slot, color, slots)); } }
private static Vector2 GetSpriteDestroyedBallTopLeftForColor(Ball.BallColor color) { int top = 0; int left = 0; switch (color) { case Ball.BallColor.Blue: top = 0; left = 0; break; case Ball.BallColor.DarkGrey: top = 1; left = 1; break; case Ball.BallColor.Green: top = 1; left = 0; break; case Ball.BallColor.Orange: top = 1; left = 2; break; case Ball.BallColor.Purple: top = 3; left = 1; break; case Ball.BallColor.Red: left = 0; top = 2; break; case Ball.BallColor.Silver: top = 0; left = 1; break; case Ball.BallColor.Yellow: top = 0; left = 2; break; default: throw new Exception(String.Format("color {0} does not exist", color)); } return(TOP_LEFT_DESTROYED + new Vector2( left * SPRITE_DISTANCE_DESTROYED_BALL_COLUMN_WIDTH, top * SPRITE_DISTANCE_DESTROYED_BALL_ROW_HEIGHT)); }
private static Rectangle GetColorNormalRectangle(Ball.BallColor color) { int top = 0; int left = 0; switch (color) { case Ball.BallColor.Blue: top = 0; left = 0; break; case Ball.BallColor.DarkGrey: top = 1; left = 1; break; case Ball.BallColor.Green: top = 0; left = 1; break; case Ball.BallColor.Orange: top = 2; left = 1; break; case Ball.BallColor.Purple: top = 3; left = 1; break; case Ball.BallColor.Red: left = 0; top = 2; break; case Ball.BallColor.Silver: top = 1; left = 0; break; case Ball.BallColor.Yellow: top = 3; left = 0; break; default: throw new Exception(String.Format("color {0} does not exist", color)); } return(new Rectangle(SPRITE_BALL_TOP_LEFT.X + left * SPRITE_BALL_COLUMN_WIDTH, SPRITE_BALL_TOP_LEFT.Y + top * SPRITE_BALL_ROW_HEIGHT, SRC_RECTANGLE_WIDTH, SRC_RECTANGLE_HEIGHT)); }