public Form1() { InitializeComponent(); world = new World(new BeeMessage(SendMessage)); timer1.Interval = 50; timer1.Tick += new EventHandler(RunFrame); timer1.Enabled = false; UpdateStats(new TimeSpan()); }
public Hive(World world, BeeMessage MessageSender) { this.MessageSender = MessageSender; this.world = world; Honey = InitialHoney; InitializeLocations(); Random random = new Random(); for (int i = 0; i < InitialBees; i++) AddBee(random); }
public Bee(int ID, Point initialLocation, World world, Hive hive) { this.ID = ID; Age = 0; location = initialLocation; InsideHive = true; CurrentState = BeeState.Idle; destinationFlower = null; NectarCollected = 0; this.world = world; this.hive = hive; }
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(); openDialog.Filter = "Simulator File (*.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); framesRun = (int)bf.Deserialize(input); } } 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 = new BeeMessage(SendMessage); foreach (Bee bee in world.Bees) bee.MessageSender = new BeeMessage(SendMessage); if (enabled) timer1.Start(); }
private void reset_Click(object sender, EventArgs e) { framesRun = 0; world = new World(new BeeMessage(SendMessage)); if (!timer1.Enabled) toolStrip1.Items[0].Text = "Start simulation"; }
private void ResetSimulator() { framesRun = 0; world = new World(new BeeMessage(SendMessage)); renderer = new Renderer(world, hiveForm, fieldForm); }
public Renderer(World world, HiveForm hiveForm, FieldForm fieldForm) { this.world = world; this.hiveForm = hiveForm; this.fieldForm = fieldForm; }