/// <summary> /// Update UI. /// </summary> /// <param name="roundCounter">Current round.</param> /// <param name="currentTurnReport">Current turn report.</param> /// <param name="showGrid">Show the grid?</param> /// <param name="grid">The <see cref="Grid"/> to show.</param> public void Update(int roundCounter, TurnReport currentTurnReport, bool showGrid, Grid grid) { ConsoleKey userInput; if (showGrid) { Console.Clear(); } Console.BackgroundColor = defaultBackgroundColor; PrintTurnReport(roundCounter, currentTurnReport); if (showGrid) { ShowGrid(roundCounter, grid); Console.WriteLine("Press [Enter] to continue."); while (true) { userInput = GetUserInputKey(); if (userInput == ConsoleKey.Enter) { break; } } } }
/// <summary> /// Print the given round report to the console. /// </summary> /// <param name="roundCounter">The current round.</param> /// <param name="turnReport">The <see cref="TurnReport"/> to show. /// </param> private void PrintTurnReport(int roundCounter, TurnReport turnReport) { string holder; holder = $"Turn {roundCounter}: "; holder += $"{turnReport.Healthy} healthy, "; holder += $"{turnReport.Infected} infected "; holder += $"and {turnReport.Dead} dead."; Console.WriteLine(holder); }
/// <summary> /// The main simulation run loop. /// </summary> public void Run() { TurnReport turnReport; List <TurnReport> turnReports = null; if (!simOptions.ShowSimulation) { Console.WriteLine($"Simulation starts with {agents.Length} " + "healthy agents."); } for (int roundCounter = 1; roundCounter <= simOptions.MaxTurns; roundCounter++) { // For every Agents... for (int k = 0; k < agents.Length; k++) { if (!agents[k].IsDead) { // ...randomly move them. simGrid.RandomlyMoveAgent(rng, agents[k]); // If infected... if (agents[k].IsInfected) { // ...spread the virus. agents[k].TileRef.SpreadVirus(roundCounter); // Performs infection tick agents[k].InfectionTick(roundCounter); } } } // First infection if (simOptions.FirstInfectionTurn == roundCounter) { int randomAgent = rng.Next(0, agents.Length); agents[randomAgent].Infect(roundCounter); } turnReport = new TurnReport(HealthyAgentCount, InfectedAgentCount, DeadAgentCount); Program.UIManager .Update(roundCounter, turnReport, simOptions.ShowSimulation, simGrid); // If user asked to generate stats file if (simOptions.OutputSimulationToFile) { if (turnReports == null) { turnReports = new List <TurnReport>(); } turnReports.Add(turnReport); } if (!IsAnyAgentAlive) { break; } } if (simOptions.OutputSimulationToFile) { SaveReport(turnReports); } }