|
using System;
namespace CChess
{
public enum ChessPieceTypes : byte
{
Pawn = 1,
King,
Queen,
Rook,
Knight,
Bishop
}
public class CChessPiece
{
/// <summary>
/// For serializing
/// </summary>
private CChessPiece() { }
public CChessPiece(byte id, ChessPieceTypes type, CChessColors color, CChessSquare square)
{
_id = id;
_type = type;
_color = color;
_square = square;
}
private byte _id;
private ChessPieceTypes _type;
private CChessSquare _square;
private CChessColors _color;
public byte ID
{
get { return _id; }
}
public ChessPieceTypes Type
{
get { return _type; }
set
{
if (_type == ChessPieceTypes.Pawn && value != ChessPieceTypes.King && value != ChessPieceTypes.Pawn)
{
_type = value;
}
else
{
throw new Exception("Invalid promotion");
}
}
}
public CChessColors Color
{
get { return _color; }
}
public bool IsAlive
{
get { return (_square != null); }
}
/// <summary>
/// Gets or sets the square in which this piece currently is.
/// </summary>
public CChessSquare Square
{
get { return _square; }
set { _square = value; }
}
}
}
|
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.
My name is Julian, I was born in Argentina, but I've been living in Israel for 6 years already. I'm a high school student in my last year, I study computer science, physics and math.
Other than programming, I really enjoy watching anime and reading manga.