// (c) 2005 kp@kp73.com
using System;
using System.Collections;
namespace KP.Tetris{
/// <summary>
/// Game piece.
/// </summary>
public abstract class Tetramino
{
/// <summary>
/// Maps of the tetramino shape in each possible orientation.
/// </summary>
protected internal TetraminoMap[] maps;
/// <summary>
/// Provides a map of the tetramino shape for a given orientation.
/// </summary>
/// <param name="orientation"></param>
/// <returns></returns>
public TetraminoMap GetMap(Direction orientation)
{
return maps[(int)orientation];
}
/// <summary>
/// Initialises a new instance of the Tetramino class.
/// </summary>
protected Tetramino()
{
}
/// <summary>
/// Initialises a tetramino instance with the correct shape maps.
/// </summary>
internal void Initialise()
{
SetShapes();
}
/// <summary>
/// Get the range of roatation.
/// </summary>
internal abstract Direction MaxRotation { get; }
/// <summary>
/// Get the tetramino colour.
/// </summary>
public abstract Colour Colour { get; }
/// <summary>
/// Populate the 'maps' property with the correct
/// shape map for each possible orientation.
/// </summary>
protected abstract void SetShapes();
/// <summary>
/// Get a map of the tetramino's appearance in it's current state.
/// </summary>
/// <returns>Map of the tetramino's appearance</returns>
public TetraminoMap GetAppearance()
{
return GetAppearance(this.State);
}
/// <summary>
/// Get a map of the tetramino's appearance in a given state.
/// </summary>
/// <returns>Map of the tetramino's appearance</returns>
public TetraminoMap GetAppearance(TetraminoState state)
{
TetraminoMap appearance = null;
if (state != null) appearance = GetMap(state.Orientation);
else appearance = GetMap(Direction.North);
return appearance;
}
private TetraminoState _state;
/// <summary>
/// Get the state of the tetramino.
/// </summary>
public TetraminoState State
{
get { return _state; }
}
internal void SetState(TetraminoState state)
{
_state = state;
}
}
}
|