Example #1
0
        protected override void Update(GameTime gameTime)
        {
            var currKS = Keyboard.GetState();

            if (currKS.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if ((autoRun && sw.ElapsedMilliseconds > 100) || (currKS.IsKeyDown(Keys.Space) && (prevKS.IsKeyUp(Keys.Space) || sw.ElapsedMilliseconds > 500)))
            {
                int dead = 0, immune = 0, infected = 0, susceptible = 0;
                foreach (var a in simState.Agents)
                {
                    if (a.Value.Infection.IsDead)
                    {
                        dead++;
                    }
                    else if (a.Value.Infection.IsImmune)
                    {
                        immune++;
                    }
                    else if (a.Value.Infection.IsInfected)
                    {
                        infected++;
                    }
                    else if (a.Value.Infection.IsSusceptible)
                    {
                        susceptible++;
                    }
                }
                stats.Add(
                    new ApplicationStats()
                {
                    Dead        = dead,
                    Immune      = immune,
                    Infected    = infected,
                    Susceptible = susceptible
                });
                simState = Simulation.updateState(simState);
                sw.Restart();
            }

            if (currKS.IsKeyDown(Keys.Enter) && prevKS.IsKeyUp(Keys.Enter))
            {
                autoRun = !autoRun;
            }

            if ((alwaysShowChart && chart_sw.ElapsedMilliseconds > 200) || currKS.IsKeyDown(Keys.Tab) && (prevKS.IsKeyUp(Keys.Tab) || chart_sw.ElapsedMilliseconds > 200))
            {
                try { GenerateInfectionChart(); } catch (Exception) { }
                chart_sw.Restart();
            }

            prevKS = currKS;
            base.Update(gameTime);
        }
Example #2
0
        protected override void Initialize()
        {
            var cityPositions =
                from i in Enumerable.Range(0, 3)
                from j in Enumerable.Range(0, 2)
                select new Vector2(200 + i * 440, 150 + j * 400);

            simState = Simulation.setupState(
                cityPositions, 1000,
                75, 24, 7,
                0.01, 4);

            base.Initialize();
        }