private static IEnumerable<Shape> ConvertChessPieceToPaths(ChessPieceWithColor chessPiece) { if (chessPiece.Color == ChessPieceColor.White) { switch (chessPiece.Type) { case ChessPieceType.Bishop: return CreateWhiteBishopShapes(); case ChessPieceType.King: return CreateWhiteKingShapes(); case ChessPieceType.Knight: return CreateWhiteKnightShapes(); case ChessPieceType.Pawn: return CreateWhitePawnShapes(); case ChessPieceType.Queen: return CreateWhiteQueenShapes(); case ChessPieceType.Rook: return CreateWhiteRookShapes(); default: throw new Exception("Unknown ChessPieceType " + chessPiece.Type); } } else { switch (chessPiece.Type) { case ChessPieceType.Bishop: return CreateBlackBishopShapes(); case ChessPieceType.King: return CreateBlackKingShapes(); case ChessPieceType.Knight: return CreateBlackKnightShapes(); case ChessPieceType.Pawn: return CreateBlackPawnShapes(); case ChessPieceType.Queen: return CreateBlackQueenShapes(); case ChessPieceType.Rook: return CreateBlackRookShapes(); default: throw new Exception("Unknown ChessPieceType " + chessPiece.Type); } } }
private void DrawPieces(bool inverted) { foreach (ChessPieceColor pieceColor in Enum.GetValues(typeof(ChessPieceColor))) foreach (ChessPieceType pieceType in Enum.GetValues(typeof(ChessPieceType))) { ChessPieceWithColor chessPiece = new ChessPieceWithColor() { Color = !inverted ? pieceColor : (pieceColor == ChessPieceColor.Black ? ChessPieceColor.White : ChessPieceColor.Black), Type = pieceType, }; string canvasPropertyName = string.Format("{0}Player{1}", pieceColor, pieceType); var canvasProperty = GetType().GetTypeInfo().GetDeclaredProperty(canvasPropertyName); if (canvasProperty != null) { Canvas canvas = (Canvas)canvasProperty.GetValue(this); canvas.Children.Clear(); ChessPieceGraphics.DrawPiece(canvas, chessPiece); } } }
public static void DrawPiece(Canvas canvas, ChessPieceWithColor chessPiece) { IEnumerable<Shape> shapes = ConvertChessPieceToPaths(chessPiece); canvas.Width = 45; canvas.Height = 45; foreach (Shape shape in shapes) { canvas.Children.Add(shape); } }