示例#1
0
        /// <summary>Cancel the result of this command.</summary>
        public override void Undo()
        {
            preventConflict(stackBefore, stackAfter, transitionStack);

            List <IAnimation> animations = new List <IAnimation>(5);

            if (transitionStack == stackAfter)
            {
                animations.Add(new EmptyPlayerHandAnimation(playerGuid, transitionStack));
                animations.Add(new RearrangeStackAnimation(transitionStack, pieces));
            }
            else
            {
                animations.Add(new SplitStackAnimation(stackAfter, pieces, transitionStack));
            }
            animations.Add(new MoveToFrontOfBoardAnimation(transitionStack, stackBefore.Board));
            for (int i = 0; i < pieces.Length; ++i)
            {
                IPiece piece = pieces[i];
                if (piece.RotationAngle != rotationAnglesBefore[i])
                {
                    int totalDetentsBefore = (int)(piece.RotationAngle * (12.0f / (float)Math.PI) + 0.5f) * 120;
                    int totalDetentsAfter  = (int)(rotationAnglesBefore[i] * (12.0f / (float)Math.PI) + 0.5f) * 120;
                    int rotationIncrements = totalDetentsAfter - totalDetentsBefore;
                    animations.Add(new InstantRotatePiecesAnimation(new IPiece[] { piece }, rotationIncrements));
                }
                if (piece.Side != sidesBefore[i])
                {
                    animations.Add(new InstantFlipPiecesAnimation(new IPiece[] { piece }));
                }
            }
            animations.Add(new MoveStackFromHandAnimation(transitionStack, stackBefore.Position));
            animations.Add(new MergeStacksAnimation(stackBefore, transitionStack, bottomIndex));
            model.AnimationManager.LaunchAnimationSequence(animations.ToArray());
        }
示例#2
0
 private void ChefIfPieceDoesNotExist(IPiece piece)
 {
     if (!this.pieces.Contains(piece))
     {
         throw new InvalidOperationException("Player does not have this piece!");
     }
 }
示例#3
0
 private void ChefIfPieceExists(IPiece piece)
 {
     if (this.pieces.Contains(piece))
     {
         throw new InvalidOperationException("Player has this piece already!");
     }
 }
示例#4
0
 public void RemovePiece(IPiece piece)
 {
     ObjectValidator.CheckIfObjectIsNull(piece, ErrorMessages.NullPieceError);
     //TODO: check piece and color
     ChefIfPieceDoesNotExist(piece);
     pieces.Remove(piece);
 }
示例#5
0
 public void Attacking(IPiece piece, Square[][] matrix)
 {
     this.AttackedSquaresY(-1, piece.Position.File, matrix, piece);
     this.AttackedSquaresX(piece.Position.Rank, -1, matrix, piece);
     this.AttackedSquaresY(1, piece.Position.File, matrix, piece);
     this.AttackedSquaresX(piece.Position.Rank, 1, matrix, piece);
 }
示例#6
0
文件: VectorMove.cs 项目: jsok/Chess
        public List<Position> applyMove(Board board, IPiece piece)
        {
            Position p = piece.Position;
            Position possible;

            List<Position> moves = new List<Position>();

            int scalar;
            for (scalar = 1; scalar < Chess.Board.BOARD_DIMENSION; scalar++)
            {
                possible = new Position(p.Column + scalar * x, p.Row + scalar * y);
                Position.Placement placement = board.validPosition(piece, possible);

                switch (placement)
                {
                    case Position.Placement.VALID:
                    case Position.Placement.CAPTURE:
                        moves.Add(possible);
                        break;

                    case Position.Placement.BLOCKED:
                    case Position.Placement.ILLEGAL:
                    default:
                        break;
                }

                if (placementWillTerminateVector(placement))
                    break;
            }

            return moves;
        }
示例#7
0
        public void RequestToSetPiece(IntegerVector2 position, IPiece piece)
        {
            if (game.CurrentPlayer != player)
            {
                logger.Log(new NotYourTurnMessage());
                return;
            }

            if (piece == null)
            {
                logger.Log(new NoPieceSelectedMessage());
                return;
            }

            IBoard board = game.Board;

            logger.Log(new SetPieceMessage(player, piece, position));
            bool result = board.SetPiece(position, piece);

            if (!result)
            {
                logger.Log(new SetPieceFailureMessage());
            }
            else
            {
                player.UseCapturedPiece(piece);
                game.TurnEnd();
            }
        }
示例#8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlayerCheckers"/> class.
        /// </summary>
        /// <param name="color">The piece color.</param>
        /// <param name="gameboard">The gameboard.</param>
        public PlayerCheckers(IPieceColor color, Gameboard gameboard)
            : base(color)
        {
            IPiece newPiece;
            int offset = 0, startPos = 0;

            this.gameboard = gameboard;
            this.moveCounter = 0;
            this.selectedPiece = null;

            if (color == IPieceColor.White)
            {
                offset = 5;
                startPos = 1;
            }
            else if (color == IPieceColor.Black)
            {
                offset = 0;
                startPos = 0;
            }

            for (int j = 0; j < 3; j++)
            {
                startPos = (++startPos) % 2;
                for (int i = startPos; i < 8; i += 2)
                {
                    newPiece = new Man(color, gameboard, new Position(i, j + offset));
                    newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
                    this.PieceList.Add(newPiece);
                }
            }
        }
示例#9
0
 public void AddPiece(IPiece piece)
 {
     ObjectValidator.CheckIfObjectIsNull(piece, ErrorMessages.NullPieceError);
     ChefIfPieceExists(piece);
     this.pieces.Add(piece);
     //TODO: check piece and color
 }
示例#10
0
	public int OnSolve(
				IPiece<int> sender,
				EventArgs e,
				bool solved) {
		on = solved;
		return 0;
	}
示例#11
0
 public void Add(IPiece piece)
 {
     if (piece == null)
         throw new ArgumentNullException("Piece must not be null!");
     else
         _pieces.Add(piece);
 }
示例#12
0
 //http://tetris.wikia.com/wiki/Wall_kick
 public override bool RotateCounterClockwise(IPiece piece)
 {
     // Special case: cannot place piece at starting location.
     if (!CheckNoConflict(piece))
         return false;
     // Try to rotate
     IPiece tempPiece = piece.Clone();
     tempPiece.RotateCounterClockwise();
     if (!CheckNoConflict(tempPiece))
     {
         // Try to move right then rotate
         tempPiece.CopyFrom(piece);
         tempPiece.Translate(1, 0);
         tempPiece.RotateCounterClockwise();
         if (!CheckNoConflict(tempPiece))
         {
             // Try to move left then rotate
             tempPiece.CopyFrom(piece);
             tempPiece.Translate(-1, 0);
             tempPiece.RotateCounterClockwise();
             if (!CheckNoConflict(tempPiece))
                 return false;
             else
                 piece.Translate(-1, 0);
         }
         else
             piece.Translate(1, 0);
     }
     // Perform rotation (wall kick translation has been done before if needed)
     piece.RotateCounterClockwise();
     return true;
 }
示例#13
0
 public void Capture(IPieceBag pieceBag, IPiece startingPiece, Direction direction)
 {
     foreach (var piece in GetCapturablePieces(pieceBag, startingPiece, direction))
     {
         piece.Flip();
     }
 }
示例#14
0
 public List<ILocation> AllowedMoves(IPiece piece)
 {
     if (piece != null)
     {
         switch (piece.Type)
         {
             case PieceType.pawn:
                 return PawnMoves(piece);
             case PieceType.rook:
                 return RookMoves(piece);
             case PieceType.knight:
                 return KnightMoves(piece);
             case PieceType.bishop:
                 return BishopMoves(piece);
             case PieceType.queen:
                 return QueenMoves(piece);
             case PieceType.king:
                 return KingMoves(piece);
             default:
                 return new List<ILocation>();
         }
     }
     else
         return new List<ILocation>();
 }
示例#15
0
        public void MakeMove(Cell i_Source, Cell i_Destination)
        {
            Move move = new Move(this, i_Source, i_Destination);

            if (move.Result)
            {
                i_Source.Piece.Position = new Tuple <int, int>(i_Destination.Row, i_Destination.Col);
                i_Destination.Piece     = i_Source.Piece;
                i_Source.Piece          = null;

                if (move.IsJump)
                {
                    int    inBetweenCol  = i_Destination.Col > i_Source.Col ? i_Source.Col + 1 : i_Source.Col - 1;
                    int    inBetweenRow  = i_Destination.Row > i_Source.Row ? i_Source.Row + 1 : i_Source.Row - 1;
                    IPiece pieceToRemove = m_Board.GetCell(inBetweenRow, inBetweenCol).Piece;

                    if (m_Player1.RemovePiece(pieceToRemove))
                    {
                        m_Board.GetCell(inBetweenRow, inBetweenCol).Piece = null;
                    }
                    else
                    {
                        m_Player2.RemovePiece(pieceToRemove);
                        m_Board.GetCell(inBetweenRow, inBetweenCol).Piece = null;
                    }
                }

                //isKing?
                CheckToMakeKing(i_Destination.Piece);

                MoveHaveBeenMade.Invoke();

                //is game ended?
                if (DoesGameEnded())
                {
                    GameEnded.Invoke();
                    return;
                }

                //another turn?
                if (move.IsJump)
                {
                    if (isAnotherTurn(move))
                    {
                        if (m_CurrentPlayer is PcPlayer)
                        {
                            (m_CurrentPlayer as PcPlayer).getNextMoveFromPc(this, move);
                            return;
                        }
                        else
                        {
                            //next move from human
                            return;
                        }
                    }
                }
                switchCurrentTurn();
            }
        }
示例#16
0
    /// <summary>
    /// Sets <paramref name="space"/> IsSelected to true, and adds to <paramref name="board"/> selection.
    /// </summary>
    /// <param name="board">The board.</param>
    /// <param name="piece">The piece to select.</param>
    /// <remarks>Opposite of <see cref="DeselectSpace"/>.</remarks>
    public static void SelectPiece(this IBoard board, IPiece piece)
    {
        board.SelectedPiece = piece;
        piece.IsSelected    = true;

        piece.MoveableSpaces = piece.MovementRules.GetLegalMoves(board, piece);
        piece.MoveableSpaces.SetCanMoveOnSpaces(true);
    }
示例#17
0
 protected void someMethodThatNeedsAFallingPiece()
 {
     if (fallingPiece == null)
     {
         IPiece piece = pieceGenerator.Generate();
         fallingPiece = fallingPieceGenerator.generate(piece);
     }
 }
示例#18
0
 public WhitePawnMoveFixture()
 {
     _sut    = new PawnMove();
     _piece  = Helper.GetMockedPieceAt(1, 0, PieceColor.White);
     _pieces = new List <IPiece> {
         _piece
     };
 }
 public DragDropPieceIntoSameStackCommand(IModel model, IPiece piece, int insertionIndex)
     : base(model)
 {
     Debug.Assert(piece.Stack.Pieces.Length > 1 && insertionIndex <= piece.Stack.Pieces.Length);
     this.piece        = piece;
     indexInStackAfter = (piece.IndexInStackFromBottomToTop < insertionIndex ? insertionIndex - 1 : insertionIndex);
     stack             = piece.Stack;
 }
示例#20
0
        bool IsCapturable(IPlayer player, IPiece movingPiece, IPiece targetPiece)
        {
            bool canMovingPieceTakePiece = movingPiece.CanTakePiece();
            bool isPieceCapturable       = targetPiece.IsCapturable();
            bool isSameOwner             = targetPiece.Owner == player;

            return(canMovingPieceTakePiece && isPieceCapturable && !isSameOwner);
        }
示例#21
0
 public DiagonalMoveFixture()
 {
     _sut    = new DiagonalMove();
     _piece  = Helper.GetMockedPieceAt(4, 4, PieceColor.Black);
     _pieces = new List <IPiece> {
         _piece
     };
 }
示例#22
0
 public Move(string startString, string endString, IPiece piece, MoveType type)
 {
     Start   = new Position(startString);
     End     = new Position(endString);
     Piece   = piece;
     Type    = type;
     IsAMove = true;
 }
示例#23
0
        public KingUserControl(IPiece piece) : this()
        {
            _Piece = piece;

            Figure.Fill = _Piece.Color == Color.White ?
                          new SolidColorBrush(Colors.Khaki) :
                          new SolidColorBrush(Colors.Black);
        }
示例#24
0
 private void HandlePromotion(IPiece piece, Position newPosition)
 {
     if ((piece.Color == PieceColor.White && newPosition.Rank == 8) ||
         (piece.Color == PieceColor.Black && newPosition.Rank == 1))
     {
         _eventAggregator.GetEvent <PromotePieceEvent>().Publish(piece.CurrentPosition);
     }
 }
示例#25
0
 public void CopyFrom(IPiece piece)
 {
     // TODO: test if same type of cell
     PosX        = piece.PosX;
     PosY        = piece.PosY;
     Orientation = piece.Orientation;
     Value       = piece.Value;
 }
示例#26
0
 public CaptureResult(bool isSuccess, IPiece capturer, IPiece captured, IPlayer formerOwner, IntegerVector2 from)
 {
     IsSuccess   = isSuccess;
     Capturer    = capturer;
     Captured    = captured;
     FormerOwner = formerOwner;
     From        = from;
 }
示例#27
0
 public CapturingPromotionMove(ISquare fromSquare, ISquare toSquare, IPiece movingPiece, IPiece capturedPiece, PieceType promotedToPieceType)
 {
     FromSquare          = fromSquare;
     ToSquare            = toSquare;
     MovingPiece         = movingPiece;
     CapturedPiece       = capturedPiece;
     PromotedToPieceType = promotedToPieceType;
 }
示例#28
0
 public CapturingMove(ISquare fromSquare, ISquare toSquare, IPiece movingPiece, IPiece capturedPiece, bool captured = true)
 {
     Captured      = captured;
     CapturedPiece = capturedPiece;
     FromSquare    = fromSquare;
     MovingPiece   = movingPiece;
     ToSquare      = toSquare;
 }
示例#29
0
 public EnPassantMove(ISquare fromSquare, ISquare toSquare, IPiece movingPiece, IPiece capturedPiece, ISquare capturedPieceSquare)
 {
     FromSquare          = fromSquare;
     ToSquare            = toSquare;
     MovingPiece         = movingPiece;
     CapturedPiece       = capturedPiece;
     CapturedPieceSquare = capturedPieceSquare;
 }
示例#30
0
 public PromotionMove(ISquare fromSquare, ISquare toSquare, IPiece movingPiece, PieceType promotedToPieceType, bool promoted = true)
 {
     FromSquare          = fromSquare;
     ToSquare            = toSquare;
     MovingPiece         = movingPiece;
     PromotedToPieceType = promotedToPieceType;
     Promoted            = promoted;
 }
示例#31
0
        public void MovePiece(IPiece piece, Cell destinationCell)
        {
            var previousPosition = piece.DestinationCell;

            destinationCell.Piece  = (Piece)piece;
            previousPosition.Piece = null;
            piece.DestinationCell  = destinationCell;
        }
示例#32
0
 public ChessPieceMoveIntegrationFixture()
 {
     _piece  = Helper.GetMockedPieceAt(0, 0, PieceColor.Black);
     _pieces = new List <IPiece> {
         _piece
     };
     _sut = new ChessPiece(new Position(), PieceColor.Black, PieceType.Knight);
 }
示例#33
0
 public void GivePiece(IPiece piece)
 {
     if (piece != null && !pieces.Contains(piece))
     {
         pieces.Add(piece);
         onPieceStrageCahnged.OnNext(Unit.Default);
     }
 }
示例#34
0
 public BlackPawnMoveFixture()
 {
     _sut    = new PawnMove();
     _piece  = Helper.GetMockedPieceAt(1, 7);
     _pieces = new List <IPiece> {
         _piece
     };
 }
示例#35
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="before">The before status</param>
 /// <param name="from">The starting square</param>
 /// <param name="to">The ending square</param>
 /// <param name="actor"></param>
 internal Move(BoardStatus before, int @from, int to, IPiece actor)
 {
     this.before = before;
     after       = before;// the after board status is initialized with the before status
     this.from   = from;
     this.to     = to;
     Actor       = actor;
 }
示例#36
0
        public static BattleResult DrawResult(IPiece attacker, IPiece attacked)
        {
            var drawResult = new BattleResult();

            drawResult.LostPieces.Add(attacker);
            drawResult.LostPieces.Add(attacked);
            return(drawResult);
        }
示例#37
0
 public Move(IPiece piece, Position from, Position to, float heuristic = 0, long evals = 0)
 {
     _piece     = piece;
     _from      = from;
     _to        = to;
     _heuristic = heuristic;
     _evals     = evals;
 }
 private IPiece[] CreatePieces(int count, IPlayer owner = null)
 {
     var pieces = new IPiece[count];
     for (var i = 0; i < count; i++)
     {
         pieces[i] = new DefaultPiece(owner);
     }
     return pieces;
 }
示例#39
0
文件: Board.cs 项目: kenkam/reversal
 public bool CanPlay(IPiece piece)
 {
     if (IsOutOfBounds(piece.Position) || IsOccupied(piece.Position))
     {
         return false;
     }
     
     return CapturesOpponentPiecesInAnyDirection(piece);
 }
示例#40
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PieceBase"/> class.
 /// </summary>
 /// <param name="piece">The piece.</param>
 public PieceBase(IPiece piece)
     : this(piece.Color, null, piece.Position)
 {
     if (piece is PieceBase)
     {
         this.GameEvent = (piece as PieceBase).GameEvent;
         this.gameboard = (piece as PieceBase).Gameboard;
     }
 }
示例#41
0
 public void TestInit()
 {
     var locationMock = new Mock<ILocation>();
     locationMock.SetupGet(m => m.X).Returns(1);
     locationMock.SetupGet(m => m.Y).Returns(1);
     _piece = _PIECE_BUILDER
                 .ColorIs(_color)
                 .TypeIs(_type)
                 .LocationIs(locationMock.Object)
                 .Build();
 }
示例#42
0
        public bool MoveIsAllowed(IPiece piece, ILocation target)
        {
            if (!Board.IsInBounds(target))
                return false;

            foreach (var l in AllowedMoves(piece))
                if (l.X == target.X && l.Y == target.Y)
                    return true;

            return false;
        }
示例#43
0
 public void PerformMove(IPiece piece, ILocation target)
 {
     if(MoveIsAllowed(piece, target))
     {
         if(ThrowAtTarget(piece.Color, target))
         {
             _board.Remove(_board.GetPiece(target));
         }
         _board.SetLocation(piece, target);
     }
 }
示例#44
0
文件: Board.cs 项目: jsok/Chess
        /// <summary>
        /// Place a piece on the board. Only a VALID placement is acceptable.
        /// </summary>
        /// <param name="piece">Piece to be placed</param>
        /// <returns>True if placement was successful</returns>
        public Boolean placeOnBoard(IPiece piece)
        {
            if (validPosition(piece, piece.Position) != Position.Placement.VALID)
            {
                return false;
            }

            board[piece.Position.Column, piece.Position.Row] = piece;

            return true;
        }
示例#45
0
文件: Board.cs 项目: kenkam/reversal
        public void Play(IPiece piece)
        {
            if (!CanPlay(piece))
            {
                throw new InvalidOperationException($"Invalid move for {piece}");
            }

            pieceBag.Add(piece);
            foreach (var direction in Direction.All())
            {
                contiguousOpponentPieces.Capture(pieceBag, piece, direction);
            }
        }
示例#46
0
 public override void Apply(IGameState state)
 {
     if (state is ChessState)
     {
         CapturedPiece = state[EnemyPawn(state as ChessState)];
         RemovePiece(CapturedPiece.Pos, state);
         MovePiece(From, To, state);
     }
     else
     {
         throw new ArgumentException();
     }
 }
示例#47
0
        public Image GetImage(IPiece figure)
        {
            int row = GetRow(figure.Color);
            int column = GetColumn(figure.Type);
            if (_imageArray[row, column] == null)
            {
                var bmp = new System.Drawing.Bitmap(_image);
                var rect = new Rectangle(133 * column , 133 * row, 133, 133);
                _imageArray[row, column] = bmp.Clone(rect, _image.PixelFormat);
            }

            return _imageArray[row, column];
        }
示例#48
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlayerChess"/> class.
        /// </summary>
        /// <param name="color">The piece color.</param>
        /// <param name="gameboard">The gameboard.</param>
        public PlayerChess(IPieceColor color, Gameboard gameboard)
            : base(color)
        {
            IPiece newPiece;
            int offset = 0;

            this.gameboard = gameboard;
            this.selectedPiece = null;

            if (color == IPieceColor.White)
            {
                offset = 7;
            }
            else if (color == IPieceColor.Black)
            {
                offset = 0;
            }

            for (int i = 0; i < 8; i++)
            {
                newPiece = new Pawn(color, gameboard, new Position(i, Math.Abs(offset - 1)));
                newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
                this.PieceList.Add(newPiece);
            }

            newPiece = new Rook(color, gameboard, new Position(0, offset));
            newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
            this.PieceList.Add(newPiece);
            newPiece = new Rook(color, gameboard, new Position(7, offset));
            newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
            this.PieceList.Add(newPiece);
            newPiece = new Knight(color, gameboard, new Position(1, offset));
            newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
            this.PieceList.Add(newPiece);
            newPiece = new Knight(color, gameboard, new Position(6, offset));
            newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
            this.PieceList.Add(newPiece);
            newPiece = new Bishop(color, gameboard, new Position(2, offset));
            newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
            this.PieceList.Add(newPiece);
            newPiece = new Bishop(color, gameboard, new Position(5, offset));
            newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
            this.PieceList.Add(newPiece);
            newPiece = new Queen(color, gameboard, new Position(3, offset));
            newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
            this.PieceList.Add(newPiece);
            newPiece = new King(color, gameboard, new Position(4, offset));
            newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent);
            this.PieceList.Add(newPiece);
            this.King = newPiece;
        }
示例#49
0
        private IEnumerable<IPiece> GetContiguousOpponentPieces(IPieceBag pieceBag, IPiece startingPiece, Direction direction)
        {
            var piece = GetNextPieceFrom(pieceBag, startingPiece, direction);
            while (piece != null)
            {
                if (piece.Side == startingPiece.Side)
                {
                    yield break;
                }

                yield return piece;
                piece = GetNextPieceFrom(pieceBag, piece, direction);
            }
        }
示例#50
0
文件: Board.cs 项目: jasgrg/ChessApi
        public void AddPieceToBoard(short x, short y, IPiece piece)
        {
            if(piece != null)
            {
                if (piece.Player == Player.Dark)
                {
                    _darkPieces.Add(piece);
                }
                else
                {
                    _lightPieces.Add(piece);
                }
            }

            SetPiece(x, y, piece);
        }
示例#51
0
        private IEnumerable<IPiece> GetCapturablePieces(IPieceBag pieceBag, IPiece startingPiece, Direction direction)
        {
            var opponents = GetContiguousOpponentPieces(pieceBag, startingPiece, direction)
                .ToArray();
            if (!opponents.Any())
            {
                return Enumerable.Empty<IPiece>();
            }

            var nextPiece = GetNextPieceFrom(pieceBag, opponents.Last(), direction);
            if (nextPiece == null || nextPiece.Side != startingPiece.Side)
            {
                return Enumerable.Empty<IPiece>();
            }

            return opponents;
        }
示例#52
0
 public bool MovePiece(IPiece piece, BoardLocation newLocation)
 {
     RemovePiece (piece);
     piece.Location = newLocation;
     AddPiece (piece);
     return true;
     //			if (piece.CanPieceMove (newLocation))
     //			{
     //				RemovePiece (piece);
     //				piece.Location = newLocation;
     //				AddPiece (piece);
     //				return true;
     //			}
     //			else
     //			{
     //				return false;
     //			}
 }
示例#53
0
        private void Board_Click(object sender, System.EventArgs e)
        {
            IPiece clickedPiece = GetClickedPiece((Button)sender);

            if (_activePiece == null && clickedPiece != null)
            {
                if (clickedPiece.Color == Color.white)
                {
                    _activePiece = clickedPiece;
                    _activeButton = (Button)sender;
                }
            }
            else if(_activePiece != null)
            {
                _moveModule.PerformMove(_activePiece, _buttonHandler.GetButtonLocation((Button)sender));
                _activePiece = null;
                _activeButton = null;
            }
            UpdateBoard();
        }
        public Object GetPresentation(IPiece p)
        {
            var piece = p as ChessPiece;

            if (piece == null)
                throw new ArgumentException();

            var c = (piece.Type == PieceTypes.Pawn) ? 'p' : ((char?)Template.GetPresentation(piece)).Value;

            switch (p.Player.Order)
            {
                case 1:
                    c = Char.ToUpper(c);
                    break;
                case 2:
                    c = Char.ToLower(c);
                    break;
            }

            return c;
        }
示例#55
0
文件: FixedMove.cs 项目: jsok/Chess
        public List<Position> applyMove(Board board, IPiece piece)
        {
            Position p = piece.Position;
            Position possible = new Position(p.Column + x, p.Row + y);

            List<Position> moves = new List<Position>();
            Position.Placement placement = board.validPosition(piece, possible);

            switch (placement)
            {
                case Position.Placement.VALID:
                case Position.Placement.CAPTURE:
                    moves.Add(possible);
                    break;

                case Position.Placement.BLOCKED:
                case Position.Placement.ILLEGAL:
                default:
                    break;
            }

            return moves;
        }
示例#56
0
 public IMoveBuilder PieceIs(IPiece piece)
 {
     _piece = piece;
     return this;
 }
示例#57
0
 private Move(IPiece piece, ILocation target)
 {
     _piece = piece;
     _target = target;
 }
示例#58
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChessPiece"/> class.
 /// </summary>
 /// <param name="piece">The piece.</param>
 public ChessPiece(IPiece piece)
     : base(piece)
 {
 }
示例#59
0
 public SpawnPiece(IPiece piece, Location location)
 {
     Piece = piece;
     Location = location;
 }
示例#60
0
 private void SpawnPiece(Rank rank, File file, IPiece piece)
 {
     _events.Add(new SpawnPiece(piece, new Location(rank, file)));
 }