Example #1
0
 public Rover(Plateau plateau, Position position, Direction direction)
 {
     if (!plateau.Contains(position))
     {
         throw new ArgumentOutOfRangeException(nameof(position), "Position must be within the plateau.");
     }
     Position  = position;
     Direction = direction;
     Plateau   = plateau;
 }
Example #2
0
        private void HandleMovement()
        {
            Position offset;

            switch (Direction)
            {
            case Direction.N: offset = new Position(0, 1); break;

            case Direction.E: offset = new Position(1, 0); break;

            case Direction.S: offset = new Position(0, -1); break;

            case Direction.W: offset = new Position(-1, 0); break;

            default: offset = new Position(0, 0); break;
            }
            var newPosition = Position + offset;

            if (Plateau.Contains(newPosition))
            {
                Position = newPosition;
            }
        }