コード例 #1
0
        //gets: index of current piece location and final location. does: moes piece to said location.
        //Will not accept occupied spot - removePiece must be used beforhand in order to simulate eating
        public void MovePiece(int firstXIndex, int firstYIndex, int secondXIndex, int secondYIndex)
        {
            if (!ChessUtilities.isIndexInBounds(firstXIndex, firstYIndex, secondXIndex, secondYIndex))
            {
                throw new ArgumentOutOfRangeException();
            }

            PictureBox pieceAtLocation;
            Point      locationNow   = ConvertIndicesToLocation(firstXIndex, firstYIndex);
            Point      finalLocation = ConvertIndicesToLocation(secondXIndex, secondYIndex);

            PieceUIMap.TryGetValue(locationNow, out pieceAtLocation);

            if (pieceAtLocation == null)
            {
                throw new PieceDoesntExistAtThatLocationException();
            }
            if (PieceUIMap.ContainsKey(finalLocation))
            {
                throw new PieceAlreadyAtLocationConflictException();
            }

            pieceAtLocation.Visible = false;
            //physically animate piece to new location
            pieceAtLocation.Location = finalLocation;

            //remove old location pair from UIMap
            PieceUIMap.Remove(locationNow);

            //add new location pair to UIMap
            PieceUIMap[finalLocation] = pieceAtLocation;
            pieceAtLocation.Visible   = true;

            resetCurrentPieceClicked();
        }
コード例 #2
0
ファイル: ChessMove.cs プロジェクト: netanel-haber/pvp-chess
        public override string ToString()
        {
            if (IsEndGameInfo)
            {
                return(EndGameInfo);
            }

            if (Tag == ChessMoveTag.KingSideCastle)
            {
                return("0-0");
            }
            if (Tag == ChessMoveTag.QueenSideCastle)
            {
                return("0-0-0");
            }

            string result = "";

            switch (MovingPiece.Type)
            {
            case PieceType.Pawn:
                result = "";
                break;

            case PieceType.Knight:
                result = "N";
                break;

            default:
                result = Enum.GetName(typeof(PieceType), MovingPiece.Type)[0] + "";
                break;
            }

            Point current = RankAndFileCurrent;

            result += ChessUtilities.ConvertIndicesToRankAndFile(current.X, current.Y);

            if (IsEat)
            {
                result += "x";
            }
            else
            {
                result += "->";
            }

            Point final = RankAndFileFinal;

            result += ChessUtilities.ConvertIndicesToRankAndFile(final.X, final.Y);

            if (Tag == ChessMoveTag.EnPassant)
            {
                result += "e.p.";
            }

            if (IsCheck)
            {
                result += "+";
            }

            if (IsDoubleCheck)
            {
                result += "+";
            }

            switch (PromotedTo)
            {
            case "K":
                result += "N";
                break;

            default:
                if (PromotedTo != "_")
                {
                    result += PromotedTo;
                }
                break;
            }
            return(result);
        }