public virtual void Execute(IRobot robot, IStringResponse respond = null) { Debug.Assert(robot != null); if (!robot.HasAPosition) { respond?.Write($"Robot position has not been set!"); return; } // validate the robot position & facing if (robot.Vector.Position.X != _vec.Position.X) { respond?.Write($"Validation of robot position ({_vec.Position.X}, {_vec.Position.Y}) facing {_vec.Dir} failed. Robot x position is {robot.Vector.Position.X}!"); } if (robot.Vector.Position.Y != _vec.Position.Y) { respond?.Write($"Validation of robot position ({_vec.Position.X}, {_vec.Position.Y}) facing {_vec.Dir} failed. Robot y position is {robot.Vector.Position.Y}!"); } if (robot.Vector.Dir != _vec.Dir) { respond?.Write($"Validation of robot position ({_vec.Position.X}, {_vec.Position.Y}) facing {_vec.Dir} failed. Robot is facing {robot.Vector.Dir}!"); } }
public virtual void Execute(IRobot robot, IStringResponse respond = null) { Debug.Assert(robot != null); if (!robot.HasAPosition) { return; } respond?.Write($"{robot.Vector.Position.X},{robot.Vector.Position.Y},{robot.Vector.Dir.ToString().ToUpper()}"); }
public virtual void Execute(IRobot robot, IStringResponse respond = null) { Debug.Assert(robot != null); if (!robot.HasAPosition) { return; } robot.TurnRight(); }
public void Execute(List <IRobotCommand> commands, IStringResponse response = null) { // so why use classes to represent commands and execute them here? // // 1. It means that the simulator is now open to the existance of other commands // that are NOT available via the command string. // 2. Also the encapsulation of the commands and their execution means that we can now implement specialisation through aggregation // 3. There is now the potential for the simple optimisation of the commands, ie. the deletion of duplicate PLACE commands one after the other Debug.Assert(commands != null); foreach (var command in commands) { Execute(command, response); } }
public void Execute(IRobotCommand command, IStringResponse response = null) { command?.Execute(TheRobot, response); }
public virtual void Execute(IRobot robot, IStringResponse respond = null) { robot?.Place(this._vec); }