} // end of CurrentTime #endregion //-------------------------------------------------------------------------------------------------- // Methods //-------------------------------------------------------------------------------------------------- #region RunSimulation public void RunSimulation(double firstWait = 0) { _simulationRunning = true; if (VisualizationEnabled) { SimulationTimer.Interval = TimeSpan.FromMilliseconds(firstWait); SimulationTimer.Start(); } else { BackgroundWorkerNonVisualization.RunWorkerAsync(); } // end if } // end of RunSimulation
} // end of RunSimulation #endregion #region StopSimulation public void StopSimulation(bool pauseSim) { if (VisualizationEnabled) { SimulationTimer.Stop(); } else { BackgroundWorkerNonVisualization.CancelAsync(); } // end if _simulationRunning = false; if (!pauseSim) { ActionsAfterFinishingSimulationRun(); } // end if } // end of StopSimulation
public void Reload() { SimulationTimer.Stop(); DayTimer.Stop(); Day = 0; RefreshLabels(); SimulationTimer.Interval = Settings.SimulationTime; Console.WriteLine($"Percentuale contagio: {Settings.SpreadProbability}%"); People = new Person[Settings.PeopleNum]; Random rand = new Random(); for (int i = 0; i < People.Length; i++) { int diameter = 7; int x = rand.Next(SimulationPanel.Width - diameter); int y = rand.Next(SimulationPanel.Height - diameter); Point point = new Point(x, y); int speedX; do { speedX = rand.Next(MinSpeed, MaxSpeed + 1); } while (speedX == 0); int speedY; do { speedY = rand.Next(MinSpeed, MaxSpeed + 1); } while (speedY == 0); People[i] = new Person(point, diameter, speedX, speedY, rand); } int j = rand.Next(Settings.PeopleNum); People[j].Infect(); RefreshLabels(); ChartThread = new ChartThread(this); SimulationTimer.Enabled = true; DayTimer.Enabled = true; SimulationTimer.Start(); DayTimer.Start(); }