66 lines
1.4 KiB
C#
66 lines
1.4 KiB
C#
|
|
using System.Collections.Generic;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace Rokojori
|
||
|
|
{
|
||
|
|
|
||
|
|
public class SimulationManager : MonoBehaviour
|
||
|
|
{
|
||
|
|
public static SimulationManager instance => Unique<SimulationManager>.Get();
|
||
|
|
|
||
|
|
public List<GamePhase> intro = new List<GamePhase>();
|
||
|
|
public List<GamePhase> preTurn = new List<GamePhase>();
|
||
|
|
public List<GamePhase> playerTurn = new List<GamePhase>();
|
||
|
|
public List<GamePhase> postTurn = new List<GamePhase>();
|
||
|
|
public List<GamePhase> outro = new List<GamePhase>();
|
||
|
|
|
||
|
|
// 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<GamePhase> 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;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|