public void Run(string commandAndArguments, RobotWorld world) { //extract commandName and Arguments string commandName; string[] arguments; ParseCommand(commandAndArguments, out commandName, out arguments); //check command is valid if (!_commandsDictionary.ContainsKey(commandName)) { Debug.LogError("command not recognised:" + commandName); return; } //execute ICommand commandInstance = _commandsDictionary[commandName]; if (world.IsRobotPlaced() || commandName == CommandNames.PLACE.ToString()) { commandInstance.Execute(world, arguments); } else { Debug.LogError("can't run commands until robot is placed"); } }
public void Init(RobotWorld robotWorld, float simulationTimestep) { _robotWorld = robotWorld; _simulationTimestep = simulationTimestep; _robotWorld.RobotPlaced.AddListener(HandleRobotPlaced); _robotWorld.RobotMoved.AddListener(HandleRobotMoved); _robotWorld.RobotRotated.AddListener(HandleRobotRotated); }
public void Execute(RobotWorld world, string[] args) { int x = int.Parse(args[0]); int y = int.Parse(args[1]); RobotWorld.Direction direction = (RobotWorld.Direction)Enum.Parse(typeof(RobotWorld.Direction), args[2]); world.Place(x, y, direction); }
public SimulationRunner() { _robotWorld = new RobotWorld(5, 5); _invoker = new CommandInvoker(); }
public void Execute(RobotWorld world, string[] args) { world.Report(); }
public void Execute(RobotWorld world, string[] args) { world.Move(); }