Exemple #1
0
 public ArrayList GetLevelBalls(int a_nLevel)
 {
     int[,] aLevel = GetLevel(a_nLevel);
     ArrayList balls = new ArrayList();
     Ball ball;
     for (int y = 0; y < aLevel.GetLength(0); y++)
     {
         for (int x = 0; x < aLevel.GetLength(1); x++)
         {
             int nType = aLevel[y,x]-1;
             if (nType < 0)
                 continue;
             ball = new Ball(nType, m_playArea);
             ball.GridLoc = new EPoint(x*2+y%2,y);
             balls.Add(ball);
         }
     }
     return balls;
 }
Exemple #2
0
        private void AddComingBall()
        {
            Random rnd = new Random();
            ArrayList aTypes = m_playArea.Grid.GetBallTypes();
            foreach (Ball ball in m_aComingBalls)
            {
                if (!aTypes.Contains(ball.BallType))
                    aTypes.Add(ball.BallType);
            }

            int nType = 0;
            if (aTypes.Count>0)
                nType = (int)aTypes[rnd.Next(aTypes.Count)];
            Ball newball = new Ball(nType, m_playArea);
            m_aComingBalls.Add(newball);
        }
Exemple #3
0
        public void ShowPath()
        {
            m_shootingBall = (Ball)m_aComingBalls[0];
            EPointF loc = m_shootingBall.Loc;
            double dAngle = -Math.PI*Angle/180;
            float fSpeed = 1000;
            EPointF pntVel = EPointF.FromLengthAndAngle(fSpeed, (float)dAngle);

            EPoint pntGridStick = null;
            EPointF pntBounce;

            int nMaxTests = 40; //if more bounces than this is calculated, then something has gone wrong as it's outside the system
            //			EH.Put("Start at "+loc.ToString());
            while (nMaxTests-->0)
            {
                if (m_playArea.m_pathCalc.GetFirstStickOrBounce(ref loc, ref pntVel, out pntGridStick,out pntBounce, true) == false)
                {
            //					EH.Put("Test num:"+nMaxTests.ToString() + " loc"+loc.ToString());
            //					EH.Put("Bounce:" + loc.ToString()+" vel:"+pntVel.ToString());
            //					loc = pntBounce.Copy();
                }
                else
                {
            //					if (m_spTarget!=null)
            //						m_spTarget.Loc = m_playArea.Grid.GetGfxLocFromGridLoc(pntGridStick);
                    break;
                }
            }
        }
Exemple #4
0
        public void LaunchBall()
        {
            m_shootingBall = (Ball)m_aComingBalls[0];
            m_shootingBall.Shoot(Angle);

            m_aComingBalls.RemoveAt(0);
            AddComingBall();
            PushNextBall();
        }
Exemple #5
0
        private bool RecursiveCalcConnection(Ball a_ball)
        {
            m_aCurrentChainInfo.Balls.Add(a_ball);
            a_ball.ChainNum = 1;
            if (a_ball.GridLoc.Y == 0)
                m_aCurrentChainInfo.State = 1; //it's connected to ceiling

            ArrayList aNeighbours = GetNeighbours(a_ball);
            foreach (Ball ball in aNeighbours)
            {
                //m_playArea.EndogineHub.Put(ball.BallType.ToString() + "  " + ball.GridLoc.ToString());

                if (ball==null)
                {
                    //m_playArea.EndogineHub.Put("Null");
                    continue;
                }
                if (ball.ChainNum > 0)
                {
                    //m_playArea.EndogineHub.Put("Is in chain:"+ball.ChainNum.ToString());
                    continue; //Connected to the chain
                }
                RecursiveCalcConnection(ball);
                //if (RecursiveCalcConnection(ball))
                //	return true;
            }

            if (m_aCurrentChainInfo.State == 1)
                return true;

            return false;
        }
Exemple #6
0
        private void RecursiveCalcColorChain(Ball a_ball)
        {
            m_aCurrentChainInfo.Balls.Add(a_ball);
            a_ball.ChainNum = m_nCurrentChainNum;

            ArrayList aNeighbours = GetNeighbours(a_ball);
            foreach (Ball ball in aNeighbours)
            {
                if (ball != null)
                {
                    if (ball.BallType == a_ball.BallType)
                    {
                        if (ball.ChainNum < m_nCurrentChainNum) //m_nStartChainNum)
                        { //not checked before
                            RecursiveCalcColorChain(ball);
                        }
                    }
                }
            }
        }
Exemple #7
0
 private ArrayList GetNeighbours(Ball a_ball)
 {
     ArrayList aBalls = new ArrayList();
     ArrayList aLocs = a_ball.GetNeighbourLocs();
     foreach (EPoint loc in aLocs)
     {
         Ball ball = this.GetBallOnLoc(loc);
         if (ball!=null)
             aBalls.Add(ball);
     }
     return aBalls;
 }
Exemple #8
0
        public void SetBallOnLoc(EPoint a_pnt, Ball a_ball)
        {
            if (a_pnt.X < 0 || a_pnt.X >= GridSize.Width || a_pnt.Y < 0)
                return;
            m_aGrid[a_pnt.X, a_pnt.Y] = a_ball;
            a_ball.GridLoc = a_pnt;
            a_ball.Loc = GetGfxLocFromGridLoc(a_pnt);

            ResetChainNums();
            m_nCurrentChainNum = 0;
            ArrayList aSameColor = CalcColorChain(a_pnt);

            if (aSameColor.Count > 2)
            {
                ArrayList aAllRemove = new ArrayList();
                //remove balls in color chain, and then all balls that are no longer connected to ceiling!

                //first color chain, and also find all neighbours to the color chain
                ArrayList aAllNeighbours = new ArrayList();
                    //make a list of all neighbours:
                    foreach (Ball removeball in aSameColor)
                    {
                        ArrayList aNeighbours = GetNeighbours(removeball);
                        foreach (Ball neighbour in aNeighbours)
                        {
                            if (aAllNeighbours.Contains(neighbour) == false && aSameColor.Contains(neighbour) == false)
                                aAllNeighbours.Add(neighbour);
                        }
                        RemoveBallAtLoc(removeball.GridLoc);
                        removeball.Burst();
                        //aAllRemove.Add(removeball);
                    }

                ResetChainNums();
                m_nCurrentChainNum = 0;
                //now for each neighbour, add to remove list if not connected to ceiling:
                foreach (Ball ball in aAllNeighbours)
                {
                    //if one of these balls is connected to another, the recursive function will already have added it to its remove list
                    if (ball.ChainNum < 0)
                    {
                        EndogineHub.Put("New chain");
                        m_aCurrentChainInfo = new ChainInfo();
                        if (RecursiveCalcConnection(ball) == false) //the chain is not connected to ceiling
                        {
                            foreach (Ball removeball in m_aCurrentChainInfo.Balls)
                            {
                                aAllRemove.Add(removeball);
                                RemoveBallAtLoc(removeball.GridLoc);
                            }
                        }
                    }
                }

                foreach (Ball removeball in aAllRemove)
                {
                    removeball.Fall(); //Dispose(); //.Color = Color.FromArgb(100,100,100);
                }

                m_playArea.RemovedBalls(aSameColor.Count, aAllRemove.Count);
            }
        }
Exemple #9
0
 public void NoRemoveSetBallOnLoc(EPoint a_pnt, Ball a_ball)
 {
     m_aGrid[a_pnt.X, a_pnt.Y] = a_ball;
 }