GameTable.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // GameTable.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 Microsoft.Xna.Framework.Graphics;
  15. #endregion
  16. namespace CardsFramework
  17. {
  18. /// <summary>
  19. /// The UI representation of the table where the game is played.
  20. /// </summary>
  21. public class GameTable : DrawableGameComponent
  22. {
  23. #region Fields and Properties and Indexer
  24. public string Theme { get; private set; }
  25. public Texture2D TableTexture { get; private set; }
  26. public Vector2 DealerPosition { get; private set; }
  27. public SpriteBatch SpriteBatch { get; private set; }
  28. public Func<int, Vector2> PlaceOrder { get; private set; }
  29. public Rectangle TableBounds { get; private set; }
  30. public int Places { get; private set; }
  31. /// <summary>
  32. /// Returns the player position on the table according to the player index.
  33. /// </summary>
  34. /// <param name="index">Player's index.</param>
  35. /// <returns>The position of the player corrsponding to the
  36. /// supplied index.</returns>
  37. /// <remarks>The location's are relative to the entire game area, even
  38. /// if the table only occupies part of it.</remarks>
  39. public Vector2 this[int index]
  40. {
  41. get
  42. {
  43. return new Vector2(TableBounds.Left, TableBounds.Top) +
  44. PlaceOrder(index);
  45. }
  46. }
  47. #endregion
  48. #region Initiaizations
  49. /// <summary>
  50. /// Initializes a new instance of the class.
  51. /// </summary>
  52. /// <param name="tableBounds">The table bounds.</param>
  53. /// <param name="dealerPosition">The dealer's position.</param>
  54. /// <param name="places">Amount of places on the table</param>
  55. /// <param name="placeOrder">A method to convert player indices to their
  56. /// respective location on the table.</param>
  57. /// <param name="theme">The theme used to display UI elements.</param>
  58. /// <param name="game">The associated game object.</param>
  59. public GameTable(Rectangle tableBounds, Vector2 dealerPosition, int places,
  60. Func<int, Vector2> placeOrder, string theme, Game game)
  61. : base(game)
  62. {
  63. TableBounds = tableBounds;
  64. DealerPosition = dealerPosition +
  65. new Vector2(tableBounds.Left, tableBounds.Top);
  66. Places = places;
  67. PlaceOrder = placeOrder;
  68. Theme = theme;
  69. SpriteBatch = new SpriteBatch(game.GraphicsDevice);
  70. }
  71. /// <summary>
  72. /// Load the table texture.
  73. /// </summary>
  74. protected override void LoadContent()
  75. {
  76. string assetName = string.Format(@"Images\UI\table");
  77. TableTexture = Game.Content.Load<Texture2D>(assetName);
  78. base.LoadContent();
  79. }
  80. #endregion
  81. #region Render
  82. /// <summary>
  83. /// Render the table.
  84. /// </summary>
  85. /// <param name="gameTime">Time passed since the last call to
  86. /// this method.</param>
  87. public override void Draw(GameTime gameTime)
  88. {
  89. SpriteBatch.Begin();
  90. // Draw the table texture
  91. SpriteBatch.Draw(TableTexture, TableBounds, Color.White);
  92. SpriteBatch.End();
  93. base.Draw(gameTime);
  94. }
  95. #endregion
  96. }
  97. }