Exemple #1
0
 private void BootControllers()
 {
     FloorPlanController.Boot();
     HeatTransferController.Boot(FloorPlanController.Walls, Multiplier);
     HumanController.Boot(FloorPlanController.Walls, FloorPlanController.Doors, (int)numericUpDownHumans.Value);
     HumanController.Humans.ForEach(i => i.SetEmergencyRoute(FloorPlanController.EmergencyRoute));
     SimulationLength   = (int)numericUpDownSimulationLength.Value;
     ParallelHorizontal = (int)numericUpDownParallelHorizontal.Value;
     ParallelVertical   = (int)numericUpDownParallelVertical.Value;
 }
Exemple #2
0
        public MainForm()
        {
            InitializeComponent();

            this.DoubleBuffered = true;
            this.SetStyle(ControlStyles.UserPaint |
                          ControlStyles.AllPaintingInWmPaint |
                          ControlStyles.ResizeRedraw |
                          ControlStyles.ContainerControl |
                          ControlStyles.OptimizedDoubleBuffer |
                          ControlStyles.SupportsTransparentBackColor
                          , true);

            FloorPlanController.Boot();
            HeatTransferController.ArrayHeight = 90;
            HeatTransferController.ArrayWidth  = 150;
            HeatTransferController.BlockHeight = 5;
            HeatTransferController.BlockWidth  = 5;

            HeatTransferController.Boot(FloorPlanController.Walls);
            HumanController.Boot(FloorPlanController.Walls, FloorPlanController.Doors, 5);
            HumanController.Humans.ForEach(i => i.SetEmergencyRoute(FloorPlanController.EmergencyRoute));

            Task.Run(() => {
                var screenWidth  = pictureBox.Width;
                var screenHeight = pictureBox.Height;

                Random rnd        = new Random();
                int randomCounter = 0;

                Stopwatch sw = new Stopwatch();
                sw.Start();

                while (true)
                {
                    if (sw.ElapsedMilliseconds > 20)
                    {
                        Bitmap buffer = new Bitmap(screenWidth, screenHeight);
                        System.Drawing.Graphics gfx = Graphics.FromImage(buffer);//set the graphics to draw on the image

                        HumanController.Calculate(
                            FloorPlanController.Walls,
                            FloorPlanController.Doors,
                            FloorPlanController.Rooms
                            );

                        HumanController.Humans.ForEach(h =>
                                                       h.Temperature = HeatTransferController.GetNearestBlock(h.Position).Temperature
                                                       );

                        HeatTransferController.Calculate();

                        HumanController.Draw(gfx);
                        FloorPlanController.Draw(gfx);
                        HeatTransferController.Draw(gfx);

                        ChangeScreen(buffer);//set the PictureBox's image to be the buffer

                        if (randomCounter == 0)
                        {
                            randomCounter = rnd.Next(0, 30);
                            HumanController.RandomEvent();
                        }
                        else
                        {
                            randomCounter--;
                        }

                        sw.Restart();
                    }
                }
            });
        }