AnimatedCardsGameComponent.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // AnimatedCardsGameComponent.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. using Microsoft.Xna.Framework;
  14. using CardsFramework;
  15. using Microsoft.Xna.Framework.Graphics;
  16. using System.Diagnostics;
  17. #endregion
  18. namespace CardsFramework
  19. {
  20. /// <summary>
  21. /// An <see cref="AnimatedGameComponent"/> implemented for a card game
  22. /// </summary>
  23. public class AnimatedCardsGameComponent : AnimatedGameComponent
  24. {
  25. public TraditionalCard Card { get; private set; }
  26. /// <summary>
  27. /// Initializes a new instance of the class.
  28. /// </summary>
  29. /// <param name="card">The card associated with the animation component.</param>
  30. /// <param name="cardGame">The associated game.</param>
  31. public AnimatedCardsGameComponent(TraditionalCard card, CardsGame cardGame)
  32. : base(cardGame, null)
  33. {
  34. Card = card;
  35. }
  36. #region Update and Render
  37. /// <summary>
  38. /// Updates the component.
  39. /// </summary>
  40. /// <param name="gameTime">The game time.</param>
  41. public override void Update(GameTime gameTime)
  42. {
  43. base.Update(gameTime);
  44. CurrentFrame = IsFaceDown ? CardGame.cardsAssets["CardBack_" + CardGame.Theme] :
  45. CardGame.cardsAssets[UIUtilty.GetCardAssetName(Card)];
  46. }
  47. /// <summary>
  48. /// Draws the component.
  49. /// </summary>
  50. /// <param name="gameTime">The game time.</param>
  51. public override void Draw(GameTime gameTime)
  52. {
  53. base.Draw(gameTime);
  54. CardGame.SpriteBatch.Begin();
  55. // Draw the current at the designated destination, or at the initial
  56. // position if a destination has not been set
  57. if (CurrentFrame != null)
  58. {
  59. if (CurrentDestination.HasValue)
  60. {
  61. CardGame.SpriteBatch.Draw(CurrentFrame,
  62. CurrentDestination.Value, Color.White);
  63. }
  64. else
  65. {
  66. CardGame.SpriteBatch.Draw(CurrentFrame,
  67. CurrentPosition, Color.White);
  68. }
  69. }
  70. CardGame.SpriteBatch.End();
  71. }
  72. #endregion
  73. }
  74. }