73 lines
2.0 KiB
C#
73 lines
2.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
|
|
|
|
// Array will contain objects which contain all information about all players
|
|
static 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;
|
|
|
|
int numberOfPlayers = GameUI.PlayersNumber; // number of the created solarsystems
|
|
|
|
public GameObject SolarSystemPrefab; // Prefab of SolarSytem-Objekts
|
|
|
|
public static GameObject[] SolarSystems;
|
|
|
|
|
|
//public int numberOfPlayers;//{ get; set; }
|
|
|
|
void Awake()
|
|
{
|
|
DontDestroyOnLoad(this.gameObject);
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
SolarSystems = new GameObject[numberOfPlayers];
|
|
initPlayerManagers(numberOfPlayers);
|
|
clock.gameManager = this;
|
|
for (int i = 0; i < numberOfPlayers; i++)
|
|
{
|
|
// Erzeuge ein neues GameObject aus dem Prefab
|
|
SolarSystems[i] = Instantiate(SolarSystemPrefab);
|
|
}
|
|
SolarSystems[0].GetComponent<SolarSystemManager>().SetIDPlanet(1, 0);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update(){}
|
|
|
|
// Initializes numberOfPlayers player managers and puts them into array
|
|
public void initPlayerManagers(int numberOfPlayers)
|
|
{
|
|
playerManagers = new PlayerManager[numberOfPlayers];
|
|
for (int i = 0; i < numberOfPlayers; i++)
|
|
{
|
|
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?
|
|
}
|
|
}
|