public IRobot FromRobotDTOToRobot(InputRobotDTO robotDTO) { IRobot robot = null; if (robotDTO != null) { robot = _robotFactory.GetRobot(); robot.Id = robotDTO.Id; robot.Position.Location = _arenaMapper.FromArenaCoordinatesDTOToArenaCoordinates(robotDTO.StartLocation); CompassPoint hd; if (Enum.TryParse(robotDTO.StartHeadingDirection, out hd)) { robot.Position.Heading = hd; } else { throw new Exception("Cannot parse robot's start heading direction"); } if (robotDTO.BattleMoves != null && robotDTO.BattleMoves.Count > 0) { robotDTO.BattleMoves.ForEach(move => { RobotMove rm; if (Enum.TryParse(move, out rm)) { robot.BattleMoves.Add(rm); } else { throw new Exception("Cannot parse robot's battle move"); } }); } } return(robot); }
private static InputCompetitionDataDTO ReadInputCompetitionData() { var console = serviceContainer.GetInstance <IConsoleWrapper>(); var inputData = new InputCompetitionDataDTO(); var defaultArenaBottomLeftCoords = "0 0"; inputData.ArenaBottomLeftCoords.TryParseInputCoords(defaultArenaBottomLeftCoords); console.Write(">>> Enter upper-right coordinates of the arena in the format [X Y] (e.g: 5 5): "); inputData.ArenaUpperRightCoords.TryParseInputCoords(console.ReadArenaUpperRightCoords()); int robotIx = 1; bool enterNextRobotToDeploy = true; while (enterNextRobotToDeploy) { var robotToDeploy = new InputRobotDTO { Id = robotIx }; console.WriteLine(">>> Enter robot # {0} configuration", robotIx); console.Write(">>> robot's position and orientation in the format [X Y Orientation:[N,S,E,W]] (e.g: 1 2 N): "); robotToDeploy.TryParseInputLocationAndHeadingDirection(console.ReadRobotLocationAndHeadingDirection()); console.Write(">>> robot's battle moves in the format [M1M2...Mn, where Mn:[L,R,M]] (e.g: LMLMLM): "); robotToDeploy.TryParseInputBattleMoves(console.ReadRobotBattleMoves()); console.Write("Enter next robot to deploy [Y/N]?: "); var proceed = console.ReadLine(); enterNextRobotToDeploy = proceed != null && proceed.Equals("Y", StringComparison.InvariantCultureIgnoreCase); inputData.RobotsToDeploy.Add(robotToDeploy); robotIx++; } return(inputData); }