Add initial game code
This commit is contained in:
parent
f80a60e208
commit
1383997ebf
55 changed files with 1355 additions and 0 deletions
39
scripts/GameObjects/Universe.cs
Normal file
39
scripts/GameObjects/Universe.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue