static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Please specify the settings file and the moves file as program arguments."); return; } #if DEBUG var settingsFile = args.Length > 0 ? args[0] : "game-settings.txt"; var movesFilePath = args.Length > 1 ? args[1] : "moves.txt"; #else var settingsFile = args[0]; var movesFilePath = args[1]; #endif if (string.IsNullOrWhiteSpace(movesFilePath)) { throw new ArgumentException("Moves file path missing", nameof(movesFilePath)); } var game = new TurtleGame(settingsFile); var moves = ParseMoves(movesFilePath); for (int i = 0; i < moves.Length; i++) { var moveSet = moves[i]; var result = game.GetResult(moveSet); Console.WriteLine($"Sequence {i + 1}: {result}!."); } #if DEBUG //Press any key to Exit Console.WriteLine("Press any key to exit"); Console.ReadKey(); #endif }
public static void Run(string filePath) { string line; int counter = 0; LocationData boardDimension = null; LocationData exitLocation = null; LocationData startingPositon = null; TurtleGame EscapeMinesGame = null; List <LocationData> mineLocations = new List <LocationData>(); using (StreamReader file = new StreamReader(filePath)) { while ((line = file.ReadLine()) != null) { counter++; string[] lineArray; if (counter < 5) { //Configuration switch (counter) { case 1: //Get Board Dimension lineArray = line.Split(' '); boardDimension = new LocationData { X = int.Parse(lineArray[0]), Y = int.Parse(lineArray[1]) }; break; case 2: //Get Mines Locations lineArray = line.Split(' '); foreach (var dimension in lineArray) { var mines = dimension.Split(','); mineLocations.Add(new LocationData { X = int.Parse(mines[0]), Y = int.Parse(mines[1]) }); } break; case 3: //Get Exit Location lineArray = line.Split(' '); exitLocation = new LocationData { X = int.Parse(lineArray[0]), Y = int.Parse(lineArray[1]) }; break; case 4: //Get Starting Postion and Direction lineArray = line.Split(' '); startingPositon = new LocationData { X = int.Parse(lineArray[0]), Y = int.Parse(lineArray[1]) }; var initialDirection = (DirectionEnum)Enum.Parse(typeof(DirectionEnum), lineArray[2]); //Create Board EscapeMinesGame = new TurtleGame(boardDimension, initialDirection, exitLocation, startingPositon, mineLocations.ToArray()); break; } } else { //Read Turtle Moves Console.WriteLine($"Sequence {counter-4}: {EscapeMinesGame.MoveTurtle(line).GetDescription()}"); } } } }