Exemple #1
0
 private void ResetSimulator()
 {
     world.framesRun = 0;                                      //+
     framesRun       = world.framesRun;
     world           = new World(new BeeMessage(SendMessage)); //+
     renderer        = new RendererForWinForm(world, hiveForm, fieldForm);
 }
Exemple #2
0
        private void Open_Click(object sender, EventArgs e)
        {
            World currentWorld     = world;
            int   currentFramesRun = framesRun;
            bool  enabled          = timer1.Enabled;

            if (enabled)
            {
                timer1.Stop();
            }
            OpenFileDialog openDialog = new OpenFileDialog();

            openDialog.Filter          = "SimulatorFile(*.bees)|*.bees";
            openDialog.CheckPathExists = true;
            openDialog.CheckFileExists = true;
            openDialog.Title           = "Choose a file with a simulation to load";
            if (openDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    using (Stream input = File.OpenRead(openDialog.FileName))
                    {
                        world           = (World)bf.Deserialize(input);
                        world.framesRun = (int)bf.Deserialize(input);//
                        framesRun       = world.framesRun;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to read the simulator file\r\n" + ex.Message,
                                    "Bee Simulator Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    world           = currentWorld;
                    world.framesRun = currentFramesRun;//
                    framesRun       = world.framesRun;
                }
            }
            world.Hive.MessageSender = new BeeMessage(SendMessage);
            foreach (Bee bee in world.Bees)
            {
                bee.MessageSender = new BeeMessage(SendMessage);
            }
            if (enabled)
            {
                timer1.Start();
            }
            renderer = new RendererForWinForm(world, hiveForm, fieldForm);//689
        }