Ejemplo n.º 1
0
        public Position Move(char[] moves, IArea area)
        {
            foreach (var move in moves)
            {
                switch (move)
                {
                case 'M':
                    _moveForward[_position.Direction].Invoke();
                    break;

                case 'L':
                    _rotateLeft[_position.Direction].Invoke();
                    break;

                case 'R':
                    _rotateRight[_position.Direction].Invoke();
                    break;

                default:
                    throw new Exception($"Invalid Character {move}");
                }
            }

            if (!area.IsValid(_position))
            {
                throw new Exception($"{_position.X},{_position.Y} is out of area");
            }
            return(_position);
        }
Ejemplo n.º 2
0
        public void SetPosition(Position position, IArea area)
        {
            if (!area.IsValid(position))
            {
                var size             = area.GetSize();
                var exceptionMessage = string.Format("Deploy failed for point ({0},{1}). Plateau size is {2} x {3}.",
                                                     position.X, position.Y, size.Width, size.Height);
                throw new Exception(exceptionMessage);
            }

            _position.X         = position.X;
            _position.Y         = position.Y;
            _position.Direction = position.Direction;
        }