public void ExecuteCommand(string command, Grid grid) { switch (command) { case "L": Left(); break; case "R": Right(); break; case "M": Move(grid); break; default: throw new ArgumentOutOfRangeException("Unknown command: " + command); } }
// The robot will ignore a Move that would take it off the edge of the grid. private void Move(Grid grid) { int newX = X, newY = Y; switch (Facing) { case Direction.N: newY += 1; break; case Direction.S: newY -= 1; break; case Direction.E: newX += 1; break; case Direction.W: newX -= 1; break; } if (grid.IsInBounds(newX, newY)) { X = newX; Y = newY; } }