コード例 #1
0
ファイル: ChessLogic.cs プロジェクト: mudale222/chess
        internal bool DoMoveIfLegal(Location from, Location to, ref string message)
        {
            var pieceUserWantToMove = board.GetSquareData(from);

            if (!IsLegalMove(pieceUserWantToMove, to, ref message))
            {
                return(false);
            }
            Sound.Play("moveSound");
            DeniedFutureCastlingIfNeedTo(pieceUserWantToMove);
            if (pieceUserWantToMove is King && Math.Abs(to.x - from.x) == 2)  //castling move
            {
                DoCastling(from, to, pieceUserWantToMove.isWhite);
            }
            else if (pieceUserWantToMove is Pawn && Math.Abs(to.y - from.y) == 1 && Math.Abs(to.x - from.x) == 1 && board.GetSquareData(to) == null)  //Pawn special eat
            {
                board.UpdateBoard(from, to, true);
            }
            else  //normal move
            {
                board.UpdateBoard(from, to);
            }
            isWhiteTurn = !isWhiteTurn;                                             //set next user turn
            board.AddCurrentBoardToBoardHistory(!pieceUserWantToMove.isWhite);
            if (pieceUserWantToMove is ChessPiece && pieceUserWantToMove is Pawn && //Pawn promotion
                ((pieceUserWantToMove.isWhite && to.y == 0) || (!pieceUserWantToMove.isWhite && to.y == 7)))
            {
                Sound.Play("promotionSoundEffect");
                var promotionForm = new PawnPromotionForm(pieceUserWantToMove as ChessPiece, this);
                promotionForm.ShowDialog();
            }
            return(true);
        }