//----------------------------------------------------------------------------- // GameTable.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.IO; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace CardsFramework { /// /// The UI representation of the table where the game is played. /// public class GameTable : DrawableGameComponent { public string Theme { get; private set; } public Texture2D TableTexture { get; private set; } public Vector2 DealerPosition { get; private set; } public SpriteBatch SpriteBatch { get; private set; } protected Matrix globalTransformation; public Func PlaceOrder { get; private set; } public Rectangle TableBounds { get; private set; } public int Places { get; private set; } /// /// Updates the number of places/spots to display on the table. /// /// The new number of places. public void SetPlaces(int places) { Places = places; } /// /// Returns the player position on the table according to the player index. /// /// Player's index. /// The position of the player corrsponding to the /// supplied index. /// The location's are relative to the entire game area, even /// if the table only occupies part of it. public Vector2 this[int index] { get { return new Vector2(TableBounds.Left, TableBounds.Top) + PlaceOrder(index); } } /// /// Initializes a new instance of the class. /// /// The table bounds. /// The dealer's position. /// Amount of places on the table /// A method to convert player indices to their /// respective location on the table. /// The theme used to display UI elements. /// The associated game object. public GameTable(Rectangle tableBounds, Vector2 dealerPosition, int places, Func placeOrder, string theme, Game game, SpriteBatch sharedSpriteBatch, Matrix? globalTransformation = null) : base(game) { TableBounds = tableBounds; DealerPosition = dealerPosition + new Vector2(tableBounds.Left, tableBounds.Top); Places = places; PlaceOrder = placeOrder; Theme = theme; this.SpriteBatch = sharedSpriteBatch; this.globalTransformation = globalTransformation ?? Matrix.Identity; } /// /// Load the table texture. /// protected override void LoadContent() { string assetName = Path.Combine("Images", "UI", "table"); TableTexture = Game.Content.Load(assetName); base.LoadContent(); } /// /// Render the table. /// /// Time passed since the last call to /// this method. public override void Draw(GameTime gameTime) { SpriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, globalTransformation); // Draw the table texture SpriteBatch.Draw(TableTexture, TableBounds, Color.White); SpriteBatch.End(); base.Draw(gameTime); } } }