public void move(List <Hole> holes)
        {
            int XVelocity = (int)(Velocity * Math.Cos(Angle));
            int YVelocity = (int)(Velocity * Math.Sin(Angle));

            XCoord += XVelocity;
            YCoord += YVelocity;

            if (collisionWithHole(holes))
            {
                visible = false;
            }

            if (XCoord - Radius <= Bounds.Left || XCoord + Radius >= Bounds.Right)
            {
                XCoord -= XVelocity;
                Angle   = HoleGenerator.getRandomAngle(Angle);
            }

            if (YCoord - Radius <= Bounds.Top || ((YCoord + Radius) >= Bounds.Bottom))
            {
                YCoord -= YVelocity;
                Angle   = HoleGenerator.getRandomAngle(Angle);
            }
        }
 public Form1()
 {
     this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
     this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
     this.SetStyle(ControlStyles.UserPaint, true);
     InitializeComponent();
     color         = Color.Red;
     listOfBalls   = new BallList();
     holeGenerator = new HoleGenerator();
     holes         = new List <Hole>();
     holes         = holeGenerator.getNewHoles(mainScreen);
 }
 private void mainScreen_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         Point clickPoint = e.Location;
         if (clickPoint.X - 25 >= 0 && clickPoint.X + 25 <= mainScreen.Width &&
             clickPoint.Y - 25 >= 0 && clickPoint.Y + 25 <= mainScreen.Height)
         {
             int  randomAngle = HoleGenerator.getRandomAngle(-1);
             Ball newBall     = new Ball(clickPoint.X, clickPoint.Y, 25, color, mainScreen.ClientRectangle, randomAngle);
             listOfBalls.addBall(newBall);
             toolStripLabel.Text = "# Balls : " + listOfBalls.size().ToString();
             mainScreen.Invalidate();
         }
     }
 }
 private void toolStripButton9_Click(object sender, EventArgs e)
 {
     holeGenerator = new HoleGenerator();
     holes         = holeGenerator.getNewHoles(mainScreen);
     mainScreen.Invalidate();
 }