コード例 #1
0
        public void ChessPiece_Move_Sets_X_Coordinate_For_Valid_Move()
        {
            IChessPiece piece = CreatePiece(PieceType.Pawn, PieceColor.Black);

            _chessBoard.Add(Arg.Any <IChessPiece>(),
                            Arg.Do <int>(x => piece.XCoordinate = x),
                            Arg.Do <int>(y => piece.YCoordinate = y),
                            piece.Color).Returns(true).AndDoes(x => piece.SetBoard(_chessBoard));
            _chessBoard.IsMoveValid(Arg.Any <Move>()).Returns(true);

            _chessBoard.Add(piece, 3, 6, piece.Color);
            piece.Move(MovementType.Move, 2, 6);
            Assert.That(piece.XCoordinate, Is.EqualTo(2));
        }
コード例 #2
0
        /// <summary>
        /// Moves the piece.  Coordinates are only updated if the move is valid
        /// </summary>
        /// <param name="newXCoordinate">The x coordinate of the square being moved to</param>
        /// <param name="newYCoordinate">The y coordinate of the square being moved to</param>
        /// <returns>True when the move was valid</returns>
        public virtual bool Move(MovementType moveType, int newXCoordinate, int newYCoordinate)
        {
            Move move = new Move(this, XCoordinate, YCoordinate, newXCoordinate, newYCoordinate);

            if (_chessBoard.IsMoveValid(move))
            {
                XCoordinate = newXCoordinate;
                YCoordinate = newYCoordinate;
                _chessBoard.UpdateBoard(move);
                return(true);
            }

            return(false);
        }