Esempio n. 1
0
        /// <summary>
        /// Initialize the ball list and start the timer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonGo_Click(object sender, EventArgs e)
        {
            balls      = new List <Ball>();
            ballsColor = new List <Color>();

            //generate balls in random positions, at random speeds
            //while loop since we don't want to generate two balls that overlap
            int i = 0;

            while (i < NUM_BALLS)
            {
                //new ball position is inside table, and speed is in range -3 to +3
                // MovingBall newBall = new MovingBall(random.Next(1, 233), random.Next(1, 117), random.Next(7) - 3, random.Next(7) - 3);

                // p = new PoolBall(newBall.XSpeed, newBall.YSpeed, newBall.X, newBall.Y);
                //  p=new PoolBall(random.Next(1, 233), random.Next(1, 117), random.Next(7) - 3, random.Next(7) - 3);

                cpb = new ColourPoolBall(random.Next(1, 233), random.Next(1, 117), random.Next(7) - 3, random.Next(7) - 3);

                //check if overlaps any existing balls
                if (!CheckOverlaps(cpb))
                { //ball position is good, so add it
                    balls.Add(cpb);
                    // ballsColor.Add(cpb.getTheColor);
                    i++; //add 1 to ball count
                }
            }


            //start timer for movement
            timerTime.Enabled = true;
        }
Esempio n. 2
0
        /// <summary>
        /// Displays the ball
        /// </summary>
        /// <param name="paper">The Graphics object to use for the drawing</param>
        public virtual void Display(Graphics paper, int NUM)// Color c)
        {
            ColourPoolBall b  = new ColourPoolBall(X, Y, xCoord, yCoord);
            SolidBrush     br = new SolidBrush(Color.Black);

            // br.Color = b.getTheColor;
            br.Color = b.GetCol(NUM);
            paper.FillEllipse(br, xCoord, yCoord, size, size);
            paper.DrawEllipse(pen, xCoord, yCoord, size, size);
        }