Example #1
0
        public void WhenCommandFactoryIsInvokedReturnsTheCorrectCommandImplementation()
        {
            var surface = new Surface(new Coordinates(5, 5));
            var robot   = new Robot(new Position(1, 1, Orientation.E));
            var command = RobotCommandsFactory.GetComand(Instruction.F, robot, surface);

            Assert.IsType <ForwardMovement>(command);

            command = RobotCommandsFactory.GetComand(Instruction.L, robot, surface);
            Assert.IsType <LeftRotationCommand>(command);

            command = RobotCommandsFactory.GetComand(Instruction.R, robot, surface);
            Assert.IsType <RightRotationCommand>(command);
        }
Example #2
0
        private Robot ExecuteInstructions(Robot robot, List <Instruction> instructions)
        {
            foreach (var instruction in instructions)
            {
                robot = RobotCommandsFactory.GetComand(instruction, robot, Surface)
                        .Execute();

                if (robot.Status == RobotStatus.Lost)
                {
                    Surface.AddScent(robot.Position.Coordinates);
                    return(robot);
                }
            }

            return(robot);
        }