|
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace CChess.Controls
{
public class CChessPiece : Control
{
public CChessPiece(CChess.CChessPiece piece, CChessSquare square, Image img)
{
System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream("CircularChess.CChess.Controls.CChessPiece.xaml");
_canvas = (Canvas)this.InitializeFromXaml(new System.IO.StreamReader(s).ReadToEnd());
_data_piece = piece;
_img = img;
if (square != null)
{
square.Piece = this;
}
_canvas.Children.Add(_img);
SetValue(MediaAttribute.NameProperty, "Piece" + piece.ID.ToString());
}
#region Fields
private Canvas _canvas;
private Image _img;
private CChess.CChessPiece _data_piece;
private CChessSquare _square;
public Image Image
{
get { return _img; }
set { _img = value; }
}
/// <summary>
/// Gets or sets the square in which this piece currently is.
/// </summary>
public CChessSquare Square
{
get { return _square; }
set { _square = value; }
}
public CChessColors CChessColor
{
get { return _data_piece.Color; }
}
#endregion
#region Data Piece Properties
public byte ID
{
get { return _data_piece.ID; }
}
public ChessPieceTypes Type
{
get { return _data_piece.Type; }
set
{
_data_piece.Type = value;
}
}
public Color Color
{
get
{
if (_data_piece.Color == CChessColors.White)
{
return Colors.White;
}
else
{
return Colors.Black;
}
}
}
public bool IsAlive
{
get { return _data_piece.IsAlive; }
}
#endregion
public void ChangeImage(Image img)
{
_canvas.Children.Remove(_img);
_img = img;
_img.Width = 100;
_img.Height = 100;
_img.Stretch = Stretch.None;
_canvas.Children.Add(_img);
}
}
}
|
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.