|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
namespace GameExample.Reversi
{
public struct Position
{
/// <summary>
/// A position on the game board. The first two bits represent the player, the last 6 bits
/// are used by render to track the current frame.
/// </summary>
private readonly byte _data;
/// <summary>
/// Initializes a new instance of the <see cref="Position"/> struct.
/// </summary>
/// <param name="data">The data.</param>
public Position(byte data)
{
_data = data;
}
public Position(Player player)
: this((byte)player)
{
}
public Position(Player player, byte renderData)
: this((byte)((byte)player | ((byte)renderData << 2)))
{
}
/// <summary>
/// An empty position.
/// </summary>
/// <value>The empty.</value>
public static Position Empty
{
get
{
return new Position();
}
}
/// <summary>
/// Gets the player.
/// </summary>
/// <value>The player.</value>
public Player Player
{
get
{
return (Player)(_data & 0x3);
}
}
/// <summary>
/// Gets data used by render.
/// </summary>
/// <value>The render data.</value>
public byte RenderData
{
get
{
return (byte)(_data >> 2);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.