Example #1
0
 public bool IntersectsWithBall(Ball b)
 {
     foreach (ModelMesh mesh in Model.Meshes)
     {
         BoundingSphere boundingSphere = mesh.BoundingSphere.Transform(World);
         foreach(ModelMesh bMesh in b.Model.Meshes)
         {
             BoundingSphere ballboundingSphere = bMesh.BoundingSphere.Transform(b.World);
             if (ballboundingSphere.Intersects(boundingSphere))
             {
                 return true;
             }
         }
     }
     return false;
 }
Example #2
0
 private void RefreshBallPosition(int rowIndex, int colIndex, Ball ball)
 {
     if (rowIndex % 2 == 0)
     {
         ball.Position = Position + new Vector3(rowIndex * 2 * Ball.BALL_RADIUS, colIndex * 2 * Ball.BALL_RADIUS, 0);
     }
     else
     {
         ball.Position = Position + new Vector3(rowIndex * 2 * Ball.BALL_RADIUS, colIndex * 2 * Ball.BALL_RADIUS + ODD_ROW_OFFSET, 0); ;
     }
     ball.Normalize();
 }
Example #3
0
        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));
            }
        }
Example #4
0
 public void SetNewBallAtPosition(int rowIndex, int colIndex, Ball ball)
 {
     PuzzleBooble3dGame.Components.Add(ball);
     this.SetBallAtPosition(rowIndex, colIndex, ball);
 }
Example #5
0
        public void SetBallToNearestSlot(Ball ball, BallSlot interSectingSlot)
        {
            int nearestRowIndex;
            int nearestColumnIndex;

            List<BallSlot> emptySlots;

            if (interSectingSlot != null)
            {
                // Get the nearest empty slots.
                emptySlots = GetAllAdjacentLowerSlots(interSectingSlot);
                emptySlots.AddRange(GetAdjacentSlotsOnSameRow(interSectingSlot));
            }
            else // The ball reached the ceiling
            {
                emptySlots = GetAllTopSlots();
            }
            emptySlots.RemoveAll(slot => GetBallAtSlot(slot) != null);

            emptySlots.Sort(delegate(BallSlot slot, BallSlot otherSlot)
            {
                float length1 = (GetSlotCenter(slot) - ball.Position).Length();
                float length2 = (GetSlotCenter(otherSlot) - ball.Position).Length();
                return length1.CompareTo(length2);
            });

            if (emptySlots.Count > 0)
            {
                try
                {
                    nearestRowIndex = emptySlots.ElementAt(0).RowIndex;
                    nearestColumnIndex = emptySlots.ElementAt(0).ColumnIndex;

                    SetBallAtPosition(nearestRowIndex, nearestColumnIndex, ball);
                    DestroyAlignedPieceAtSlot(nearestRowIndex, nearestColumnIndex);

                    int numOfBallsFallen = FallDownAllBallsWithNoUpperAdjacentBalls(nearestRowIndex, nearestColumnIndex);
                    CurrentScore.Value += (numOfBallsFallen > 0) ? (int)Math.Pow(2, numOfBallsFallen) * 10
                                                                 : 0;
                    CheckIfPlayerWins();
                    CheckIfPlayerLost();
                }
                catch (SlotOccupiedException ex)
                {
                }
            }
            else
            {
                //Set All balls to Dark
                foreach (List<Ball> list in Balls)
                {
                    foreach (Ball b in list)
                    {
                        if (b != null)
                        {
                            b.GoDark();
                        }
                    }
                }

                Observer.ForEach(observer => observer.OnPlayerLoses());
            }
        }
Example #6
0
        public void SetBallAtPosition(int rowIndex, int colIndex, Ball ball)
        {
            if (Balls.ElementAt(rowIndex).ElementAt(colIndex) != null)
            {
                throw new SlotOccupiedException(rowIndex, colIndex);
            }
            Balls[rowIndex][colIndex] = ball;

            RefreshBallPosition(rowIndex, colIndex, ball);
        }
Example #7
0
 public BallSlot BallsIntersectingWithBall(Ball ball)
 {
     for (int i = 0; i < NUMBER_OF_ROWS; i++)
     {
         for (int j = 0; j < GetNumberOfColumnForRow(i); j++)
         {
             Ball b = Balls.ElementAt(i).ElementAt(j);
             if (b != null && ball.IntersectsWithBall(b))
             {
                 return new BallSlot(i, j);
             }
         }
     }
     return null;
 }
 private void SetNextBall(Ball ball)
 {
     NextBall = ball;
     NextBall.Position = GetNextBallPosition();
     PuzzleBooble3dGame.Components.Add(NextBall);
     NextBall.Load();
 }
        private void SetCurrentBall(Ball ball)
        {
            if(!PuzzleBooble3dGame.Components.Contains(ball))
            {
                PuzzleBooble3dGame.Components.Add(ball);
            }

            CurrentBall = ball;
            CurrentBall.Position = GetCurrentBallPosition();
            CurrentBall.Load();
        }