using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    // Array will contain objects which contain all information about all players
    public PlayerManager[] playerManagers { get; private set; }

    // Clock which counts seconds until new day and updates playerManagers at new day
    public Clock clock;

    public ScienceManager sm;

    public int numberOfPlayers { get; set; }

    void Awake()
    {
        DontDestroyOnLoad(this.gameObject);
    }

    // Start is called before the first frame update
    void Start()
    {
        initPlayerManagers(1);
        clock.gameManager = this;
    }

    // Update is called once per frame
    void Update(){}

    // Initializes numberOfPlayers player managers and puts them into array
    public void initPlayerManagers(int numberOfPlayers)
    {
        this.playerManagers = new PlayerManager[numberOfPlayers];
        for (int i = 0; i < numberOfPlayers; i++)
        {
            this.playerManagers[i] = new PlayerManager(sm);
        }
    }

    // Updates game
    public void updateGame()
    {
        if (playerManagers != null)
        {
            // Simulate day for each player
            foreach (var playerManager in playerManagers)
            {
                playerManager.simulateDay();
            }
        }
        // TODO update view, do we need to update view?
    }
}
