Beispiel #1
0
        public Hive(World world, MessageDelegate messageSender)
        {
            this.Honey = InitialHoney;
            InitialLocations();
            beeCount = 0;
            Random random = new Random();
            this.world = world;
            this.messageSender = messageSender;
            for (beeCount = 0; beeCount < InitialBees; beeCount++)
            {
                AddBee(random);
            }


        }
Beispiel #2
0
        public Form1()
        {
            InitializeComponent();
            world = new World(new MessageDelegate(SendMessage));

            timer1.Interval = 50;
            timer1.Tick += new EventHandler(RunFrame);
            timer1.Enabled = false;
            UpdateStats(new TimeSpan());
            hiveForm.Show(this);
            fieldForm.Show(this);
            MoveChildForms();
            ResetSimulator();
            
        }
Beispiel #3
0
        public Bee(int id, Point location, World world, Hive hive,MessageDelegate messageSender)
        {
            this.ID = id;
            this.Age = 0;
            this.location = location;
            this.InsideHive = true;
            this.CurrentState = BeeState.Idle;
            this.destinationFlower = null;
            this.NectarCollected = 0;
            this.world = world;
            this.hive = hive;
            this.ExState = CurrentState;
            this.MessageSender += messageSender;

        }
Beispiel #4
0
 private void ResetSimulator()
 {
     framesRun = 0;
     world = new World(new MessageDelegate(this.SendMessage));
     renderer = new Renderer(this.world, this.hiveForm, this.fieldForm);
 }
Beispiel #5
0
        private void openToolStripButton_Click(object sender, EventArgs e)
        {
            World CurrentWorld = this.world;
            int FramesRun = this.framesRun;
            bool enabled = timer1.Enabled;
            if (enabled)
                timer1.Stop();
            openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "Simulator File (*.bees)|*.bees";
            openFileDialog1.Title = "Open simulation";
            openFileDialog1.CheckPathExists = true;
            openFileDialog1.CheckFileExists = true;


            if (openFileDialog1.ShowDialog() == DialogResult.OK)
                try
                {
                    using (FileStream stream = File.OpenRead(openFileDialog1.FileName))
                    {
                        BinaryFormatter formatter = new BinaryFormatter();
                        world = (World)formatter.Deserialize(stream);
                        framesRun = (int)formatter.Deserialize(stream);
                        UpdateStats(new TimeSpan());
                    }
                }


                catch (Exception ex)
                {
                    MessageBox.Show("Unnable to open simulation file,ex.Message\r\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.world = CurrentWorld;
                    this.framesRun = FramesRun;
                }

            world.Hive.messageSender = new MessageDelegate(SendMessage);
            foreach (Bee bee in world.Bees)
            {
                bee.MessageSender += world.Hive.messageSender;
            }

            if (enabled)
                timer1.Start();
            else
            {
                toolStrip1.Items[0].Text = "Resume Simulation";
                statusStrip1.Items[0].Text = "Simulation paused";
            }

            renderer.Reset();
            renderer = new Renderer(world, hiveForm, fieldForm);


        }