private void DriveRover(Plateau p) { bool isDriving = true; Console.WriteLine(string.Format("Plateau Bounds: North = {0}, East = {1}, South = {2}, West = {3}", p.NorthBounds, p.EastBounds, p.SouthBounds, p.WestBounds)); while (isDriving == true) { Console.WriteLine(string.Format("Current Rover Location & Heading: ({0},{1}) {2}", CurrentXPos, CurrentYPos, CurrentHeading)); Console.WriteLine(string.Format("Enter Driving Commands (L,R,M):")); string drivingCommand = Console.ReadLine().Replace(" ", string.Empty); if (IsValidDrivingCommand(drivingCommand)) { SetRoverPath(p, drivingCommand); bool roverValidResponse = false; string pilotInput = "Y"; while (roverValidResponse == false) { Console.WriteLine(string.Format("Current Rover Location & Heading: ({0},{1}) {2}", CurrentXPos, CurrentYPos, CurrentHeading)); Console.WriteLine("Do you want to continue driving the Mars Rover? (Y/N)"); pilotInput = Console.ReadLine().Replace(" ", string.Empty); if (pilotInput != "Y" && pilotInput != "y" && pilotInput != "N" && pilotInput != "n") { Console.WriteLine("Answer must be Y or N"); continue; } else { Console.Clear(); roverValidResponse = true; } } if (pilotInput == "N" || pilotInput == "n") { isDriving = false; } } else { Console.ReadLine(); Console.Clear(); } } }
private void SetNorthernPlateauBounds(Plateau p) { bool validBounds = false; while (validBounds == false) { Console.WriteLine("What is the northern bounds of the Mars plateau? "); string plateauNorthernBounds = Console.ReadLine().Replace(" ", string.Empty); try { int northernBounds = int.Parse(plateauNorthernBounds); if (northernBounds >= 1) { p.NorthBounds = northernBounds; validBounds = true; Console.Clear(); } else { Console.WriteLine("Northern bounds cannot be less than 1."); Console.ReadLine(); Console.Clear(); } } catch (FormatException) { Console.WriteLine("Northern bounds does not have only integer values."); Console.ReadLine(); Console.Clear(); } catch (OverflowException) { Console.WriteLine(string.Format("Northern bounds cannot be greater than {0}.", int.MaxValue)); Console.ReadLine(); Console.Clear(); } catch (Exception e) { Console.WriteLine(string.Format("Uncaught Exception: {0}", e)); Console.ReadLine(); Console.Clear(); } } }
public void SetPlateau(Plateau plateau) { this.plateau = plateau; }
private void DeterminePlateauBounds(Plateau p) { SetNorthernPlateauBounds(p); SetEasternPlateauBounds(p); }