Galaxy Anpassen

This commit is contained in:
mkadou
2023-07-02 14:25:11 +02:00
parent 05142dbb22
commit b38ff3197a
107 changed files with 833 additions and 187 deletions

View File

@@ -1,18 +1,28 @@
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
public PlayerManager[] playerManagers { get; private set; }
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;
public int numberOfPlayers { get; set; }
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()
{
@@ -22,8 +32,15 @@ public class GameManager : MonoBehaviour
// Start is called before the first frame update
void Start()
{
initPlayerManagers(1);
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
@@ -32,10 +49,10 @@ public class GameManager : MonoBehaviour
// Initializes numberOfPlayers player managers and puts them into array
public void initPlayerManagers(int numberOfPlayers)
{
this.playerManagers = new PlayerManager[numberOfPlayers];
playerManagers = new PlayerManager[numberOfPlayers];
for (int i = 0; i < numberOfPlayers; i++)
{
this.playerManagers[i] = new PlayerManager(sm);
playerManagers[i] = new PlayerManager(sm);
}
}

View File

@@ -1,5 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class PlayerManager
{
@@ -10,6 +12,7 @@ public class PlayerManager
//private List<GameObject> fleets = new List<GameObject>();
private ScienceManager _scienceManager;
public static int PlayerID = 1;
public int ScienceAcumulated; // this int has to be moved to player manager later
@@ -54,17 +57,43 @@ public class PlayerManager
}
}
private PlayerValues _playerAttributes;
public PlayerValues _playerAttributes;
public PlayerManager(ScienceManager sm)
{
this._scienceManager = sm;
this._playerAttributes = new PlayerValues();
this._playerAttributes.id = PlayerID;
PlayerID++;
}
// Called by clock over game manager, once per day
public void simulateDay()
{
if (GameManager.SolarSystems != null)
{
for (int i = 0; i < GameUI.PlayersNumber; i++)
{
if (GameManager.SolarSystems[i].GetComponent<SolarSystemManager>() != null)
{
int playerID = this._playerAttributes.id;
_scienceManager.UpdateScience(this._playerAttributes.science);
this._playerAttributes.science = _scienceManager.PublicScienceAcumulated;
this._playerAttributes.industrialCapacity += GameManager.SolarSystems[i].GetComponent<SolarSystemManager>().GetIndustrialCapacity(playerID) * _scienceManager.techs[0].Level;
this._playerAttributes.money += GameManager.SolarSystems[i].GetComponent<SolarSystemManager>().GetMoney(playerID) * _scienceManager.techs[1].Level;
this._playerAttributes.science += GameManager.SolarSystems[i].GetComponent<SolarSystemManager>().GetScience(playerID) * _scienceManager.techs[2].Level;
GameManager.SolarSystems[i].GetComponent<SolarSystemManager>().UpdateFood(playerID, _scienceManager.techs[3].Level);
this._playerAttributes.food += GameManager.SolarSystems[i].GetComponent<SolarSystemManager>().GetFood(playerID);
this._playerAttributes.population += GameManager.SolarSystems[i].GetComponent<SolarSystemManager>().GetPopulation(playerID);
this._playerAttributes.actualFood += GameManager.SolarSystems[i].GetComponent<SolarSystemManager>().GetActualFood(playerID);
}
}
}
//if (starSystems != null)
//{
// Add resources for each part of each starSystem which belongs to this player
@@ -78,11 +107,10 @@ public class PlayerManager
// this._playerAttributes.power += ((StarSystem)starSystem).getPower(playerID);
// this._playerAttributes.food += ((StarSystem)starSystem).getFood(playerID);
// this._playerAttributes.industrialCapacity += ((StarSystem)starSystem).getIC(playerID);
this._playerAttributes.science += 5;
_scienceManager.UpdateScience(this._playerAttributes.science);
this._playerAttributes.science = _scienceManager.PublicScienceAcumulated;
//}
//}
//this._playerAttributes.science += 5 * _scienceManager.techs[2].Level;
//_scienceManager.UpdateScience(this._playerAttributes.science);
//this._playerAttributes.science = _scienceManager.PublicScienceAcumulated;
}
// Deletes overhanded referrence from fleets list

View File

@@ -9,6 +9,8 @@ public class PlayerValues
public int power { get; set; }
public int food { get; set; }
public int industrialCapacity { get; set; }
public int population { get; set; }
public int actualFood { get; set; }
// Default constructor
public PlayerValues()
@@ -20,10 +22,13 @@ public class PlayerValues
this.power = 0;
this.food = 0;
this.industrialCapacity = 0;
this.population = 0;
this.actualFood = 0;
}
// Constructor to init values
public PlayerValues(int id, int newMoney, int newScience, int newPower, int newFood, int newIC)
public PlayerValues(int id, int newMoney, int newScience, int newPower, int newFood, int newIC, int newPopulation, int newActualFood)
{
this.id = id;
@@ -32,5 +37,7 @@ public class PlayerValues
this.power = newPower;
this.food = newFood;
this.industrialCapacity = newIC;
this.population = newPopulation;
this.actualFood = newActualFood;
}
}