示例#1
0
        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();
        }
示例#2
0
 public void ReplacePiece(ChessPieceViewModel oldPieceViewModel, ChessPieceViewModel newPieceViewModel)
 {
     RemovePiece(oldPieceViewModel);
     AddPiece(newPieceViewModel);
 }
示例#3
0
 public void AddPiece(ChessPieceViewModel pieceViewModel)
 {
     Pieces.Add(pieceViewModel);
 }
示例#4
0
 public bool RemovePiece(ChessPieceViewModel pieceViewModel)
 {
     return(Pieces.Remove(pieceViewModel));
 }