#region File Description
//-----------------------------------------------------------------------------
// GameTable.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion
namespace CardsFramework
{
///
/// The UI representation of the table where the game is played.
///
public class GameTable : DrawableGameComponent
{
#region Fields and Properties and Indexer
public string Theme { get; private set; }
public Texture2D TableTexture { get; private set; }
public Vector2 DealerPosition { get; private set; }
public SpriteBatch SpriteBatch { get; private set; }
public Func PlaceOrder { get; private set; }
public Rectangle TableBounds { get; private set; }
public int Places { get; private set; }
///
/// 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);
}
}
#endregion
#region Initiaizations
///
/// 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)
: base(game)
{
TableBounds = tableBounds;
DealerPosition = dealerPosition +
new Vector2(tableBounds.Left, tableBounds.Top);
Places = places;
PlaceOrder = placeOrder;
Theme = theme;
SpriteBatch = new SpriteBatch(game.GraphicsDevice);
}
///
/// Load the table texture.
///
protected override void LoadContent()
{
string assetName = string.Format(@"Images\UI\table");
TableTexture = Game.Content.Load(assetName);
base.LoadContent();
}
#endregion
#region Render
///
/// Render the table.
///
/// Time passed since the last call to
/// this method.
public override void Draw(GameTime gameTime)
{
SpriteBatch.Begin();
// Draw the table texture
SpriteBatch.Draw(TableTexture, TableBounds, Color.White);
SpriteBatch.End();
base.Draw(gameTime);
}
#endregion
}
}