public RoverTest() { map.Setup(x => x.MaxX).Returns(5); map.Setup(x => x.MaxY).Returns(5); rover = new Rover(map.Object); rover.RoverDirection = Direction.N; }
private void GetRoverCommand(BaseRover rover) { Console.Write("Koordinatlarını girdiğiniz rover için hareket komutlarını giriniz. [L R M] = "); var commands = Console.ReadLine(); if (InputValidator.CheckMoveCommands(commands)) { rover.MoveCommandString = commands; return; } GetRoverCommand(rover); }
static void WaitForMap(BaseRover rover) { try { var command = Console.ReadLine(); if (Validator.ValidateMapCommand(command)) { rover.Map = Map.Parse(command); WaitForInstructions(rover); } else { throw new ApplicationException("Invalid map command " + command); } } catch (Exception ex) { Console.WriteLine(ex.Message); WaitForMap(rover); } }
static void WaitForInstructions(BaseRover rover) { try { var command = Console.ReadLine(); if (Validator.ValidateMapCommand(command)) { // NASA can reset the rover's map rover.Map = Map.Parse(command); command = Console.ReadLine(); } if (Validator.ValidatePositionCommand(command)) { rover.CurrentPosition = Position.Parse(command); } else { throw new ApplicationException(string.Format("Invalid position command [{0}]", command)); } command = Console.ReadLine(); if (Validator.ValidateMoveCommand(command)) { rover.Move(command); } else { throw new ApplicationException(string.Format("Invalid move command [{0}]", command)); } Console.WriteLine(rover.CurrentPosition.ToString()); WaitForInstructions(rover); } catch (Exception ex) { Console.WriteLine(ex.Message); WaitForInstructions(rover); } }