39 lines
985 B
C#
39 lines
985 B
C#
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
|
|
public partial class Universe
|
|
{
|
|
public decimal CurrentTick { get; private set; }
|
|
public List<GameObject> GameObjects { get; private set; }
|
|
|
|
public Ship PlayerShip { get; private set; }
|
|
|
|
public Universe()
|
|
{
|
|
this.GameObjects = new List<GameObject>();
|
|
}
|
|
|
|
public decimal SimulateTick()
|
|
{
|
|
this.CurrentTick++;
|
|
|
|
List<Task> galaxySimulationTasks = new List<Task>();
|
|
|
|
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;
|
|
}
|
|
}
|