using System.Collections.Generic; using System.Threading.Tasks; public partial class Universe { public decimal CurrentTick { get; private set; } public List GameObjects { get; private set; } public Ship PlayerShip { get; private set; } public Universe() { this.GameObjects = new List(); } public decimal SimulateTick() { this.CurrentTick++; List galaxySimulationTasks = new List(); foreach (GameObject gameObject in this.GameObjects) { if (gameObject.GetType().Name == "Galaxy") { Task galaxySimulation = new Task(() => gameObject.Simulate()); galaxySimulation.Start(); galaxySimulationTasks.Add(galaxySimulation); continue; } gameObject.Simulate(); } Task.WaitAll(galaxySimulationTasks.ToArray()); return this.CurrentTick; } }