title: C#/XNA How do I get my classes to "speak" to each other?
body: <p>I'm attempting to build a clone of the first level of Super Mario Bros., but i'm having some trouble getting my classes to "speak" to each other. As of now, I have two Controller classes (keyboard, gamepad) and two animated sprite classes (RunMarioSprite, DeadMarioSprite). What I want to do is switch between these two sprites displaying on the screen based on the keyboard/gamepad input from the user. If key F is pressed, Mario should be displayed running right. If Key D is pressed Mario should move up and down.</p>
  
  <p>What's the proper way of changing which Animated Sprite Class is drawing on the screen through my Controller Classes?</p>
  
  <p><strong>Keyboard Class</strong></p>
  
  <pre><code>public class KeyboardController : IController
  {
      KeyboardState keyboard = Keyboard.GetState();
      private IAnimatedSprite marioSprite;
      Texture2D texture;
  
      public void Update()
      {
          if (keyboard.IsKeyDown(Keys.Q))
          {
              // QUIT GAME    
          }
          if (keyboard.IsKeyDown(Keys.F))
          {
              // MARIO RUN RIGHT             
          }
          if (keyboard.IsKeyDown(Keys.D))
          {
              // DEAD MARIO UP DOWN
  
          }
      }
  }
  </code></pre>
  
  <p><strong>Example of an animated sprite class</strong></p>
  
  <pre><code>public class RunMarioSprite : IAnimatedSprite
  {
      public Texture2D Texture { get; set; }
      private int currentFrame = 0;
      private int totalFrames = 4;
      public int frameShift = 30;
  
      public RunMarioSprite(Texture2D texture)
      {
          currentFrame = 0;
          this.Texture = texture;
      }
  
      public void Update()
      {
          currentFrame++;
          if (currentFrame == totalFrames)
              currentFrame = 0;
      }
  
      public void Draw(SpriteBatch spriteBatch)
      {
  
          Rectangle sourceRectangle2 = new Rectangle((240 +(currentFrame*frameShift)), 0, 30, 30);
          Rectangle destinationRectangle2 = new Rectangle(100, 100, 30, 30);
  
          spriteBatch.Begin();
          spriteBatch.Draw(Texture, destinationRectangle2, sourceRectangle2, Color.White);
          spriteBatch.End();
      }
  }
  
  
      protected override void Update(GameTime gameTime)
      {
          // Allows the game to exit
          if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
              this.Exit();
  
  
          // TODO: Add your update logic here
        foreach (IController Controller in ControllerList)
          {
             Controller.Update();
          }
  
          marioSprite.Update();
          base.Update(gameTime);
      }
  
      /// &lt;summary&gt;
      /// This is called when the game should draw itself.
      /// &lt;/summary&gt;
      /// &lt;param name="gameTime"&gt;Provides a snapshot of timing values.&lt;/param&gt;
      protected override void Draw(GameTime gameTime)
      {
          GraphicsDevice.Clear(Color.CornflowerBlue);
  
          // TODO: Add your drawing code here
          marioSprite.Draw(this.spriteBatch);
  
          base.Draw(gameTime);
      }
  </code></pre>
  
  <p><strong>Main (Update and Draw)</strong></p>
  
  <pre><code>    protected override void Update(GameTime gameTime)
      {
          // Allows the game to exit
          if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
              this.Exit();
  
  
          // TODO: Add your update logic here
        foreach (IController Controller in ControllerList)
          {
             Controller.Update();
          }
  
          marioSprite.Update();
          base.Update(gameTime);
      }
  
      /// &lt;summary&gt;
      /// This is called when the game should draw itself.
      /// &lt;/summary&gt;
      /// &lt;param name="gameTime"&gt;Provides a snapshot of timing values.&lt;/param&gt;
      protected override void Draw(GameTime gameTime)
      {
          GraphicsDevice.Clear(Color.CornflowerBlue);
  
          // TODO: Add your drawing code here
          marioSprite.Draw(this.spriteBatch);
  
          base.Draw(gameTime);
      }
  </code></pre>
  
  <p>I apologize if the question is poorly formatted. Thanks for the help!</p>