private void RemoveBalloon(Balloon balloon) { // remove event delegate handler for Popped even for this balloon balloon.Popped -= this.PoppedEventHandler; _balloonDrawAnimate -= balloon.DrawAndAnimate; // Find balloon in ArrayList for removal and reset of active balloon int index = _balloons.IndexOf(balloon); if (index >= 0) { if (_balloons[index] == _activeBalloon) _activeBalloon = null; _balloons.RemoveAt(index); // raise OnNoInfo event OnNoInfo(balloon, EventArgs.Empty); } }
// Private methods private Balloon CreateBalloon() { // Randomly set growth and lift rates, and create a balloon int growthRate = _random.Next(10, 41); int liftRate = _random.Next(1, 6); Balloon balloon = new Balloon(new Point(_random.Next(_boardSize.Width - 20), _boardSize.Height), new Size(20, 20), _defaultColor, growthRate, liftRate); // Add event handler to Popped event for each balloon balloon.Popped += new EventHandler(PoppedEventHandler); // Add balloon drawing and animation method to our delegate _balloonDrawAnimate += balloon.DrawAndAnimate; return balloon; }