public void Rotate(Rotate rotation) { switch (rotation) { case Contracts.Rotate.Left: Bearing = RotateLeft(Bearing); break; case Contracts.Rotate.Right: Bearing = RotateRight(Bearing); break; default: throw new ArgumentOutOfRangeException("rotation", rotation, null); } }
public void AfterMaximumNumberOfCommandsExecutedDoesRoverReportItsPositionAndHeading() { //Arrange CardinalHeading reportedHeading = CardinalHeading.South; ICoordinates reportedCoordinates = new Coordinates() { X = 0, Y = 0 }; _roverController.RaiseLocationReport += delegate(object sender, LocationHeadingEventArg e) { reportedHeading = e.Heading; reportedCoordinates = e.Location; }; //Act _roverController.AddCommand(new MoveCommand(_rover) { Distance = 50 }); _roverController.AddCommand(new RotateCommand(_rover) { Rotation = Rotate.Left }); _roverController.AddCommand(new MoveCommand(_rover) { Distance = 23 }); _roverController.AddCommand(new RotateCommand(_rover) { Rotation = Rotate.Left }); _roverController.AddCommand(new MoveCommand(_rover) { Distance = 4 }); //Assert Assert.AreEqual(24, reportedCoordinates.X); Assert.AreEqual(46, reportedCoordinates.Y); Assert.AreEqual(CardinalHeading.North, reportedHeading); }
public Navigation(IPlanet planet, ICompass compass, ICoordinates initialLocation, CardinalHeading initialHeading) { if (planet == null) { throw new ArgumentNullException("planet"); } if (compass == null) { throw new ArgumentNullException("compass"); } if (initialLocation == null) { throw new ArgumentNullException("initialLocation"); } Location = initialLocation; Heading = initialHeading; Planet = planet; Compass = compass; }
private CardinalHeading RotateRight(CardinalHeading heading) { CardinalHeading newHeading = heading; switch (heading) { case CardinalHeading.North: newHeading = CardinalHeading.East; break; case CardinalHeading.East: newHeading = CardinalHeading.South; break; case CardinalHeading.South: newHeading = CardinalHeading.West; break; case CardinalHeading.West: newHeading = CardinalHeading.North; break; } return(newHeading); }
public LocationHeadingEventArg(ICoordinates location, CardinalHeading heading) { Location = location; Heading = heading; }
public Compass() { Bearing = CardinalHeading.North; }