示例#1
0
    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");
        }
    }
示例#2
0
 public void Init(RobotWorld robotWorld, float simulationTimestep)
 {
     _robotWorld         = robotWorld;
     _simulationTimestep = simulationTimestep;
     _robotWorld.RobotPlaced.AddListener(HandleRobotPlaced);
     _robotWorld.RobotMoved.AddListener(HandleRobotMoved);
     _robotWorld.RobotRotated.AddListener(HandleRobotRotated);
 }
示例#3
0
    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();
 }
示例#5
0
 public void Execute(RobotWorld world, string[] args)
 {
     world.Report();
 }
示例#6
0
 public void Execute(RobotWorld world, string[] args)
 {
     world.Move();
 }