private void OnSquarePressed(SquareViewModel squareVM) { // the square does not belong to our bord if (BoardViewModel.Squares.IndexOf(squareVM) == -1) { return; } ChessPieceViewModel pieceViewModel = BoardViewModel.GetPiece(squareVM.Coordinate); if (pieceViewModel != null || PiecesPaletteViewModel.SelectedPiece == null) { BoardViewModel.RemovePiece(pieceViewModel); editorBoardService.SetPiece(squareVM.Coordinate, null); } else { BoardViewModel.AddPiece(new ChessPieceViewModel(PiecesPaletteViewModel.SelectedPiece.Piece, squareVM.Coordinate)); editorBoardService.SetPiece(squareVM.Coordinate, PiecesPaletteViewModel.SelectedPiece.Piece); } IsBoardValid = editorBoardService.AcceptEditedPosition(); }
public void ReplacePiece(ChessPieceViewModel oldPieceViewModel, ChessPieceViewModel newPieceViewModel) { RemovePiece(oldPieceViewModel); AddPiece(newPieceViewModel); }
public void AddPiece(ChessPieceViewModel pieceViewModel) { Pieces.Add(pieceViewModel); }
public bool RemovePiece(ChessPieceViewModel pieceViewModel) { return(Pieces.Remove(pieceViewModel)); }