public void DragFigureEnter(ChessFigure figure)
        {
            dynamic       dynamicFigure = selectedFigure;
            ChessMoveInfo MoveInfo      = rulesService.Check(board, dynamicFigure, figure);

            if (MoveInfo)
            {
                board[figure.Row, figure.Col].CursorOver = true;
            }
        }
        private bool CanAttackerBeBlocked(Square[,] board, List <Square> attackingPath, King attackedKing)
        {
            bool canBeBlocked = false;

            foreach (var boardSquare in board)
            {
                if (boardSquare.Figure.Name != Constants.EmptySquare)
                {
                    if (boardSquare.Figure.IsWhite == attackedKing.IsWhite && boardSquare.Figure.Name != Constants.KingName)
                    {
                        foreach (var attackingPathSquare in attackingPath)
                        {
                            if (rulesService.Check(board, boardSquare.Figure, attackingPathSquare.Figure))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(canBeBlocked);
        }
示例#3
0
        public void DragOver(ChessFigure figure)
        {
            dynamic tempFigure = selectedFigure;

            if (tempFigure == null)
            {
                return;
            }

            if (!rulesService.Check(board, tempFigure, figure))
            {
                return;
            }

            var selectedSquare    = board[selectedFigure.Row, selectedFigure.Col];
            var destinationSquare = board[figure.Row, figure.Col];

            var selectedSquareIndex    = ChessGrid.IndexOf(selectedSquare);
            var destinationSquareIndex = ChessGrid.IndexOf(destinationSquare);

            var newSelectedSquare = new Square(selectedSquare.Row, selectedSquare.Col, selectedSquare.Color,
                                               new Empty(selectedSquare.Row, selectedSquare.Col));

            ChessGrid[selectedSquareIndex] = newSelectedSquare;

            selectedFigure.Row = destinationSquare.Row;
            selectedFigure.Col = destinationSquare.Col;

            var newDestinationSquare = new Square(destinationSquare.Row, destinationSquare.Col, destinationSquare.Color,
                                                  selectedFigure);

            ChessGrid[destinationSquareIndex] = newDestinationSquare;

            board[selectedSquare.Row, selectedSquare.Col]       = newSelectedSquare;
            board[destinationSquare.Row, destinationSquare.Col] = newDestinationSquare;
        }