private void BabyShapes_BashingComponentRemoved(object sender, GameComponentCollectionEventArgs e)
 {
     // Clean up the bashing shape once it's lifespan is over.
     if (Object.ReferenceEquals(this._BashingShape, e.GameComponent))
     {
         this._BashingShape = null;
         this._BabyShapes.Components.ComponentRemoved -= new EventHandler <GameComponentCollectionEventArgs>(BabyShapes_BashingComponentRemoved);
     }
 }
        protected virtual void DoKeyboardHandling(GameTime gameTime, Configuration config, IBabyPackageProvider babyPackage, SoundService sound)
        {
            // Keyboard handling.
            var keyboardState = Keyboard.GetState();

            // Idle timeout reset.
            if (keyboardState.GetPressedKeys().Length > 0)
            {
                this._LastAction = gameTime.TotalGameTime;
            }

            if (!this.IsBashingKeys(keyboardState))
            {
                // Add characters pressed to be drawn.
                foreach (var key in this.GetKeyPresses(keyboardState))
                {
                    var keyResult = babyPackage.MapKeyPress(key);
                    this.HandleShapeAndSound(sound, keyResult, SoundAction.Button);
                }
            }
            else
            {
                // Bashing detected, display something different and clear all other shapes / letters on screen.
                var bashingAction = babyPackage.KeyBashingDetected();
                if (bashingAction != null)
                {
                    foreach (var element in this._BabyShapes.Components.OfType <BabyShape>().ToArray())
                    {
                        this._BabyShapes.Components.Remove(element);
                    }

                    sound.StopPlayingAllSounds();
                    this.HandleShapeAndSound(sound, bashingAction, SoundAction.ForceButton);

                    this._BashingShape = bashingAction.Shape;
                    this._BabyShapes.Components.ComponentRemoved += new EventHandler <GameComponentCollectionEventArgs>(BabyShapes_BashingComponentRemoved);
                }
            }
        }