private static void ConfigureItems(int itemsCount, Map map) { for (int i = 0; i < itemsCount; i++) { var coordinates = GetItemCoordinates(); map.AddItem(int.Parse(coordinates[0]), int.Parse(coordinates[1])); } }
public static void Main(string[] args) { int itemsCount = ReadItemsCount(); Map map = new Map(); Robot robot = new Robot(new ConsoleCommandProvider()); ConfigureItems(itemsCount, map); robot.CollectItems(map); PrintResult(robot.ItemsCollected); }
public void CollectItems(Map map) { foreach (var command in commandProvider.GetCommands()) { HandleRobotCommand(command, map); } }
private void HandleRobotCommand(char command, Map map) { switch (command) { case Commands.Left: case Commands.Right: Direction = directionsMap[new KeyValuePair<char, Direction>(command, Direction)]; dimention = dimention == Dimention.Horizontal ? Dimention.Vertical : Dimention.Horizontal; break; case Commands.Forward: RobotXCoord += Steps.StepForward; RobotYCoord += Steps.StepForward; CheckItemPresence(map); break; case Commands.Back: RobotXCoord += Steps.StepBack; RobotYCoord += Steps.StepBack; CheckItemPresence(map); break; } }
private void CheckItemPresence(Map map) { if (map.HasItemAtCoords(RobotXCoord, RobotYCoord)) { map.RemoveItem(RobotXCoord, RobotYCoord); ItemsCollected++; } }