예제 #1
0
        public bool intersectsWithGreenBall(GreenBall blue)
        {
            int distance = (int)Math.Sqrt(Math.Pow(XCoord - blue.XCoord, 2) + Math.Pow(YCoord - blue.YCoord, 2));

            if (distance <= Ball.Radius * 2)
            {
                return(true);
            }
            return(false);
        }
 public GreenBall intersectWithGreenBall(RedBall redBall)
 {
     foreach (Ball ball in balls)
     {
         if (ball is GreenBall)
         {
             GreenBall green = (GreenBall)ball;
             if (redBall.intersectsWithGreenBall(green))
             {
                 return(green);
             }
         }
     }
     return(null);
 }
예제 #3
0
 private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         int chance = random.Next(2);
         if (chance == 1)
         {
             GreenBall ball = new GreenBall(e.X, e.Y);
             balls.addBall(ball);
         }
         else
         {
             BlueBall ball = new BlueBall(e.X, e.Y);
             balls.addBall(ball);
         }
         Invalidate(true);
     }
 }
 public void move(Rectangle windowSize)
 {
     for (int i = balls.Count - 1; i >= 0; i--)
     {
         if (i >= 0)
         {
             Ball ball = balls.ElementAt(i);
             if (ball != null && ball is RedBall)
             {
                 RedBall redBall = (RedBall)ball;
                 if (redBall.clicked)
                 {
                     redBall.move(windowSize);
                     GreenBall green = intersectWithGreenBall(redBall);
                     if (green != null)
                     {
                         balls.Remove(green);
                     }
                 }
             }
         }
     }
 }