コード例 #1
0
 public Rover(int x, int y, Direction direction, ILandingSurface landingSurface)
 {
     X              = x;
     Y              = y;
     Direction      = direction;
     LandingSurface = landingSurface;
 }
コード例 #2
0
 public Rover(ILandingSurface landingSurface, INavigationAdvisor navigationAdvisor, IReport report, IValidator validator)
 {
     _landingSurface    = landingSurface;
     _navigationAdvisor = navigationAdvisor;
     _report            = report;
     _validator         = validator;
 }
コード例 #3
0
        public Orientation Navigate(ILandingSurface landingSurface, CardinalDirection currentCardinalDirection, Position currentPosition, Movement movement)
        {
            Orientation orientation = new Orientation
            {
                Position = new Position
                {
                    X = currentPosition.X,
                    Y = currentPosition.Y
                },
                CardinalDirection = currentCardinalDirection
            };

            IDictionary <Movement, Action>          movementMethodDictionary = new Dictionary <Movement, Action>();
            IDictionary <CardinalDirection, Action> leftMoveDictionary       = new Dictionary <CardinalDirection, Action>();
            IDictionary <CardinalDirection, Action> rightMoveDictionary      = new Dictionary <CardinalDirection, Action>();
            IDictionary <CardinalDirection, Action> forwardMoveDictionary    = new Dictionary <CardinalDirection, Action>();

            movementMethodDictionary = new Dictionary <Movement, Action>
            {
                { Movement.SpinLeft, () => leftMoveDictionary[currentCardinalDirection].Invoke() },
                { Movement.SpinRight, () => rightMoveDictionary[currentCardinalDirection].Invoke() },
                { Movement.StepForward, () => forwardMoveDictionary[currentCardinalDirection].Invoke() }
            };

            leftMoveDictionary = new Dictionary <CardinalDirection, Action>
            {
                { CardinalDirection.North, () => orientation.CardinalDirection = CardinalDirection.West },
                { CardinalDirection.East, () => orientation.CardinalDirection = CardinalDirection.North },
                { CardinalDirection.South, () => orientation.CardinalDirection = CardinalDirection.East },
                { CardinalDirection.West, () => orientation.CardinalDirection = CardinalDirection.South }
            };

            rightMoveDictionary = new Dictionary <CardinalDirection, Action>
            {
                { CardinalDirection.North, () => orientation.CardinalDirection = CardinalDirection.East },
                { CardinalDirection.East, () => orientation.CardinalDirection = CardinalDirection.South },
                { CardinalDirection.South, () => orientation.CardinalDirection = CardinalDirection.West },
                { CardinalDirection.West, () => orientation.CardinalDirection = CardinalDirection.North }
            };

            forwardMoveDictionary = new Dictionary <CardinalDirection, Action>
            {
                { CardinalDirection.North, () => { orientation.Position = new Position(currentPosition.X, currentPosition.Y + STEPINCREMENT); } },
                { CardinalDirection.East, () => { orientation.Position = new Position(currentPosition.X + STEPINCREMENT, currentPosition.Y); } },
                { CardinalDirection.South, () => { orientation.Position = new Position(currentPosition.X, currentPosition.Y - STEPINCREMENT); } },
                { CardinalDirection.West, () => { orientation.Position = new Position(currentPosition.X - STEPINCREMENT, currentPosition.Y); } }
            };

            movementMethodDictionary[movement].Invoke();

            if (!landingSurface.IsValid(orientation.Position))
            {
                var exceptionMessage = string.Format("Rover has moved out of bounds ({0},{1}). Landing surface size is {2}.",
                                                     orientation.Position.X, orientation.Position.Y, landingSurface.GetSize().GetFormattedDescription());
                throw new NavigatedOutOfBoundsException(exceptionMessage);
            }

            return(orientation);
        }
コード例 #4
0
        private static void throwDeployException(ILandingSurface aLandingSurface, Point aPoint)
        {
            var size             = aLandingSurface.GetSize();
            var exceptionMessage = String.Format("Deploy failed for point ({0},{1}). Landing surface size is {2} x {3}.",
                                                 aPoint.X, aPoint.Y, size.Width, size.Height);

            throw new RoverDeployException(exceptionMessage);
        }
コード例 #5
0
ファイル: Rover.cs プロジェクト: mfguleryuz/MarsRover
        public Rover(ILandingSurface landingSurface, string roverPosition, string roverCommands)
        {
            this.TranslateRoverPosition(roverPosition);

            if (RoverIsBetweenLandingCoordinates(landingSurface))
            {
                this.TranslateRoverCommands(roverCommands);
            }
        }
コード例 #6
0
 public void RoverIsWithinLandingCoordinate(ILandingSurface landingSurface)
 {
     if ((this.XCoordinate < 0) || (this.XCoordinate > landingSurface.Width) || (this.YCoordinate < 0) || (this.YCoordinate > landingSurface.Height))
     {
         this.DirectionFacing = Facing.OUTOFBound;
         this.XCoordinate     = 0;
         this.YCoordinate     = 0;
     }
 }
コード例 #7
0
ファイル: CommandCenter.cs プロジェクト: ilhanozhamur/Move
 public CommandCenter(ILandingSurface aLandingSurface, ICommandParser aCommandParser, ICommandInvoker aCommandInvoker, IReportComposer aReportComposer)
 {
     rovers         = new List <IRover>();
     landingSurface = aLandingSurface;
     commandParser  = aCommandParser;
     commandInvoker = aCommandInvoker;
     reportComposer = aReportComposer;
     commandInvoker.SetLandingSurface(landingSurface);
     commandInvoker.SetRovers(rovers);
 }
コード例 #8
0
 public CommandCenter(ILandingSurface aLandingSurface, ICommandParser aCommandParser, ICommandInvoker aCommandInvoker, IReportComposer aReportComposer)
 {
     rovers = new List<IRover>();
     landingSurface = aLandingSurface;
     commandParser = aCommandParser;
     commandInvoker = aCommandInvoker;
     reportComposer = aReportComposer;
     commandInvoker.SetLandingSurface(landingSurface);
     commandInvoker.SetRovers(rovers);
 }
コード例 #9
0
        public void Move(IEnumerable <Movement> movements, ILandingSurface landingSurface)
        {
            foreach (var move in movements)
            {
                var orientation = _navigator.Navigate(landingSurface, CardinalDirection, Position, move);

                Position          = orientation.Position;
                CardinalDirection = orientation.CardinalDirection;
            }
        }
コード例 #10
0
        public void Deploy(ILandingSurface aLandingSurface, Point aPoint, CardinalDirection aDirection)
        {
            if (aLandingSurface.IsValid(aPoint))
            {
                Position          = aPoint;
                CardinalDirection = aDirection;
                isDeployed        = true;
                return;
            }

            throwDeployException(aLandingSurface, aPoint);
        }
コード例 #11
0
        public Rover(ILandingSurface landingSurface, string roverPosition, string roverCommands)
        {
            _LandingSurface = landingSurface;
            SetRoverPosition(roverPosition);

            if (!RoverIsWithinLandingCoordinates())
            {
                return;
            }

            _RoverCommands = roverCommands;
        }
コード例 #12
0
ファイル: Rover.cs プロジェクト: MadhuraAgharkar/rover
 public Rover(ILandingSurface landingSurface, string roverPosition, string roverCommands)
 {
     TranslateRoverPosition(roverPosition);
     if (!IsWithinLandingSurface(landingSurface))
     {
         throw new InvalidOperationException();
     }
     else
     {
         TranslateRoverCommands(roverCommands);
     }
 }
コード例 #13
0
        public Mission(ILandingSurface landingSurface, ICommandParser commandParser, ICommandInvoker commandInvoker, IReportBuilder reportBuilder)
        {
            _rovers = new List <IRover>();

            _commandParser  = commandParser;
            _commandInvoker = commandInvoker;

            _commandInvoker.SetLandingSurface(landingSurface);
            _commandInvoker.SetRovers(_rovers);

            _reportBuilder = reportBuilder;
        }
コード例 #14
0
        public void Deploy(ILandingSurface landingSurface, Position position, CardinalDirection cardinalDirection)
        {
            if (!landingSurface.IsValid(position))
            {
                var exceptionMessage = string.Format("Deploy failed for point ({0},{1}). Landing surface size is {2}.",
                                                     position.X, position.Y, landingSurface.GetSize().GetFormattedDescription());
                throw new RoverDeployException(exceptionMessage);
            }

            Position          = position;
            CardinalDirection = cardinalDirection;
            _isDeployed       = true;
        }
コード例 #15
0
        public Rover(List <IRover> squad, ILandingSurface landingSurface, string roverPosition, string roverCommands)
        {
            this.Squad = squad;

            this.TranslateRoverPosition(roverPosition);

            if (!RoverIsWithinLandingCoordinates(landingSurface))
            {
                return;
            }

            this.TranslateRoverCommands(roverCommands);
        }
コード例 #16
0
        public Rover(List <IRover> squad, ILandingSurface landingSurface, string roverPosition, string roverCommands)
        {
            this.Squad = squad;


            this.TranslateRoverPosition(roverPosition);



            this.TranslateRoverCommands(roverCommands);

            this.RoverIsWithinLandingCoordinate(landingSurface);

            this.Height = landingSurface.Height;
            this.Width  = landingSurface.Width;
        }
コード例 #17
0
ファイル: Houston.cs プロジェクト: kagantantan/MarsRover
 public Houston(ILandingSurface landingSurface, CommandManager commandManager)
 {
     _landingSurface = landingSurface;
     _commandManager = commandManager;
 }
コード例 #18
0
 public void SetLandingSurface(ILandingSurface aLandingSurface)
 {
     landingSurface = aLandingSurface;
 }
コード例 #19
0
 public void SetReceivers(IRover aRover, ILandingSurface aLandingSurface)
 {
     rover          = aRover;
     landingSurface = aLandingSurface;
 }
コード例 #20
0
ファイル: Rover.cs プロジェクト: mfguleryuz/MarsRover
 private bool RoverIsBetweenLandingCoordinates(ILandingSurface landingSurface)
 {
     return((this.XCoordinate >= 0) && (this.XCoordinate < landingSurface.Width) &&
            (this.YCoordinate >= 0) && (this.YCoordinate < landingSurface.Height));
 }
コード例 #21
0
 public void SetReceivers(IRover aRover, ILandingSurface aLandingSurface)
 {
     rover = aRover;
     landingSurface = aLandingSurface;
 }
コード例 #22
0
 public void SetLandingSurface(ILandingSurface aLandingSurface)
 {
     landingSurface = aLandingSurface;
 }
コード例 #23
0
 public RoverSquad(ILandingSurface landingSurface)
 {
     this.LandingSurface = landingSurface;
 }
コード例 #24
0
 public void SetReceiver(ILandingSurface aLandingSurface)
 {
     landingSurface = aLandingSurface;
 }
コード例 #25
0
 public PlataueCommandExecuter(IServiceProvider serviceProvider)
 {
     _landingSurface = serviceProvider.GetService <ILandingSurface>();
 }
コード例 #26
0
 public RoverSquadManager(ILandingSurface landingSurface)
 {
     LandingSurface = landingSurface;
 }
コード例 #27
0
ファイル: Rover.cs プロジェクト: MadhuraAgharkar/rover
 private bool IsWithinLandingSurface(ILandingSurface landingSurface)
 {
     return((XCoordinate >= 0) && (XCoordinate < landingSurface.XCoordinate) &&
            (YCoordinate >= 0) && (YCoordinate < landingSurface.YCoordinate));
 }
コード例 #28
0
 public void SetReceiver(ILandingSurface aLandingSurface)
 {
     landingSurface = aLandingSurface;
 }
コード例 #29
0
ファイル: SurfacesTest.cs プロジェクト: WicMan101/MarsRover
 public void InitializeTest()
 {
     _StaticCoordinatesSurface = new Surface(8, 8);
 }