public override bool Equals(object obj) { if (!(obj is ball)) { return(false); } ball temporaryBall = (ball)obj; return(GetDistance(this, temporaryBall) < ((this.size / 2) + (temporaryBall.size / 2))); }
private void DrawSpace_MouseLeftClick(Point pos, CDrawer dr) { ball temp = new ball((float)(rnd.NextDouble() * 100 + 10), pos); //Access the list to see if it contains a ball lock (ballList) { if (ballList.Contains(temp)) { return; //return nothing! } } //Add ball to the list lock (ballList) { ballList.Add(temp); } Render(); }
//Methods private static float GetDistance(ball ballUno, ball ballDuo) { return((float)(Math.Sqrt(Math.Pow(ballDuo.position.X - ballUno.position.X, 2) + Math.Pow(ballDuo.position.Y - ballUno.position.Y, 2)))); }