public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { // This converter will receive two properties: the Position of the square, and whether it // is being hovered. BoardPosition pos = (BoardPosition)values[0]; bool isHovered = (bool)values[1]; int playerSquare = (int)values[2]; Model.ChessPiece cp = (Model.ChessPiece)values[3]; bool isSelected = (bool)values[4]; bool isCheck = (bool)values[5]; // Mouse Hovering over a Piece if (isHovered) { return(HOVER_BRUSH); } // Current Piece that has been selected to interact with if (isCheck) { return(CHECK_BRUSH); } if (isSelected) { //if selected, change to red background return(SELECTED_BRUSH); } if (pos.Row % 2 == 0 & pos.Col % 2 == 0 | pos.Row % 2 == 1 & pos.Col % 2 == 1) { return(WHITE_BRUSH); } else { return(BLACK_BRUSH); } //if current player king in check, change square to CHECK_BRUSH }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { Model.ChessPiece cs = (Model.ChessPiece)value; if (cs.PieceType != Model.ChessPieceType.Empty && cs.Player != 0) { switch (cs.Player) { case 1: switch (cs.PieceType) { case Model.ChessPieceType.Pawn: return(new BitmapImage(new Uri("/Cecs475.BoardGames.Chess.WpfViewNew;component/Resources/WhitePawn.png", UriKind.Relative))); case Model.ChessPieceType.Rook: return(new BitmapImage(new Uri("/Cecs475.BoardGames.Chess.WpfViewNew;component/Resources/WhiteRook.png", UriKind.Relative))); case Model.ChessPieceType.Knight: return(new BitmapImage(new Uri("/Cecs475.BoardGames.Chess.WpfViewNew;component/Resources/WhiteKnight.png", UriKind.Relative))); case Model.ChessPieceType.Bishop: return(new BitmapImage(new Uri("/Cecs475.BoardGames.Chess.WpfViewNew;component/Resources/WhiteBishop.png", UriKind.Relative))); case Model.ChessPieceType.Queen: return(new BitmapImage(new Uri("/Cecs475.BoardGames.Chess.WpfViewNew;component/Resources/WhiteQueen.png", UriKind.Relative))); case Model.ChessPieceType.King: return(new BitmapImage(new Uri("/Cecs475.BoardGames.Chess.WpfViewNew;component/Resources/WhiteKing.png", UriKind.Relative))); default: return(null); } case 2: switch (cs.PieceType) { case Model.ChessPieceType.Pawn: return(new BitmapImage(new Uri("/Cecs475.BoardGames.Chess.WpfViewNew;component/Resources/BlackPawn.png", UriKind.Relative))); case Model.ChessPieceType.Rook: return(new BitmapImage(new Uri("/Cecs475.BoardGames.Chess.WpfViewNew;component/Resources/BlackRook.png", UriKind.Relative))); case Model.ChessPieceType.Knight: return(new BitmapImage(new Uri("/Cecs475.BoardGames.Chess.WpfViewNew;component/Resources/BlackKnight.png", UriKind.Relative))); case Model.ChessPieceType.Bishop: return(new BitmapImage(new Uri("/Cecs475.BoardGames.Chess.WpfViewNew;component/Resources/BlackBishop.png", UriKind.Relative))); case Model.ChessPieceType.Queen: return(new BitmapImage(new Uri("/Cecs475.BoardGames.Chess.WpfViewNew;component/Resources/BlackQueen.png", UriKind.Relative))); case Model.ChessPieceType.King: return(new BitmapImage(new Uri("/Cecs475.BoardGames.Chess.WpfViewNew;component/Resources/BlackKing.png", UriKind.Relative))); default: return(null); } default: return(null); } } else { return(null); } } catch (Exception e) { return(null); } }