예제 #1
0
        public bool Execute(char command, IRobotWars robot)
        {
            _validate = new ValidateCommand();
            if (robot == null || !_validate.IsValid(command))
                return false;
            this.ProcessCommand(command, robot);

            return true;
        }
예제 #2
0
        public bool Execute(char command, IRobotWars robot)
        {
            var validate = new ValidateCommand();
            if (robot == null || !validate.IsValid(command))
            { return false; }

            robot.Move();
            return true;
        }
예제 #3
0
        public bool Execute(char command, IRobotWars robot)
        {
            _validate = new ValidateCommand();
            if (robot == null || !_validate.IsValid(command))
            {
                return(false);
            }
            this.ProcessCommand(command, robot);

            return(true);
        }
예제 #4
0
        public virtual void Setup()
        {
            this.arenaStub = MockRepository.GenerateStub <IArena>();
            this.arenaStub.Stub(c => c.Width).Return(coordinate);
            this.arenaStub.Stub(c => c.Height).Return(coordinate);

            this.robotStub = MockRepository.GenerateStub <IRobotWars>();
            this.robotStub.Stub(c => c.Direction).Return(Direction.South);

            this.contextStub = MockRepository.GenerateStub <IContext>();
            this.robot       = new RobotWars();
        }
예제 #5
0
        public bool Execute(char command, IRobotWars robot)
        {
            var validate = new ValidateCommand();

            if (robot == null || !validate.IsValid(command))
            {
                return(false);
            }

            robot.Move();
            return(true);
        }
예제 #6
0
        public virtual void Setup()
        {
            this.arenaStub = MockRepository.GenerateStub<IArena>();
            this.arenaStub.Stub(c => c.Width).Return(coordinate);
            this.arenaStub.Stub(c => c.Height).Return(coordinate);

            this.robotStub = MockRepository.GenerateStub<IRobotWars>();
            this.robotStub.Stub(c => c.Direction).Return(Direction.South);

            this.contextStub = MockRepository.GenerateStub<IContext>();
            this.robot = new RobotWars();
        }
예제 #7
0
        private void ProcessCommand(char command, IRobotWars robot)
        {
            string commandAsString = command.ToString(CultureInfo.InvariantCulture);
            if (_validate.IsLeftCommand(commandAsString))
            {
                robot.Spin(false);
            }

            if (_validate.IsRightCommand(commandAsString))
            {
                robot.Spin(true);
            }
        }
예제 #8
0
        private void ProcessCommand(char command, IRobotWars robot)
        {
            string commandAsString = command.ToString(CultureInfo.InvariantCulture);

            if (_validate.IsLeftCommand(commandAsString))
            {
                robot.Spin(false);
            }

            if (_validate.IsRightCommand(commandAsString))
            {
                robot.Spin(true);
            }
        }
 private bool ExecuteInternal(char character, IRobotWars robot, IValidateCommand validation)
 {
     if(validation.IsMoveCommand(character.ToString(CultureInfo.InvariantCulture)))
     {
         ICommand command = new MoveCommand();
         command.Execute(character, robot);
     }
     else
     {
         ICommand command = new SpinCommand();
         command.Execute(character, robot);
     }
     return true;
 }
예제 #10
0
 private bool ExecuteInternal(char character, IRobotWars robot, IValidateCommand validation)
 {
     if (validation.IsMoveCommand(character.ToString(CultureInfo.InvariantCulture)))
     {
         ICommand command = new MoveCommand();
         command.Execute(character, robot);
     }
     else
     {
         ICommand command = new SpinCommand();
         command.Execute(character, robot);
     }
     return(true);
 }
예제 #11
0
        public bool Process(string commands)
        {
            var  result   = string.Empty;
            bool moveDone = false;

            try
            {
                if (!this.Validate(commands))
                {
                    return(false);
                }
                IRobotWars robot = this._context.Robot;
                foreach (var command in commands.ToLowerInvariant())
                {
                    if (!_validation.IsValid(command))
                    {
                        return(false);
                    }
                    moveDone = ExecuteInternal(command, robot, _validation);
                }
                if (moveDone)
                {
                    result = "Robot movement completed \n";
                }
                result += string.Format("Robot Position: {0} {1} {2}", robot.XAxis, robot.YAxis, robot.Direction);
            }
            catch (Exception)
            {
                result = "Something went wrong while moving robot";
                throw;
            }
            finally
            {
                Console.WriteLine(result);
            }
            return(true);
        }