Пример #1
0
        public Position Execute(Position currentPosition, IPositionValidator positionValidator)
        {
            if (currentPosition == null)
            {
                return(currentPosition);
            }

            Position newPosition = new Position(currentPosition);

            newPosition.X = currentPosition.X + XCoordChanges[currentPosition.Facing];
            newPosition.Y = currentPosition.Y + YCoordChanges[currentPosition.Facing];

            if (!positionValidator.Validate(newPosition))
            {
                return(currentPosition);
            }

            return(newPosition);
        }
Пример #2
0
        public Position Execute(Position currentPosition, IPositionValidator positionValidator)
        {
            try
            {
                Position newPosition = new Position
                {
                    Facing = GetDirectionParameter(),
                    X      = GetXParameter(),
                    Y      = GetYParameter()
                };

                if (!positionValidator.Validate(newPosition))
                {
                    return(currentPosition);
                }
                return(newPosition);
            }
            catch
            {
                return(currentPosition);
            }
        }