Exemplo n.º 1
0
        //------------------------------------------------------------------------------------------------------------------------
        //Function: RobotSimulator (constructor)
        //Sets up the simulation, setting up the framerate, web service communication (between robot and simulation), and simulation
        //UI.
        //------------------------------------------------------------------------------------------------------------------------
        public RobotSimulator()
        {
            InitializeComponent();
            // Set the framerate to 30 FPS.
            Application.Current.Host.Settings.MaxFrameRate = 30;

            // Connect to and set up the web service.
            robotService = new ServiceClient();
            robotService.getMotionCompleted += new EventHandler<getMotionCompletedEventArgs>(robotService_getMotionCompleted);
            robotService.getMotionAsync();

            /*broker = new brokerService.Service1SoapClient();
            broker.GetAddressCompleted += new EventHandler<GetAddressCompletedEventArgs>(broker_getAddressCompleted);
            broker.GetAddressAsync(0);*/

            // Create a box around the entire boundary of the simulator area
            Rectangle worldBoundary = new Rectangle();
            worldBoundary.Width = simWorld.getWorldSize() - 2;
            worldBoundary.Height = simWorld.getWorldSize() - 2;
            SolidColorBrush lightGray = new SolidColorBrush(Colors.LightGray);
            worldBoundary.Fill = lightGray;
            worldBoundary.Margin = new Thickness(0, 0, 0, 0);
            worldBoundary.HorizontalAlignment = HorizontalAlignment.Left;
            worldBoundary.VerticalAlignment = VerticalAlignment.Top;
            objectInWorld worldBoundaryObject = new objectInWorld(worldBoundary, 0.0);
            worldObjects.Add(worldBoundaryObject);

            // Calculate all of the physics-related variables for the entire simulated world.
            simWorld.populateWorld(LayoutRoot, worldObjects);  // Now just for the world boundary

            // Start a thread that checks for updates from the web service and sends updates (from the sensors) to the web service.
            runner = new Thread(robotUpdater);
            runner.Start();

            // This function initializes the contents of the maze and other pieces in the simulator.
            simWorld.defaultTestSetup(LayoutRoot, theRobot, ref robotRotation);

            // Populate the list of the combobox.
            populateComboBox(defaultActionComboBox, defaultOptions);
            defaultActionComboBox.SelectedIndex = 0;    // By default, the default action is to move forward.
        }