private static void performInstructions(ExplorationGrid grid, string instructions) { bool instructionPerformed = true; foreach (Char instruction in instructions) { instructionPerformed = grid.PerformInstruction((RoverInstruction)Enum.Parse(typeof(RoverInstruction), instruction.ToString())); if (!instructionPerformed) { Console.WriteLine("Error. Rover out of bounds. Aborting instructions."); break; } } }
private static void setPosition(ExplorationGrid grid) { bool inBounds = true; do { string[] initialPosition = getInitialPosition().Split(" "); inBounds = grid.ConfirmPosition(Int32.Parse(initialPosition[0]), Int32.Parse(initialPosition[1]), char.Parse(initialPosition[2])); if (!inBounds) { Console.WriteLine("Mars Rover cannot leave the bounds of the map. Please enter valid position.\r\n"); } } while (!inBounds); }
static void Main(string[] args) { string[] gridBounds = getGridBounds().Split(" "); ExplorationGrid grid = new ExplorationGrid(Int32.Parse(gridBounds[0]), Int32.Parse(gridBounds[1])); setPosition(grid); performInstructions(grid, getInstructions()); Console.WriteLine("Rover Position: {0}\r\n", grid.GetRoverPosition()); setPosition(grid); performInstructions(grid, getInstructions()); Console.WriteLine("Rover Position: {0}", grid.GetRoverPosition()); }