Ejemplo n.º 1
0
 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]));
     }
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 public void CollectItems(Map map)
 {
     foreach (var command in commandProvider.GetCommands())
     {
         HandleRobotCommand(command, map);
     }
 }
Ejemplo n.º 4
0
 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;
     }
 }
Ejemplo n.º 5
0
 private void CheckItemPresence(Map map)
 {
     if (map.HasItemAtCoords(RobotXCoord, RobotYCoord))
     {
         map.RemoveItem(RobotXCoord, RobotYCoord);
         ItemsCollected++;
     }
 }