示例#1
0
        public void Move(Piece piece, Position destination)
        {
            Position currentPos = _board.GetCurrentPosition(piece);

            int deltaX = destination.X - currentPos.X;
            int deltaY = destination.Y - currentPos.Y;

            Vector moveVector;

            if (_originColor == piece.Color)
            {
                Direction direction = (Direction)0;

                if (deltaX > 0)
                {
                    direction |= Direction.Forward;
                }
                else if (deltaX < 0)
                {
                    direction |= Direction.Backward;
                }

                if (deltaY > 0)
                {
                    direction |= Direction.Left;
                }
                else if (deltaY < 0)
                {
                    direction |= Direction.Right;
                }

                if (!Enum.IsDefined(typeof(Direction), direction))
                {
                    throw new InvalidOperationException();
                }
            }
        }