public Rover(Plateau p, string start, bool v) { //store a record of the plateau this rover exists on plateau = p; //split currPosition into current/start x and y and the orientation string[] currPositions = start.Split((string[])null, StringSplitOptions.RemoveEmptyEntries); startX = currX = Int32.Parse(currPositions[0]); startY = currY = Int32.Parse(currPositions[1]); startOrientation = currOrientation = currPositions[2]; verbose = v; }
static void Main(string[] args) { int line_count = 1; int rover_count = 1; bool verbose; //make sure that an input file was passed in if (args.Length == 0) { Console.WriteLine("Usage: RoverSimulation.exe c:\\path\\to\\input_file.txt"); return; } if (!File.Exists(@args[0])) { Console.WriteLine("The specified input ( " + @args[0] + " ) file can not be read."); return; } //read the input file into an array string[] inputFile = File.ReadAllLines(@args[0], Encoding.UTF8); //if -v was added to the end, turn on verbose mode if (args.Length == 2 && @args[1].Equals("-v")) { verbose = true; } else { verbose = false; } //don't do anything if there's no data if (inputFile.Length == 0) { Console.WriteLine("The input file has no valid data."); return; } //Create the plateau dimension string topRightIndices = inputFile[0]; Plateau plateau = new Plateau(topRightIndices); while (line_count < inputFile.Length) { Console.WriteLine("\nMoving Rover " + rover_count + ":" + "\nStarting Coordinates: " + inputFile[line_count]); //create a new rover, passing the top right indices of the plateau and the starting position of the rover Rover rover = new Rover(plateau, inputFile[line_count], verbose); //command the rover to move based on the instructions read in try { rover.commandRover(inputFile[line_count + 1]); } catch (ArgumentException e) { Console.WriteLine("ArgumentException: {0}", e.Message); } line_count += 2; rover_count++; } Console.WriteLine("All rovers have been moved!"); }