/// <summary> /// Generates new food at an interval determined by the number of snakes. /// The maximum capacity is specified as food density in the settings file. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="ElapsedEventArgs"/> instance containing the event data.</param> private void SpawnNewFood(object sender, ElapsedEventArgs e) { lock (world) { if (world.Snakes.Count > 0 && (foodGenerationTimer.Interval * world.Snakes.Count) != 1000) { foodGenerationTimer.Stop(); foodGenerationTimer.Interval = 1000 / world.Snakes.Count; foodGenerationTimer.Start(); } if (world.Food.Count < (foodDensity * world.Snakes.Count)) { world.AddRandomFood(ref playerCount); } } }