예제 #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);
    }
예제 #4
0
 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();
 }