using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; namespace Rokojori { public class SimulationManager : MonoBehaviour { public static SimulationManager instance => Unique.Get(); public List intro = new List(); public List preTurn = new List(); public List playerTurn = new List(); public List postTurn = new List(); public List outro = new List(); // No Player type exists yet - intro phases are expected to set this // (e.g. from a GameStateNumberVariable) before the turn loop starts. public int playerCount = 1; public bool _gameFinished = false; public async Task Run() { _gameFinished = false; await RunPhases( intro ); while ( ! _gameFinished ) { await RunPhases( preTurn ); for ( int i = 0; i < playerCount && ! _gameFinished; i++ ) { await RunPhases( playerTurn ); } if ( ! _gameFinished ) { await RunPhases( postTurn ); } } await RunPhases( outro ); } public async Task RunPhases( List phases ) { for ( int i = 0; i < phases.Count; i++ ) { var phase = phases[ i ]; await phase.Execute( GameStateManager.instance, SimulationRenderer.instance ); if ( phase.gameFinished ) { _gameFinished = true; return; } } } } }