示例#1
0
        public Renderer(World world, HiveForm hiveForm, Field fieldForm)
        {
            _world = world;
            _hiveForm = hiveForm;
            _fieldForm = fieldForm;

            InitializeImages();
        }
示例#2
0
        public Bee(int id, Point location, Hive hive, World world)
        {
            _id = id;
            _location = location;
            _hive = hive;
            _world = world;

            IsInsideHive = true;
            State = new IdleState(this);
        }
示例#3
0
 public Hive(World world, Bee.BeeMessage messageSender)
 {
     MessageSender = messageSender;
     Honey = INITIAL_HONEY;
     InitializeLocations();
     _world = world;
     Random random = new Random();
     for (int i = 0; i < INITIAL_BEES; i++)
         AddBee(random);
 }
示例#4
0
 private void ResetSimulator()
 {
     _framesRun = 0;
     _world = new World(SendMessage);
     CreateRenderer();
 }
示例#5
0
        private void openToolStripButton_Click(object sender, EventArgs e)
        {
            World currentWorld = _world;
            int currentFramesRun = _framesRun;

            bool enabled = timer1.Enabled;

            if (enabled)
                timer1.Stop();

            OpenFileDialog openDialog =
                new OpenFileDialog
                    {
                        InitialDirectory = @"C:\BeeSimulator",
                        Filter = "Simulator Files (*.sim)|*.sim",
                        CheckFileExists = true,
                        CheckPathExists = true,
                        Title = "Choose a file with a simulation to load"
                    };

            if (openDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    using (Stream output = File.OpenRead(openDialog.FileName))
                    {
                        _world = (World)bf.Deserialize(output);
                        _framesRun = (int)bf.Deserialize(output);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to read the simulator file\r\n" + ex.Message,
                        "Bee simulator error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    _world = currentWorld;
                    _framesRun = currentFramesRun;
                }
            }

            _world.Hive.MessageSender = SendMessage;
            foreach (Bee bee in _world.Bees)
                bee.MessageSender = SendMessage;
            if (enabled)
                timer1.Start();
            CreateRenderer();
        }