public bool Execute(char command, IRobotWars robot) { _validate = new ValidateCommand(); if (robot == null || !_validate.IsValid(command)) return false; this.ProcessCommand(command, robot); return true; }
public bool Execute(char command, IRobotWars robot) { var validate = new ValidateCommand(); if (robot == null || !validate.IsValid(command)) { return false; } robot.Move(); return true; }
public bool Execute(char command, IRobotWars robot) { _validate = new ValidateCommand(); if (robot == null || !_validate.IsValid(command)) { return(false); } this.ProcessCommand(command, robot); return(true); }
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(); }
public bool Execute(char command, IRobotWars robot) { var validate = new ValidateCommand(); if (robot == null || !validate.IsValid(command)) { return(false); } robot.Move(); return(true); }
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(); }
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 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; }
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); }
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); }