private ReportOutPutEntity GenerateReportOutPut(int horizontalCordinate, int verticalCordinate, string faceDirection, List <string> commandSet) { try { ReportOutPutEntity pacManReport = new ReportOutPutEntity(); PacManEntity populatedEntity = PopulatePacManEntity(horizontalCordinate, verticalCordinate, faceDirection, commandSet); //resolved location populatedEntity = locationResolver(populatedEntity); //Check wheter PacMan is out of Grid if (populatedEntity.isOutOfGrid) { pacManReport.responceMessage = OutOfGridText; } else { pacManReport.horizontalCordinate = populatedEntity.xCordinate; pacManReport.verticalCordinate = populatedEntity.yCordinate; pacManReport.responceMessage = populatedEntity.responceMessage; pacManReport.faceDirection = populatedEntity.faceDirection; pacManReport.isValiedCommands = populatedEntity.isCommandsValidated; pacManReport.responceMessage = populatedEntity.responceMessage; } return(pacManReport); } catch (Exception ex) { throw ex; } }
static void Main(string[] args) { PacManPresentation pacManPresentation = new PacManPresentation(new PacManMovementService()); //Implement the UI Console.WriteLine("--Welcome to PacMan Simulator--"); Console.Write("Please Enter Initial Place Command: "); string initialCommand = Console.ReadLine(); try { Console.Write("Please Enter X Cordination: "); int xCordination = Convert.ToInt32(Console.ReadLine()); Console.Write("Please Enter Y Cordination: "); int yCordination = Convert.ToInt32(Console.ReadLine()); Console.Write("Please Enter Direction: "); string direction = Console.ReadLine(); Console.Write("Please Enter Movement Commands(Comma Separated: "); string movementCommands = Console.ReadLine(); //Add the all commands to List List <string> commandsList = new List <string>(); commandsList.Add(initialCommand); foreach (var item in movementCommands.Split(',')) { commandsList.Add(item); } ReportOutPutEntity reportOutPut = pacManPresentation.FinalizePacManReport(xCordination, yCordination, direction, commandsList); if (reportOutPut.isValiedCommands) { Console.WriteLine(reportOutPut.faceDirection); Console.WriteLine(reportOutPut.horizontalCordinate); Console.WriteLine(reportOutPut.verticalCordinate); } Console.WriteLine(reportOutPut.responceMessage); } catch (FormatException) { Console.WriteLine("Input is not in correct Format"); } }
public void IsRunningWithoutReportCommand() { int horizontalCordinate = 2; int verticalCordinate = 2; string faceDirectionInput = "NORTH"; List <string> commands = new List <string>(); commands.Add("MOVE"); commands.Add("MOVE"); ReportOutPutEntity report = new ReportOutPutEntity(); PacManMovementService service = new PacManMovementService(); string actualResponceMessage = "Command is not in Correct Format"; report = service.ProduceReport(horizontalCordinate, verticalCordinate, faceDirectionInput, commands); Assert.AreEqual(report.responceMessage, actualResponceMessage); }
//Produsing the final outcome based on the user commands public ReportOutPutEntity ProduceReport(int horizontalCordinate, int verticalCordinate, string faceDirection, List <string> commandSet) { try { //Initiating the new pacMan Report instance to return final outcome. ReportOutPutEntity pacManReport = new ReportOutPutEntity(); pacManReport = GenerateReportOutPut(horizontalCordinate, verticalCordinate, faceDirection, commandSet); return(pacManReport); } catch (Exception ex) { throw ex; } }
public void IsPacManOutOfGrid() { int horizontalCordinate = 2; int verticalCordinate = 2; string faceDirectionInput = "EAST"; List <string> commands = new List <string>(); commands.Add("PLACE"); commands.Add("MOVE"); commands.Add("MOVE"); commands.Add("MOVE"); commands.Add("MOVE"); commands.Add("REPORT"); ReportOutPutEntity report = new ReportOutPutEntity(); PacManMovementService service = new PacManMovementService(); string actualResponceMessage = "Pac Man is Out of Grid"; report = service.ProduceReport(horizontalCordinate, verticalCordinate, faceDirectionInput, commands); Assert.AreEqual(report.responceMessage, actualResponceMessage); }
public void IsValiedReportOutput() { int horizontalCordinate = 2; int verticalCordinate = 2; string faceDirectionInput = "NORTH"; List <string> commands = new List <string>(); commands.Add("PLACE"); commands.Add("MOVE"); commands.Add("MOVE"); commands.Add("LEFT"); commands.Add("REPORT"); ReportOutPutEntity report = new ReportOutPutEntity(); PacManMovementService service = new PacManMovementService(); int actualHorizontalCordinate = 2; int actualVerticalCordinates = 4; string actualFaceDirection = "WEST"; report = service.ProduceReport(horizontalCordinate, verticalCordinate, faceDirectionInput, commands); Assert.AreEqual(report.horizontalCordinate, actualHorizontalCordinate); Assert.AreEqual(report.verticalCordinate, actualVerticalCordinates); Assert.AreEqual(report.faceDirection, actualFaceDirection); }