/// <summary> /// Runs the currently loaded arena /// </summary> private void runGame() { if (robots.Count == 0) { Console.WriteLine("No Robots! Nothing to run"); } else { IEnumerable <SimulationEvent> arenaIt = arena.run(); foreach (SimulationEvent ev in arenaIt) { if (ev.GetType() == typeof(ChrononEndEvent)) { if (ChrononsPerUpdate > 0 && arena.chronon % ChrononsPerUpdate == 0) { DisplayState(); } } if (ev.GetType() == typeof(RobotFaultEvent)) { if (!HandleError(ev as RobotFaultEvent)) { break; } } } DisplayState(); Console.WriteLine("".PadLeft(40, '#')); } }
// Handle for timer ticks, step a chronon private void frame(object sender, EventArgs e) { if (arenaIt == null) { arenaIt = arena.run(); } foreach (SimulationEvent ev in arenaIt) { if (ev.GetType() == typeof(ChrononEndEvent)) { arenaview.Invalidate(); foreach (RobotControl c in robotlist) { c.update_info(); } chrononlabel.Text = "Chronon " + arena.chronon.ToString(); // Wait a bit return; } } gametimer.Stop(); playpausebutton.Text = "Finished"; playpausebutton.Enabled = false; }
// Timer callback private bool frame() { if (arenaIt == null) { arenaIt = arena.run(); } foreach (SimulationEvent ev in arenaIt) { if (ev.GetType() == typeof(ChrononEndEvent)) { arenaview.QueueDraw(); foreach (RobotWidget w in robotlist) { if (w != null) { w.update_info(); } } chrononlabel.Text = "Chronon " + arena.chronon.ToString() + " (20 c/s)"; // Wait a bit return(true); } if (ev.GetType() == typeof(RobotFaultEvent)) { int userAction = new ErrorDialog(ev as RobotFaultEvent).Run(); if (userAction == (int)Gtk.ResponseType.Cancel) { stop_game(); return(false); } } } // If we fall through the loop, iteration has ended stop_game(); playbutton.Sensitive = false; return(false); }