Sicherheitskopie_001

This commit is contained in:
Aaron Moser
2023-07-21 23:31:11 +02:00
parent ec4cda81e9
commit 2e96435f94
1093 changed files with 161513 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 92a02ff3338a15c44b7bf2ab762fc4b5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,183 @@
using System.Collections;
using System.Collections.Generic;
namespace NBuilding
{
public abstract class ABuilding : IBuilding
{
//----------------------------------------------------------------------------
// private object variables
private int _runningCost = 0;
private int _scienceCapacity = 0;
private int _foodCapacity = 0;
private int _industrialCapacity = 0;
private int _moneyCapacity = 0;
private int _militaryPower = 0;
private bool _isRunning = true;
private ABuilding.BuildingID _iD = 0;
//----------------------------------------------------------------------------
//
public enum BuildingID
{
Farm,
Smeltery,
Armory,
Spaceport,
Market,
University
}
//----------------------------------------------------------------------------
// Getters
public int GetRunningCost()
{
if (_isRunning)
{
return _runningCost;
}
else
{
return 0;
}
}
public int GetScienceCapacity()
{
if (_isRunning)
{
return _scienceCapacity;
}
else
{
return 0;
}
}
public int GetFoodCapacity()
{
if (_isRunning)
{
return _foodCapacity;
}
else
{
return 0;
}
}
public int GetIndustrialCapacity()
{
if (_isRunning)
{
return _industrialCapacity;
}
else
{
return 0;
}
}
public int GetMoneyCapacity()
{
if (_isRunning)
{
return _moneyCapacity;
}
else
{
return 0;
}
}
public int GetMilitaryPower()
{
if (_isRunning)
{
return _militaryPower;
}
else
{
return 0;
}
}
public bool IsRunning()
{
return _isRunning;
}
public ABuilding.BuildingID GetId()
{
return _iD;
}
//----------------------------------------------------------------------------
// Setters
public void SetRunningCost(int newRunningCost)
{
if (newRunningCost > 0)
{
_runningCost = newRunningCost;
}
}
public void SetScienceCapacity(int newScienceCapacity)
{
if (newScienceCapacity >= 0)
{
_scienceCapacity = newScienceCapacity;
}
}
public void SetFoodCapacity(int newFoodCapacity)
{
if (newFoodCapacity >= 0)
{
_foodCapacity = newFoodCapacity;
}
}
public void SetIndustrialCapacity(int newIndustrialCapacity)
{
_industrialCapacity = newIndustrialCapacity;
}
public void SetMoneyCapacity(int newMoneyCapacity)
{
if (newMoneyCapacity >= 0)
{
_moneyCapacity = newMoneyCapacity;
}
}
public void SetMilitaryPower(int newMilitaryPower)
{
if (newMilitaryPower >= 0)
{
_militaryPower = newMilitaryPower;
}
}
public void SetRunning(bool newRunning)
{
_isRunning = newRunning;
}
public void SetId(ABuilding.BuildingID newId)
{
_iD = newId;
}
//----------------------------------------------------------------------------
//
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6d95038c0949c2a42a47dd6db1bdb27a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
namespace NBuilding
{
public static class BuildingBuilder
{
public static ABuilding Build(ABuilding.BuildingID eBuilding)
{
switch (eBuilding)
{
case ABuilding.BuildingID.Farm:
{
return new Farm();
}
case ABuilding.BuildingID.Smeltery:
{
return new Smeltery();
}
case ABuilding.BuildingID.Armory:
{
return new Armory();
}
case ABuilding.BuildingID.Spaceport:
{
return new Spaceport();
}
case ABuilding.BuildingID.Market:
{
return new Market();
}
default:
{
return null;
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6346204d85cd4e749988f67fc29952c7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,169 @@
using System.Collections;
using System.Collections.Generic;
namespace NBuilding
{
/// <summary>
/// Class <c>BuildingManager</c> contains functions to sum up values from buidlings at star system.
/// </summary>
public class BuildingManager
{
Dictionary<int, List<IBuilding>> doPlayerBuildings = new Dictionary<int, List<IBuilding>>();
/// <summary>
/// Function <c>GetAllValues</c> sums up the running cost of all buildings at star system of player.
/// <param><c>iId</c> is the id of a player.</param>
/// <returns>Returns <c>all values</c> of all buildings at star system of player.</returns>
/// More efficient because it iterates only once through list instead of 6 times.
/// </summary>
public BuildingValues GetAllValues(int iId)
{
BuildingValues oValues = new BuildingValues();
List<IBuilding> loBuildings = doPlayerBuildings[iId];
foreach (var oBuilding in loBuildings)
{
oValues.RunningCost += oBuilding.GetRunningCost();
oValues.ScienceCapacity += oBuilding.GetScienceCapacity();
oValues.FoodCapacity += oBuilding.GetFoodCapacity();
oValues.IndustrialCapacity += oBuilding.GetIndustrialCapacity();
oValues.MoneyCapacity += oBuilding.GetMoneyCapacity();
oValues.MilitaryPower += oBuilding.GetMilitaryPower();
}
return oValues;
}
/// <summary>
/// Function <c>GetRunningCost</c> sums up the running cost of all buildings at star system of player.
/// <param><c>iId</c> is the id of a player.</param>
/// <returns>Returns <c>running cost</c> of all buildings at star system of player.</returns>
/// </summary>
public int GetRunningCost(int iId)
{
int iRunningCost = 0;
List<IBuilding> loBuildings = doPlayerBuildings[iId];
foreach (var oBuilding in loBuildings)
{
iRunningCost += oBuilding.GetRunningCost();
}
return iRunningCost;
}
/// <summary>
/// Function <c>GetScienceCapacity</c> sums up the science capacity of all buildings at star system of player.
/// <param><c>iId</c> is the id of a player.</param>
/// <returns>Returns <c>science capacity</c> of all buildings at star system of player.</returns>
/// </summary>
public int GetScienceCapacity(int iId)
{
int iScienceCapacity = 0;
List<IBuilding> loBuildings = doPlayerBuildings[iId];
foreach (var oBuilding in loBuildings)
{
iScienceCapacity += oBuilding.GetScienceCapacity();
}
return iScienceCapacity;
}
/// <summary>
/// Function <c>GetFoodCapacity</c> sums up the food capacity of all buildings at star system of player.
/// <param><c>iId</c> is the id of a player.</param>
/// <returns>Returns <c>food capacity</c> of all buildings at star system of player.</returns>
/// </summary>
public int GetFoodCapacity(int iId)
{
int iFoodCapacity = 0;
List<IBuilding> loBuildings = doPlayerBuildings[iId];
foreach (var oBuilding in loBuildings)
{
iFoodCapacity += oBuilding.GetFoodCapacity();
}
return iFoodCapacity;
}
/// <summary>
/// Function <c>GetIndustrialCapacity</c> sums up the industrial capacity of all buildings at star system of player.
/// <param><c>iId</c> is the id of a player.</param>
/// <returns>Returns <c>industrial capacity</c> of all buildings at star system of player.</returns>
/// </summary>
public int GetIndustrialCapacity(int iId)
{
int iIndustrialCapacity = 0;
List<IBuilding> loBuildings = doPlayerBuildings[iId];
foreach (var oBuilding in loBuildings)
{
iIndustrialCapacity += oBuilding.GetIndustrialCapacity();
}
return iIndustrialCapacity;
}
/// <summary>
/// Function <c>GetMoneyCapacity</c> sums up the money capacity of all buildings at star system of player.
/// <param><c>iId</c> is the id of a player.</param>
/// <returns>Returns <c>money capacity</c> of all buildings at star system of player.</returns>
/// </summary>
public int GetMoneyCapacity(int iId)
{
int iMoneyCapacity = 0;
List<IBuilding> loBuildings = doPlayerBuildings[iId];
foreach (var oBuilding in loBuildings)
{
iMoneyCapacity += oBuilding.GetMoneyCapacity();
}
return iMoneyCapacity;
}
/// <summary>
/// Function <c>GetMilitaryCapacity</c> sums up the military capacity of all buildings at star system of player.
/// <param><c>iId</c> is the id of a player.</param>
/// <returns>Returns <c>military capacity</c> of all buildings at star system of player.</returns>
/// </summary>
public int GetMilitaryPower(int iId)
{
int iMilitaryPower = 0;
List<IBuilding> loBuildings = doPlayerBuildings[iId];
foreach (var oBuilding in loBuildings)
{
iMilitaryPower += oBuilding.GetMilitaryPower();
}
return iMilitaryPower;
}
/// <summary>
/// Function <c>BuildNewBuilding</c> checks if building already exists, if not creates a new building and adds it to list.
/// <param><c>iPlayerId</c> is the id of a player.</param>
/// <param><c>eBuildingId</c> is the id of a building.</param>
/// </summary>
public void BuildNewBuilding(int iPlayerId, ABuilding.BuildingID eBuildingId)
{
List<IBuilding> loBuildings = doPlayerBuildings[iPlayerId];
foreach (var oBuilding in loBuildings)
{
if (oBuilding.GetId() == eBuildingId)
{
// TODO throw exception
}
}
loBuildings.Add(BuildingBuilder.Build(eBuildingId));
}
/// <summary>
/// Function <c>DestroyBuilding</c> checks if building exists, if it exists, deletes it from list, if not, returns value of Remove(null).
/// <param><c>iPlayerId</c> is the id of a player.</param>
/// <param><c>eBuildingId</c> is the id of a building.</param>
/// </summary>
public void DestroyBuilding(int iPlayerId, ABuilding.BuildingID eBuildingId)
{
List<IBuilding> loBuildings = doPlayerBuildings[iPlayerId];
IBuilding building = null;
foreach (var oBuilding in loBuildings)
{
if (oBuilding.GetId() == eBuildingId)
{
building = oBuilding;
}
}
//TODO what does Remove return? handle
loBuildings.Remove(building);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 576e5620b79b5854c91181d252d444e1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
namespace NBuilding
{
/// <summary>
/// Class <c>BuildingValues</c> is a container to transport data.
/// <value></value>
/// <value>RunningCost is the running cost of a building.</value>
/// <value>ScienceCapacity is the amount of science produced by the building.</value>
/// <value>FoodCapacity is the amount of food produced by the building.</value>
/// <value>IndustrialCapacity is the amount of industry produced by the building.</value>
/// <value>MoneyCapacity is the amount of money produced by the building.</value>
/// <value>MilitaryPower is the amount of military produced by the building.</value>
/// </summary>
public class BuildingValues
{
public int RunningCost = 0;
public int ScienceCapacity = 0;
public int FoodCapacity = 0;
public int IndustrialCapacity = 0;
public int MoneyCapacity = 0;
public int MilitaryPower = 0;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4b6bc30937fb869458f2221f12868a00
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 790bd74d9b470f544b305c56600fa50f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace NBuilding
{
public class Farm : ABuilding
{
public Farm()
{
SetFoodCapacity(3);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 687e6b0e8ad8b6b429f19d1e523b9ba2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,76 @@
using System.Collections;
using System.Collections.Generic;
namespace NBuilding
{
/// <summary>
/// Interface <c>IBuilding</c> defines the functions for the buildings.
/// <param><c>iId</c> is the id of a player.</param>
/// <returns>Returns <c>all values</c> of all buildings at star system of player.</returns>
/// More efficient because it iterates only once through list instead of 6 times.
/// </summary>
public interface IBuilding
{
//----------------------------------------------------------------------------
// Getters
/// <summary>
/// Function <c>GetRunningCost</c> returns the running cost if the building is running.
/// </summary>
public int GetRunningCost();
/// <summary>
/// Function <c>GetScienceCapacity</c> returns the amount of science the building produces if it is running.
/// </summary>
public int GetScienceCapacity();
/// <summary>
/// Function <c>GetFoodCapacity</c> returns the amount of food the building produces if it is running.
/// </summary>
public int GetFoodCapacity();
/// <summary>
/// Function <c>GetIndustrialCapacity</c> returns the amount of industrial the building produces if it is running.
/// </summary>
public int GetIndustrialCapacity();
/// <summary>
/// Function <c>GetMoneyCapacity</c> returns the amount of money the building produces if it is running.
/// </summary>
public int GetMoneyCapacity();
/// <summary>
/// Function <c>GetMilitaryPower</c> returns the amount of power the building produces if it is running.
/// </summary>
public int GetMilitaryPower();
/// <summary>
/// Function <c>IsRunning</c> returns true if the building is running, false if the building is not running.
/// </summary>
public bool IsRunning();
/// <summary>
/// Function <c>GetId</c> returns id of building.
/// </summary>
public ABuilding.BuildingID GetId();
//----------------------------------------------------------------------------
// Setters
public void SetRunningCost(int newRunningCost);
public void SetScienceCapacity(int newScienceCapacity);
public void SetFoodCapacity(int newFoodCapacity);
public void SetIndustrialCapacity(int newIndustrialCapacity);
public void SetMoneyCapacity(int newMoneyCapacity);
public void SetMilitaryPower(int newMilitaryPower);
public void SetRunning(bool newRunning);
public void SetId(ABuilding.BuildingID newId);
//----------------------------------------------------------------------------
//
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b7fc53c8e36981944867e93f430530ba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e0fa54a65a66aee469a6cbe9f34092d5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
namespace NBuilding
{
public class Smeltery : ABuilding
{
public Smeltery()
{
SetIndustrialCapacity(3);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1da7c3c2e236a3b41bf2a6bfb386b03a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ef894b562a549e54f97363daa2986a4c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
namespace NBuilding
{
public class Armory : ABuilding
{
public Armory()
{
SetMilitaryPower(3);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2ed8a94ec6fa6d746a131a9ef93c848f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b461a2ff3391e3e449844f08232ce06e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,10 @@
using System.Collections;
using System.Collections.Generic;
namespace NBuilding
{
public class Spaceport : ABuilding
{
public Spaceport() { }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4d08ff6417479424ea4d546092ccc83f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 827a2da0b0eb4b74e8b23073689e2a00
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
namespace NBuilding
{
/// <summary>
/// Class <c>Market</c> defines the class for market.
/// </summary>
public class Market : ABuilding
{
public Market()
{
SetMoneyCapacity(3);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0f46ca5315e6ef743839ccb33a1901ad
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0e5731afcc42baa43ae629377f9debcb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
namespace NBuilding
{
public class University : ABuilding
{
public University()
{
SetScienceCapacity(3);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a716d03c78498e54ca17e19eab119e9c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Clock : MonoBehaviour
{
// Array ref to player managers
public GameManager GameManager { private get; set; }
public float DayTime = 10.0f;
// Start is called before the first frame update
void Start()
{
// callUpdateGame will be called once each n seconds
InvokeRepeating("CallUpdateGame", 0.0f, DayTime);
}
// Update is called once per frame
void Update(){}
// calls update game
private void CallUpdateGame()
{
if (GameManager != null)
{
GameManager.UpdateGame();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0128bb3b379e8144eae3b33ceb9c4bfd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 55abc87d40a760941b8437a23f670ed7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Exit : MonoBehaviour
{
public string sceneName;
// To change the scene by name
public void changeScene()
{
Debug.Log("Taste exit wurde gedr<64>ckt!");
SceneManager.LoadScene(sceneName);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d6e5a86eab8a0ad47b9c96feb36e4fc0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 232039b77fb3bde43bf698dc8ce34dea
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9003a43967753904b83b6a9b2c50f25e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
namespace NGalaxy
{
public class GalaxyController
{
private NGalaxy.GalaxyModelBuilder oGalaxyModelBuilder;
public GalaxyController(GalaxyModel oGalaxyModel, GalaxyViewScript oGalaxyView)
{
oGalaxyModelBuilder = new NGalaxy.GalaxyModelBuilder();
oGalaxyModel.SolarSystemModels = oGalaxyModelBuilder.BuildStreetSystem(oGalaxyModel.SolarSystemCount);
oGalaxyView.DisplaySolarSystems();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 74b1aed770a686c4e945881fa6d302eb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2e4d7f9b7336b6746b66e30e396557d9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,100 @@
namespace NGalaxy
{
public class GalaxyModel
{
public int SolarSystemCount;
public SolarSystemModel[] SolarSystemModels;
public GalaxyModel()
{
this.SolarSystemCount = NewGameDataManager.Instance.NumberOfSolarSystems;
}
public NPlanet.PlanetModel FindPlanet(int PlanetID)
{
NPlanet.PlanetModel oPlanetToReturn = null;
for (int i = 0; i < SolarSystemModels.Length; i++)
{
oPlanetToReturn = SolarSystemModels[i].FindPlanet(PlanetID);
if (oPlanetToReturn != null)
{
break;
}
}
return oPlanetToReturn;
}
public int GetIndustrialCapacityOfSolarSystems(int iPlayerID)
{
int iIndustrialCapacitySum = 0;
for (int i = 0; i < SolarSystemModels.Length; i++)
{
iIndustrialCapacitySum += SolarSystemModels[i].GetIndustrialCapacityOfPlanets(iPlayerID);
}
return iIndustrialCapacitySum;
}
public int GetMoneyOfSolarSystems(int iPlayerID)
{
int iMoneySum = 0;
for (int i = 0; i < SolarSystemModels.Length; i++)
{
iMoneySum += SolarSystemModels[i].GetMoneyOfPlanets(iPlayerID);
}
return iMoneySum;
}
public int GetScienceOfSolarSystems(int iPlayerID)
{
int iScienceSum = 0;
for (int i = 0; i < SolarSystemModels.Length; i++)
{
iScienceSum += SolarSystemModels[i].GetScienceOfPlanets(iPlayerID);
}
return iScienceSum;
}
public int GetPowerOfSolarSystems(int iPlayerID)
{
int iPowerSum = 0;
for (int i = 0; i < SolarSystemModels.Length; i++)
{
iPowerSum += SolarSystemModels[i].GetPowerOfPlanets(iPlayerID);
}
return iPowerSum;
}
public int GetFoodOfSolarSystems(int iPlayerID, int iFoodTechLevel)
{
int iFoodSum = 0;
for (int i = 0; i < SolarSystemModels.Length; i++)
{
iFoodSum += SolarSystemModels[i].GetFoodOfPlanets(iPlayerID, iFoodTechLevel);
}
return iFoodSum;
}
public int GetPopulationOfSolarSystems(int iPlayerID)
{
int iPopulationSum = 0;
for (int i = 0; i < SolarSystemModels.Length; i++)
{
iPopulationSum += SolarSystemModels[i].GetPopulationOfPlanets(iPlayerID);
}
return iPopulationSum;
}
public int GetActualFoodOfSolarSystems(int iPlayerID)
{
int iActualFoodSum = 0;
for (int i = 0; i < SolarSystemModels.Length; i++)
{
iActualFoodSum += SolarSystemModels[i].GetActualFoodOfPlanets(iPlayerID);
}
return iActualFoodSum;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 23db42a6f1827e54d897bcaabf139cea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,136 @@
using UnityEngine;
namespace NGalaxy
{
public class GalaxyModelBuilder
{
/**
*
* @param iCountOfSolarSystems
* @return SolarSystemModel[] models of solarsystem
*/
public SolarSystemModel[] BuildStreetSystem(int iCountOfSolarSystems)
{
if ((iCountOfSolarSystems % 2) != 0)
{
iCountOfSolarSystems--;
}
int iNumberOfDistinctSolarSystems = iCountOfSolarSystems / 2;
SolarSystemModel[] SolarSystemModels = new SolarSystemModel[iCountOfSolarSystems];
SolarSystemModel[] oSolarSystemsToClone = new SolarSystemModel[iNumberOfDistinctSolarSystems];
for (int i = 0; i < iNumberOfDistinctSolarSystems; i++)
{
oSolarSystemsToClone[i] = new SolarSystemModel(0, 3);
}
// Copy distinct planets into array to return
int iCounterDistinct = 0;
int iCounterDistinctIncrementValue = 1;
for (int i = 0; i < iCountOfSolarSystems; i++)
{
// Turn around order of planets with resources at mid
// So both players will start at planet with same resources
// Example: 1 2 3 4 5 5 4 3 2 1
if (iCounterDistinct == iNumberOfDistinctSolarSystems)
{
iCounterDistinct = iNumberOfDistinctSolarSystems - 1;
iCounterDistinctIncrementValue = -1;
}
SolarSystemModels[i] = oSolarSystemsToClone[iCounterDistinct].Clone();
iCounterDistinct += iCounterDistinctIncrementValue;
}
int iPlanetIDCounter = 0;
// Set position of solar systems relative to screen size
int iBorderMargin = (Screen.width / iCountOfSolarSystems) / 2;
int iStreetY = Screen.height / 3;
for (int i = 0; i < iCountOfSolarSystems; i++)
{
SolarSystemModels[i].SolarSystemID = i;
SolarSystemModels[i].Position = new Vector2((i * (Screen.width / iCountOfSolarSystems) + iBorderMargin), iStreetY);
SolarSystemModels[i].SolarSystemSprite = SolarSystemSpriteRandomizer.GetRandomSprite();
for (int j = 0; j < SolarSystemModels[i].Planets.Length; j++)
{
SolarSystemModels[i].Planets[j].PlanetID = iPlanetIDCounter;
iPlanetIDCounter++;
}
}
SolarSystemModels[0].Planets[0].PlayerID = 0;
SolarSystemModels[0].Planets[0].Resous.Population = 1;
SolarSystemModels[iCountOfSolarSystems - 1].Planets[0].PlayerID = 1;
SolarSystemModels[iCountOfSolarSystems - 1].Planets[0].Resous.Population = 1;
return SolarSystemModels;
}
//TODO
private void BuildSolarSystems(int iCountOfSolarSystems, int iCountOfPlayers, int[,] aaiPlayerArea)
{
int iNumberOfDistinctSolarSystems = iCountOfSolarSystems / iCountOfPlayers;
// Create iNumberOfDistinctPlanets planets to clone them multiple times playercount.
SolarSystemModel[] oSolarSystemsToClone = new SolarSystemModel[iNumberOfDistinctSolarSystems];
// Divide Canvas into squares of equal size
// Create a two dimensional array representing the canvas grid and put into it the center of square and bool if used.
SolarSystemBuildHelper[,] aaoCanvasGridRepresentation = new SolarSystemBuildHelper[12, 8];
for (int column = 0; column < 12; column++)
{
for (int row = 0; row < 8; row++)
{
aaoCanvasGridRepresentation[column, row].Position = new Vector2();
}
}
for (int i = 0; i < iNumberOfDistinctSolarSystems; i++)
{
oSolarSystemsToClone[i] = new SolarSystemModel(0, 3);
}
SolarSystemModel[] SolarSystemModels = new SolarSystemModel[iCountOfSolarSystems];
int iCounterDistinct = 0;
for (int i = 0; i < iCountOfSolarSystems; i++)
{
if (iCounterDistinct == iNumberOfDistinctSolarSystems)
{
iCounterDistinct = 0;
}
SolarSystemModels[i] = oSolarSystemsToClone[iCounterDistinct].Clone();
iCounterDistinct++;
}
// Insert distinct planets and clones into each players area so each player has the same amount of resources
}
//TODO
private void Build4PlayerGalaxy(int iCountOfSolarSystems, int iCountOfPlayers)
{
// Depending on players divide grid so each player has one area.
// For beginning (because I don't have time to invent a good partition system) add one default layout for maximum 4 players.
// Grid is 12 x 8
// 6 x 4 squares per player
// [0,0] - [5,3] player 0
// [0,4] - [5,7] player 2
// [6,3] - [11,3] player 3
// [6,4] - [11,7] player 1
int[,] aaiPlayerArea = {
{ 0, 0, 0, 0, 2, 2, 2, 2 }, { 0, 0, 0, 0, 2, 2, 2, 2 }, { 0, 0, 0, 0, 2, 2, 2, 2 },
{ 0, 0, 0, 0, 2, 2, 2, 2 }, { 0, 0, 0, 0, 2, 2, 2, 2 }, { 0, 0, 0, 0, 2, 2, 2, 2 },
{ 3, 3, 3, 3, 1, 1, 1, 1 }, { 3, 3, 3, 3, 1, 1, 1, 1 }, { 3, 3, 3, 3, 1, 1, 1, 1 },
{ 3, 3, 3, 3, 1, 1, 1, 1 }, { 3, 3, 3, 3, 1, 1, 1, 1 }, { 3, 3, 3, 3, 1, 1, 1, 1 }
};
BuildSolarSystems(iCountOfSolarSystems, iCountOfPlayers, aaiPlayerArea);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b1f8a0dc14b08c14493b85fac308c626
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
using UnityEngine;
public class SolarSystemBuildHelper
{
public Vector2 Position;
public bool Occupied;
public SolarSystemBuildHelper()
{
Position = new Vector2(0, 0);
Occupied = false;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9a4d96d3d6709714e90f5761b39233e7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1d1a0f5d1fafdb643bdfedef050eff32
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4074bef126c5b264f91ab9e2aa1c51d7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,113 @@
/**
* @file
*
* @author Aaron Moser
*
* @package Assets.Scripts.Galaxy.SolarSystem.Controller
*/
using UnityEngine;
namespace NSolarSystem
{
/**
* @section DESCRIPTION
*
* Class handles communication of solar system view with solar system model.
*/
public class SolarSystemController
{
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public values
/**
* Handler for event.
*/
public delegate void SolarSystemPressedHandler(object sender, SolarSystemEventArgs e);
/**
* Event if solar system is clicked on.
*/
public static event SolarSystemPressedHandler SolarSystemPressed;
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private values
/**
* Array with references to solar system models.
*/
private SolarSystemModel[] aoSolarSystemModels;
/**
* Reference to solar system view.
*/
private SolarSystemViewScript oSolarSystemView;
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public functions
/**
* Constructor sets references of array to solar system models and solar system view.
*
* Adds the function @see OnSolarSystemPressed(object oSender, SolarSystemEventArgs e) to the SolarSystemPressed event.
*
* @param aoSolarSystemModels array with references to solar system models.
* @param oSolarSystemView reference to solar system view.
*/
public SolarSystemController(SolarSystemModel[] aoSolarSystemModels, SolarSystemViewScript oSolarSystemView)
{
this.aoSolarSystemModels = aoSolarSystemModels;
this.oSolarSystemView = oSolarSystemView;
SolarSystemPressed += OnSolarSystemPressed;
}
/**
* Static function can be called without instantiating an object of SolarSystemController class.
* Invokes the SolarSystemPressed event if it is not null.
*
* @param oSender object from where funtion was called.
* @param eArgs event arguments containing information of event, unique solar system id.
*/
public static void SolarSystemPressedEvent(object oSender, SolarSystemEventArgs eArgs)
{
SolarSystemPressed?.Invoke(oSender, eArgs);
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private functions
/**
* Function is added at constructor to SolarSystemPressed event. If event gets invoked, this function is called.
* Calls @see DisplaySolarSystem(int iSolarSystemID) with unique solar system id received in event args.
*
* @param oSender, object where event occured.
* @param e, event arguments containing unique solar system id.
*/
private void OnSolarSystemPressed(object oSender, SolarSystemEventArgs e)
{
switch (e.eSolarSystemEvent)
{
case (ESolarSystemEvent.SolarSystemClicked):
{
DisplaySolarSystem(e.SolarSystemID);
}
break;
default:
{
}
break;
}
}
/**
* Calls DisplaySolarSystem(iSolarSystemID) function from solar system view, to display solar system.
*
* @param iSolarSystemID id of solar system to display.
*/
private void DisplaySolarSystem(int iSolarSystemID)
{
oSolarSystemView.DisplaySolarSystem(iSolarSystemID);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b344fc279f5f4834482d11fd757407d9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fec9381aea5e0c240b7d57103fc28c7e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
/**
* @file
*
* @author Aaron Moser
*
* @package Assets.Scripts.Galaxy.SolarSystem.Events
*/
/**
* @section DESCRIPTION
*
* Enum contains values describing events possible at solar system level.
*/
public enum ESolarSystemEvent
{
SolarSystemClicked
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8a56601b79c4f5e4c92b263f2712f94d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,39 @@
/**
* @file
*
* @author Aaron Moser
*
* @package Assets.Scripts.Galaxy.SolarSystem.Events
*/
namespace NSolarSystem
{
/**
* @section DESCRIPTION
*
* Class .
*/
public class SolarSystemEventArgs
{
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public values
public ESolarSystemEvent eSolarSystemEvent { get; set; }
public int SolarSystemID { get; set; }
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private values
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public functions
public SolarSystemEventArgs(ESolarSystemEvent eSolarSystemEvent, int iSolarSystemID)
{
this.eSolarSystemEvent = eSolarSystemEvent;
this.SolarSystemID = iSolarSystemID;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private functions
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a7c8e74a072440b4ca269f113ace8036
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 39d54702aa5eb3f41b4200abd168a1f9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,284 @@
/**
* @file
*
* @author Mohamad Kadou
* @author Aaron Moser
*
* @package Assets.Scripts.Galaxy.SolarSystem.Model
*/
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/**
* @section DESCRIPTION
*
* Class contains attributes for solar system model.
*/
public class SolarSystemModel
{
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public values
/**
* Property ID of solar system.
*/
public int SolarSystemID { get; set; }
/**
* Property Planets array containing planet references of this solar system.
*/
public NPlanet.PlanetModel[] Planets { get; set; }
/**
* Property Position on ui of this solar system.
*/
public Vector2 Position { get; set; }
/**
* Sprite of this solar system.
*/
public Sprite SolarSystemSprite;
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private values
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public consturctor
/**
* Constructor initializes this solar system model, setting overhanded id and number of planets.
* Initializes planets array with capacity of number of planets.
* Sets planets array to chosen values.
*
* @param iSolarSystemId unique id of solar system.
* @param iNumberOfPlanets number of planet at solar system.
*/
public SolarSystemModel(int iSolarSystemId, int iNumberOfPlanets)
{
this.SolarSystemID = iSolarSystemId;
// Create array with size depending overhanded value.
this.Planets = new NPlanet.PlanetModel[iNumberOfPlanets];
System.Random oRand = new System.Random();
// Instantiate models of planets.
for (int i = 0; i < iNumberOfPlanets; i++)
{
this.Planets[i] = new NPlanet.PlanetModel();
this.Planets[i].OrbitRadius = (i + 1) * 100;
this.Planets[i].OrbitAngle = (i + 1) * 30;
this.Planets[i].RotationSpeed = (oRand.Next(1,4) * 0.1f);
}
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private consturctor
/**
* Empty constructor for @see Clone() funtion.
*/
private SolarSystemModel()
{ }
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public functions
/**
* Clones this SolarSytemModel and returns clone.
*
* @return cloned SolarSystemModel of this.
*/
public SolarSystemModel Clone()
{
SolarSystemModel oSolarSystemModelClone = new SolarSystemModel();
// Primiive datatypes require flat copy
// Clone id
oSolarSystemModelClone.SolarSystemID = this.SolarSystemID;
// Complex datatypes require deep copy
// Clone planets
oSolarSystemModelClone.Planets = new NPlanet.PlanetModel[this.Planets.Length];
for (int i = 0; i < this.Planets.Length; i++)
{
oSolarSystemModelClone.Planets[i] = this.Planets[i].Clone();
}
// Clone position
oSolarSystemModelClone.Position = new Vector2(this.Position.x, this.Position.y);
return oSolarSystemModelClone;
}
/**
* Searches planets array for planet with id indicated by overhanded planet id.
*
* @param PlanetID unique id of planet to search for.
*
* @return reference of planet if it was found. Else null.
* @todo should throw exception if planet not found. Never return null.
*/
public NPlanet.PlanetModel FindPlanet(int PlanetID)
{
NPlanet.PlanetModel oPlanetToReturn = null;
for (int i = 0; i < Planets.Length; i++)
{
if (Planets[i].PlanetID == PlanetID)
{
oPlanetToReturn = Planets[i];
break;
}
}
return oPlanetToReturn;
}
/**
* Returns the industrial capacity sum of all planets that belong to overhanded player id.
*
* @param iPlayerID id of player to look if a planet of this solar system belongs to it.
*
* @return sum of industrial capacity resource of all planets that belong to overhanded player id.
*/
public int GetIndustrialCapacityOfPlanets(int iPlayerID)
{
int iIndustrialCapacitySum = 0;
for (int i = 0; i < Planets.Length; i++)
{
if (iPlayerID == Planets[i].PlayerID)
{
iIndustrialCapacitySum += Planets[i].Resous.Population * Planets[i].Resous.IndustrialCapacity;
}
}
return iIndustrialCapacitySum;
}
/**
* Returns the money sum of all planets that belong to overhanded player id.
*
* @param iPlayerID id of player to look if a planet of this solar system belongs to it.
*
* @return sum of money resource of all planets that belong to overhanded player id.
*/
public int GetMoneyOfPlanets(int iPlayerID)
{
int iMoneySum = 0;
for (int i = 0; i < Planets.Length; i++)
{
if (iPlayerID == Planets[i].PlayerID)
{
iMoneySum += Planets[i].Resous.Population * Planets[i].Resous.Money;
}
}
return iMoneySum;
}
/**
* Returns the science sum of all planets that belong to overhanded player id.
*
* @param iPlayerID id of player to look if a planet of this solar system belongs to it.
*
* @return sum of science resource of all planets that belong to overhanded player id.
*/
public int GetScienceOfPlanets(int iPlayerID)
{
int iScienceSum = 0;
for (int i = 0; i < Planets.Length; i++)
{
if (iPlayerID == Planets[i].PlayerID)
{
iScienceSum += Planets[i].Resous.Population * Planets[i].Resous.Science;
}
}
return iScienceSum;
}
/**
* Returns the power sum of all planets that belong to overhanded player id.
*
* @param iPlayerID id of player to look if a planet of this solar system belongs to it.
*
* @return sum of power resource of all planets that belong to overhanded player id.
*/
public int GetPowerOfPlanets(int iPlayerID)
{
int iPowerSum = 0;
for (int i = 0; i < Planets.Length; i++)
{
if (iPlayerID == Planets[i].PlayerID)
{
iPowerSum += Planets[i].Resous.Population * Planets[i].Resous.Power;
}
}
return iPowerSum;
}
/**
* Returns the food sum of all planets that belong to overhanded player id.
*
* @param iPlayerID id of player to look if a planet of this solar system belongs to it.
*
* @return sum of food resource of all planets that belong to overhanded player id.
*/
public int GetFoodOfPlanets(int iPlayerID, int iFoodTechLevel)
{
int iFoodSum = 0;
for (int i = 0; i < Planets.Length; i++)
{
if (iPlayerID == Planets[i].PlayerID)
{
Planets[i].UpdateFoodProduction(iFoodTechLevel);
iFoodSum += Planets[i].Resous.Population * Planets[i].Resous.Food;
}
}
return iFoodSum;
}
/**
* Returns the population sum of all planets that belong to overhanded player id.
*
* @param iPlayerID id of player to look if a planet of this solar system belongs to it.
*
* @return sum of population resource of all planets that belong to overhanded player id.
*/
public int GetPopulationOfPlanets(int iPlayerID)
{
int iPopulationSum = 0;
for (int i = 0; i < Planets.Length; i++)
{
if (iPlayerID == Planets[i].PlayerID)
{
Planets[i].DistributeFoodToPopulation();
iPopulationSum += Planets[i].Resous.Population;
}
}
return iPopulationSum;
}
/**
* Returns the actual food sum of all planets that belong to overhanded player id.
*
* @param iPlayerID id of player to look if a planet of this solar system belongs to it.
*
* @return sum of actual food resource of all planets that belong to overhanded player id.
*/
public int GetActualFoodOfPlanets(int iPlayerID)
{
int iActualFoodSum = 0;
for (int i = 0; i < Planets.Length; i++)
{
if (iPlayerID == Planets[i].PlayerID)
{
iActualFoodSum += Planets[i].Resous.ActualFood;
}
}
return iActualFoodSum;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private functions
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 144fa302472cbea4ea6bb2a3460f413c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,41 @@
/**
* @file
*
* @author Aaron Moser
*
* @package Assets.Scripts.Galaxy.SolarSystem.Model
*/
using System;
using UnityEngine;
/**
* @section DESCRIPTION
*
* Class contains function to instantiate random solar system sprite.
*/
public static class SolarSystemSpriteRandomizer
{
/**
* Returns a randomly selected solar system sprite.
*
* @return Sprite randomly selected.
*/
public static Sprite GetRandomSprite()
{
String sSpriteToReturn = "Blue";
System.Random rnd = new System.Random();
int iSpriteNumber = rnd.Next(0, 2);
switch (iSpriteNumber)
{
case 0:
{
sSpriteToReturn = "Red";
}
break;
}
return Resources.Load<Sprite>("Images/Sun" + sSpriteToReturn); ;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2c6ed38d6276d10439911cdb34ce4962
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4d75ca111c12f4a49a36c8de0dfb25c2
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 82a5ed6bd3311014bb3bdc6db7a072e6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
/**
* @file
*
* @author Aaron Moser
*
* @package Assets.Scripts.Galaxy.SolarSystem.Planet.Controller
*/
namespace NPlanet
{
/**
* @todo Should have functionality of PlanetInfo. Like PlanetInfo reference should be here instead of solar system view. If planet is clicked, function from this class is called and values set.
*/
public class PlanetController
{
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public values
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private values
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Unity Functions
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public Functions
/**
* Constructor of PlanetController class.
* @todo ..
*/
public PlanetController(SolarSystemModel[] aoSolarSystemModels, PlanetViewScript oPlanetView)
{
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private Functions
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4d3f2a94a68f9d54bb393beb1bac1702
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e6ccf3823763d954ebf650dc47c9c585
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,159 @@
/**
* @file
*
* @author Mohamad Kadou
* @author Aaron Moser
*
* @package Assets.Scripts.Galaxy.SolarSystem.Planet.Model
*/
using System.Collections.Generic;
using UnityEngine;
namespace NPlanet
{
/**
* @section DESCRIPTION
*
* Class for model of a planet. Contains all necessary values a planet needs.
*/
public class PlanetModel
{
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private values
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public values
/**
* Unique ID of planet
*/
public int PlanetID { get; set; }
/**
* ID of player whom the planet belongs to.
*/
public int PlayerID { get; set; }
/**
* Resources of planet.
*/
public NResources.Resources Resous { get; set; }
/**
* Buildings of planet.
*/
public List<NBuilding.IBuilding> Buildings { get; set; }
/**
* Start position of planet.
*/
public Vector3 Position { get; set; }
/**
* Orbit radius of planet.
*/
public float OrbitRadius;
/**
* Rotation speed of planet.
*/
public float RotationSpeed;
/**
* Orbit starting angle of planet.
*/
public float OrbitAngle;
/**
* Local food tech level on planet. Fetched from player it belongs to.
*/
public int FoodLevel;
/**
* Sprite of planet.
*/
public Sprite PlanetSprite;
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Unity Functions
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public Functions
/**
* Constructor initializes random values for resources of planet.
* Sets sprite of planet to a random sprite.
*/
public PlanetModel()
{
// Planet Belongs to no player
this.PlayerID = -1;
this.Resous = new NResources.Resources(1,8);
this.Buildings = new List<NBuilding.IBuilding>();
this.PlanetSprite = PlanetModelSpriteRandomizer.GetRandomSprite();
}
/**
* Distributes food to the population and reduces population if there is not enough food.
*/
public void DistributeFoodToPopulation()
{
int iRemainingFood = Resous.Food - Resous.Population;
if (iRemainingFood < 0)
{
// If the remaining food is smaller than 0, this means the population is too huge to feed everyone.
// ActualFood will be set to 0 and population will shrink to value of food.
Resous.ActualFood = 0;
Resous.Population = Resous.Food;
}
else
{
// If there was enough food to feed the population
// set actualfood to the remaining food value
Resous.ActualFood = iRemainingFood;
}
}
/**
* Updates food lavele if the food tech level of the player changed.
*/
public void UpdateFoodProduction(int iNewFoodLevel)
{
if (iNewFoodLevel > FoodLevel)
{
Resous.Food *= iNewFoodLevel;
FoodLevel = iNewFoodLevel;
}
}
/**
* Clones a planet creating a deep copy of all attributes.
*
* @return copy of this PlanetModel.
*/
public PlanetModel Clone()
{
PlanetModel oPlanetModelClone = new PlanetModel();
// Primitive properties can be copied flat
oPlanetModelClone.PlanetID = this.PlanetID;
oPlanetModelClone.PlayerID = this.PlayerID;
oPlanetModelClone.OrbitRadius = this.OrbitRadius;
oPlanetModelClone.FoodLevel = this.FoodLevel;
oPlanetModelClone.RotationSpeed = this.RotationSpeed;
oPlanetModelClone.OrbitAngle = this.OrbitAngle;
// Complex datatypes need deep copy
oPlanetModelClone.Resous = this.Resous.clone();
// Deep clone missing, building not implemented yet
oPlanetModelClone.Buildings = new List<NBuilding.IBuilding>();
oPlanetModelClone.Position = new Vector3(this.Position.x, this.Position.y, 0);
return oPlanetModelClone;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private Functions
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c13ac23c96fd0e340ad323ce7b903fd6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,75 @@
/**
* @file
*
* @author Aaron Moser
*
* @package Assets.Scripts.Galaxy.SolarSystem.Planet.Model
*/
using System;
using UnityEngine;
/**
* @section DESCRIPTION
*
* Class contains functionality to return random sprites for Planets.
*/
public static class PlanetModelSpriteRandomizer
{
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private values
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Unity Functions
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public Functions
/**
* Calculates a number between 0 and 5 and returns corresponding sprite.
*
* @return A random Sprite object with image from the Resources/Images/Planet folder. Hardcoded paths!
*/
public static Sprite GetRandomSprite()
{
String sSpriteToReturn = "Dry";
System.Random rnd = new System.Random();
// Creates random number 0 to 5
int iSpriteNumber = rnd.Next(0, 6);
// Has no case 5 because case 5 is implicit the initial value. At the moment "Dry".
switch (iSpriteNumber)
{
case 0:
{
sSpriteToReturn = "Gas";
}
break;
case 1:
{
sSpriteToReturn = "Green";
}
break;
case 2:
{
sSpriteToReturn = "Ice";
}
break;
case 3:
{
sSpriteToReturn = "Stone";
}
break;
case 4:
{
sSpriteToReturn = "Volcano";
}
break;
}
return Resources.Load<Sprite>("Images/Planet" + sSpriteToReturn); ;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private Functions
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4762c63c5d5e4d248b72e7abb0d8401c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 125d7995827c5864cb9ce27aa32f44da
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,82 @@
/**
* @file
*
* @author Mohamad Kadou
*
* @package Assets.Scripts.Galaxy.SolarSystem.Planet.View
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace NPlanet
{
/**
* @section DESCRIPTION
*
* Class administrates movement of an overhanded PlanetViewBody object on it's parent ui.
*/
public class PlanetMovement
{
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public values
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private values
/**
*
*/
private NPlanetView.PlanetViewBody planet;
/**
* Position of center.
*/
private Vector2 centerPosition;
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public functions
/**
* Constructor, setting references of planet and center position.
*
* @param planet refernce to planet object.
* @param centerPosition reference to center position.
*/
public PlanetMovement(NPlanetView.PlanetViewBody planet, Vector2 centerPosition)
{
this.planet = planet;
this.centerPosition = centerPosition;
}
/**
* Moves planet by calculating new angle of planet, afterwards calling @see GetPositionOnCircle() to set new position.
*/
public void MovePlanet()
{
// Update angle based on velocity
planet.OrbitAngle += planet.RotationSpeed * Time.deltaTime;
// Calculate new position of planet
planet.transform.position = GetPositionOnCircle();
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private functions
/**
* Returns position of planet on circle.
*
* @return Position of planet on circle as Vector3 object.
*/
private Vector3 GetPositionOnCircle()
{
// X-Position on circle
float xPos = centerPosition.x + Mathf.Sin(planet.OrbitAngle) * planet.OrbitRadius;
// Y-Position on circle
float yPos = centerPosition.y + Mathf.Cos(planet.OrbitAngle) * planet.OrbitRadius;
// Return position as vector
return new Vector3(xPos, yPos, 0f);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9e58a406000b6cd448a3901e4a61f2f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,134 @@
/**
* @file
*
* @author Mohamad Kadou
* @author Aaron Moser
*
* @package Assets.Scripts.Galaxy.SolarSystem.Planet.View
*/
using UnityEngine;
using UnityEngine.UI;
namespace NPlanetView
{
/**
* Class representing a planet on the ui. Contains necessary attributes.
*/
public class PlanetViewBody : Button
{
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public values
/**
* Unique ID of planet.
*/
public int PlanetID { get; set; }
/**
* Radius of orbit where planet travels on.
*/
public float OrbitRadius { get; set; }
/**
* Angle of position at orbit where planet travels on.
*/
public float OrbitAngle { get; set; }
/**
* Speed with which planet travels on orbit.
*/
public float RotationSpeed { get; set; }
/**
* Color property of player marker.
*
* @param value of new Color representing a player to set player marker to.
*
* @returns Color of player, which this planet belongs to.
*/
public Color PlayerMarkerColor
{
get
{
return gameObject.transform.GetChild(0).GetComponent<Image>().color;
}
set
{
gameObject.transform.GetChild(0).GetComponent<Image>().color = value;
}
}
/**
* Sprite property of player marker.
*
* @param value of new Sprite to set player marker to.
*
* @returns Sprite of player marker.
*/
public Sprite PlayerMarkerSprite
{
get
{
return gameObject.transform.GetChild(0).GetComponent<Image>().sprite;
}
set
{
gameObject.transform.GetChild(0).GetComponent<Image>().sprite = value;
}
}
/**
* Sprite property of planet.
*
* @param value of new Sprite to set planet to.
*
* @returns Sprite of planet.
*/
public Sprite PlanetSprite
{
get
{
return gameObject.GetComponent<Image>().sprite;
}
set
{
gameObject.GetComponent<Image>().overrideSprite = value;
}
}
/**
* Position property of planet.
*
* @param value of new position to set planets position to.
*
* @returns Position of planet as Vector2.
*/
public Vector2 Position
{
get
{
return gameObject.transform.position;
}
set
{
gameObject.transform.position = value;
}
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private values
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Unity Functions
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public Functions
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private Functions
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 09a89437dc8b88b4b8fa7f9bc59c591a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,125 @@
/**
* @file
*
* @author Mohamad Kadou
* @author Aaron Moser
*
* @package Assets.Scripts.Galaxy.SolarSystem.Planet.View
*/
using UnityEngine;
using UnityEngine.UI;
/**
* @section DESCRIPTION
*
* Class administrates the PlanetBodyViews, which are created, if the player clicks on a solar system.
* Cares about the instantiation and the movement of the objects on the ui canvas.
*/
public class PlanetViewScript : MonoBehaviour
{
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public values
/**
* Reference to text FoodNumberText
*/
public Text FoodNumberText;
/**
* Reference to text IndustryNumberText
*/
public Text IndustryNumberText;
/**
* Reference to text WealthNumberText
*/
public Text WealthNumberText;
/**
* Reference to text ScienceNumberText
*/
public Text ScienceNumberText;
/**
* Reference to text MilitaryNumberText
*/
public Text MilitaryNumberText;
/**
* Reference to text PopulationNumberText
*/
public Text PopulationNumberText;
/**
* Reference to text ActualFoodNumberText
*/
public Text ActualFoodNumberText;
/**
* ID of focused planet, set by the player clicking on the planet.
*/
public int iFocusedPlanet = 0;
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private values
/**
* Reference to GameModel. Set by call from parent view of @see SetGameModel(GameModel oGameModel).
*/
private GameModel oGameModel;
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Unity Functions
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public Functions
/**
* Sets intern game model reference to overhanded reference.
* @param oGameModel reference to game model.
*/
public void SetGameModel(GameModel oGameModel)
{
// Set own game model
this.oGameModel = oGameModel;
}
/**
* Sets intern value iFocusedPlanet to iPlanetID and calls @see DailyUpdateView().
*
* @param iPlanetID id of planet which was clicked by the player.
*/
public void SetFocusedPlanet(int iPlanetID)
{
if (iPlanetID != iFocusedPlanet)
{
iFocusedPlanet = iPlanetID;
DailyUpdateView();
}
}
/**
* Called every day or if player clicks on planet through SetFocusedPlanet.
* Sets PlanetInfo texts to fetched data from planet model.
*/
public void DailyUpdateView()
{
// Search reference of planet by id represented by iFocusedPlanet.
NPlanet.PlanetModel oPlanetModel = oGameModel.GalaxyModel.FindPlanet(iFocusedPlanet);
// If search was successful, set texts to values of planet.
if (oPlanetModel != null)
{
FoodNumberText.text = oPlanetModel.Resous.Food.ToString() + " * " + oPlanetModel.Resous.Population.ToString();
IndustryNumberText.text = oPlanetModel.Resous.IndustrialCapacity.ToString() + " * " + oPlanetModel.Resous.Population.ToString();
WealthNumberText.text = oPlanetModel.Resous.Money.ToString() + " * " + oPlanetModel.Resous.Population.ToString();
ScienceNumberText.text = oPlanetModel.Resous.Science.ToString() + " * " + oPlanetModel.Resous.Population.ToString();
MilitaryNumberText.text = oPlanetModel.Resous.Power.ToString() + " * " + oPlanetModel.Resous.Population.ToString();
PopulationNumberText.text = oPlanetModel.Resous.Population.ToString() + " * " + oPlanetModel.Resous.Population.ToString();
ActualFoodNumberText.text = oPlanetModel.Resous.ActualFood.ToString() + " * " + oPlanetModel.Resous.Population.ToString();
}
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public Functions
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0ab6531148f872e45903f7aac96859f8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4669f404fdfda15469c48c622bdb79b1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,103 @@
/**
* @file
*
* @author Mohamad Kadou
* @author Aaron Moser
*
* @package Assets.Scripts.Galaxy.SolarSystem.View
*/
using UnityEngine;
using UnityEngine.UI;
/**
* @section DESCRIPTION
*
* Class administrates the SolarSystemViewBodies, which are created, if the game starts.
* Cares about the instantiation of the solar system view objects on the ui canvas.
*/
public class SolarSystemViewBody : Button
{
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public values
/**
* References to the player markers, which indicate if players colonized planets at the star system.
*/
public GameObject[] playerMarkers;
/**
* Unique id of solar system.
*/
public int ID;
/**
* Sprite property of this solar system.
*
* @param value of new Sprite to set solar system'sprite to.
*
* @return sprite of this solar system.
*/
public Sprite SolarSystemSprite
{
get
{
return gameObject.GetComponent<Image>().sprite;
}
set
{
gameObject.GetComponent<Image>().overrideSprite = value;
}
}
/**
* Position property of this solar system.
*
* @param value of new position to set solar system to.
*
* @return position of this solar system as Vector2.
*/
public Vector2 Position
{
get
{
return gameObject.transform.position;
}
set
{
gameObject.transform.position = value;
}
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private values
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public functions
/**
* Set player marker indicated by iElement to color.
*
* @param iElement indicates which of the n player markers is set to a color. n is number of planets at solar system.
* @param color which player marker is set to.
*/
public void SetPlayerMarkerColor(int iElement, Color color)
{
playerMarkers[iElement].GetComponent<Image>().color = color;
}
/**
* Set player marker sprite indicated by iElement to sprite.
*
* @param iElement indicates which of the n player markers sprite is set. n is number of planets at solar system.
* @param sprite which player marker sprite is set to.
*/
public void SetPlayerMarkerSprite(int iElement, Sprite sprite)
{
playerMarkers[iElement].GetComponent<Image>().overrideSprite = sprite;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private functions
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 19ab00982c6d1164196a353710379ac7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,222 @@
/**
* @file
*
* @author Mohamad Kadou
* @author Aaron Moser
*
* @package Assets.Scripts.Galaxy.SolarSystem.View
*/
using UnityEngine;
using UnityEngine.UI;
/**
* @section DESCRIPTION
*
* Class administrates the PlanetBodyViews, which are created, if the player clicks on a solar system.
* Cares about the instantiation and the movement of the objects on the ui canvas.
*/
public class SolarSystemViewScript : MonoBehaviour
{
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public values
/**
* Children view of this view.
*/
public PlanetViewScript oPlanetView;
/**
* Reference to SolarSystemCanvas.PlanetInfo GameObject at unity ui.
*/
public GameObject PlanetInfo;
/**
* Reference to SolarSystemCanvas Canvas object at unity ui.
*/
public Canvas SolarSystemCanvas;
/**
* Reference to SolarSystemCanvas.BackButton Button object at unity ui.
*/
public Button BackButton;
/**
* Reference to InvisibleObjectsCanvas.GameView.GalaxyView.SolarSystemView SolarSystemViewSpawnerScript object at unity ui.
*/
public SolarSystemViewSpawnerScript SolarSystemViewSpawner;
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private values
/**
* References to PlanetViewBodies, which are instantiated if the player clicks on a planet.
*/
private NPlanetView.PlanetViewBody[] PlanetViewBodies;
/**
* References to PlanetMovement objects, which are instantiated if the player clicks on a planet.
* They handle the movement each for one planet.
*/
private NPlanet.PlanetMovement[] planetMovement;
/**
* References the GameModel. Is set at beginning of game by call of @see SetGameModel(GameModel oGameModel) from parent view InvisibleObjectsCanvas.GameView.GalaxyView.
*/
private GameModel oGameModel;
/**
* True -> solar system is visible and planets can be moved around.
* False -> solar system is invisible and planets can't be moved around.
*/
private bool bSolarSystemVisible = false;
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Unity Functions
/**
* Is called at start of game (if this object is instantiated).
* Adds the @see HideSolarSystem() function to the on click event listener of the BackButton.
*/
void Start()
{
BackButton.onClick.AddListener(() => HideSolarSystem());
}
/**
* Update is called once per frame.
* If one solar system is visible, moves the planets of the solar system around by changing their position in a specific intervall.
* @see NPlanet.PlanetMovement for details. Not connected to framerate, else planets would move slower or faster depending on fps.
*/
void Update()
{
if (bSolarSystemVisible == true)
{
foreach (NPlanet.PlanetMovement SingleplanetMovement in planetMovement)
{
SingleplanetMovement?.MovePlanet();
}
}
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public Functions
/**
* If the player clicks on a solar system, the planets of that single solar system have to be displayed.
* This function takes the id of the solar system clicked, fetches the data to that corresponding solar system from
* the model and calls the @see SolarSystemViewSpawner.SpawnPlanets(int iCountOfPlanets) function.
* After the declaration of the PlanetViewBodies, the function defines the values with the data fetched from the model.
*
* @param iSolarSystemID the id of the solar system clicked by the player.
*/
public void DisplaySolarSystem(int iSolarSystemID)
{
NPlanet.PlanetModel[] Planets = oGameModel.GalaxyModel.SolarSystemModels[iSolarSystemID].Planets;
int iCountOfPlanets = Planets.Length;
PlanetViewBodies = SolarSystemViewSpawner.SpawnPlanets(iCountOfPlanets);
for (int i = 0; i < iCountOfPlanets; i++)
{
PlanetViewBodies[i].PlanetSprite = Planets[i].PlanetSprite;
// Set SolarSystemCanvas to parent of instantiated planet prefabs, so they behave related to that canvas.
PlanetViewBodies[i].transform.SetParent(SolarSystemCanvas.transform, false);
PlanetViewBodies[i].transform.localScale = new Vector3(1, 1, 1);
// Set values related to movement on ui.
PlanetViewBodies[i].transform.position = Planets[i].Position;
PlanetViewBodies[i].RotationSpeed = Planets[i].RotationSpeed;
PlanetViewBodies[i].OrbitRadius = Planets[i].OrbitRadius;
PlanetViewBodies[i].OrbitAngle = Planets[i].OrbitAngle;
// If planets belongs to a player, set the color of the marker to the color of that player.
if (Planets[i].PlayerID >= 0)
{
PlanetViewBodies[i].PlayerMarkerColor = oGameModel.PlayerModel.GetPlayerColors()[Planets[i].PlayerID];
}
// Else set the color of the marker to transparent, so the marker will be hidden.
// Color(r, g, b, a) a = alpha, if zero => transparent
else
{
PlanetViewBodies[i].PlayerMarkerColor = new Color(0, 0, 0, 0);
}
// On click on a planet, the planet info is displayed.
PlanetViewBodies[i].PlanetID = Planets[i].PlanetID;
int PlanetID = PlanetViewBodies[i].PlanetID;
PlanetViewBodies[i].onClick.AddListener(() => SetPlanetInfoActive());
PlanetViewBodies[i].onClick.AddListener(() => SetPlanetInfo(PlanetID));
}
// Calculate center of screen
Vector2 oCenterVector = new Vector2(Screen.width / 2, Screen.height / 2);
planetMovement = new NPlanet.PlanetMovement[iCountOfPlanets];
// Add PlanetViewBodies to the planet movement objects, which take care of the movement of the overhanded references on the ui.
for (int i = 0; i < iCountOfPlanets; i++)
{
planetMovement[i] = new NPlanet.PlanetMovement(PlanetViewBodies[i], oCenterVector);
}
// Set sprite of center to corresponding solar system sprite.
SolarSystemCanvas.transform.Find("Center").GetComponent<Image>().overrideSprite = oGameModel.GalaxyModel.SolarSystemModels[iSolarSystemID].SolarSystemSprite;
SolarSystemCanvas.transform.Find("Center").position = oCenterVector;
// Allow @see Update() of this gameobject, to access PlanetViewBodies.
bSolarSystemVisible = true;
}
/**
* Hides solar system, by destroying PlanetViewBodies.
*/
public void HideSolarSystem()
{
// Deny @see Update() of this gameobject, to access PlanetViewBodies.
// Because they will be destroyed afterwards.
bSolarSystemVisible = false;
PlanetInfo.SetActive(false);
// Destroy all PlanetViewBodies
for (int i = 0; i < PlanetViewBodies.Length; i++)
{
Transform childToDestroy = SolarSystemCanvas.transform.Find("PlanetViewBody(Clone)");
DestroyImmediate(childToDestroy.gameObject);
}
}
/**
* Sets game model of this view and it's children.
*/
public void SetGameModel(GameModel oGameModel)
{
// Set own game model
this.oGameModel = oGameModel;
// Set sub views game model
oPlanetView.SetGameModel(oGameModel);
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private Functions
/**
* Sets the info of one planet which was clicked, active.
*/
private void SetPlanetInfoActive()
{
PlanetInfo.SetActive(true);
}
/**
* Informs the planet info which planet was clicked.
*/
private void SetPlanetInfo(int iPlanetID)
{
oPlanetView.SetFocusedPlanet(iPlanetID);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6a5aad5657c746543b2ccd59ce121a90
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,57 @@
/**
* @file
*
* @author Mohamad Kadou
* @author Aaron Moser
*
* @package Assets.Scripts.Galaxy.SolarSystem.View
*/
using UnityEngine;
/**
* @section DESCRIPTION
*
* Class contains function to instantiate an overhanded number of PlanetViewBodyPrefabs.
*/
public class SolarSystemViewSpawnerScript : MonoBehaviour
{
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public values
/**
* Prefab to instantiate.
* From package Assets.PreFabs.Planet.
*/
public NPlanetView.PlanetViewBody PlanetViewBodyPrefab;
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private values
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Unity Functions
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Public Functions
/**
* Instantiates iCountOfPlanets PlanetViewBodies from the PlanetViewBodyPrefab and returns the array reference.
*
* @param iCountOfPlanets is the count of planets the solar system has and the count how many planets have to be spawned.
*
* @return PlanetViewBodies array reference.
*/
public NPlanetView.PlanetViewBody[] SpawnPlanets(int iCountOfPlanets)
{
NPlanetView.PlanetViewBody[] aoPlanetViewBodies = new NPlanetView.PlanetViewBody[iCountOfPlanets];
for (int i = 0; i < iCountOfPlanets; i++)
{
aoPlanetViewBodies[i] = Instantiate(PlanetViewBodyPrefab);
}
return aoPlanetViewBodies;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Private Functions
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c7f48c01fc215af40b1e31a3d11d49ce
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1cd3fdb91736f8547a27ceb7cd2f06ad
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,68 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GalaxyViewScript : MonoBehaviour
{
public SolarSystemViewScript oSolarSystemView;
public GameObject GalaxyCanvas;
public GameObject SolarSystemCanvas;
public Canvas GalaxyBodysCanvas;
public GalaxyViewSpawnerScript GalaxyViewSpawner;
private SolarSystemViewBody[] SolarSystemViewBodies;
private GameModel oGameModel;
/// <summary>
/// Lets spawner instantiate solarsystemviewbodies.
/// </summary>
public void DisplaySolarSystems()
{
SolarSystemViewBodies = GalaxyViewSpawner.SpawnSolarSystems(oGameModel.GalaxyModel.SolarSystemCount);
for (int i = 0; i < SolarSystemViewBodies.Length; i++)
{
SolarSystemViewBodies[i].SolarSystemSprite = oGameModel.GalaxyModel.SolarSystemModels[i].SolarSystemSprite;
SolarSystemViewBodies[i].transform.SetParent(GalaxyBodysCanvas.transform, false);
SolarSystemViewBodies[i].transform.position = oGameModel.GalaxyModel.SolarSystemModels[i].Position;
SolarSystemViewBodies[i].transform.localScale = new Vector3(1, 1, 1);
SolarSystemViewBodies[i].ID = oGameModel.GalaxyModel.SolarSystemModels[i].SolarSystemID;
int ID = SolarSystemViewBodies[i].ID;
SolarSystemViewBodies[i].onClick.AddListener(() => DisplaySolarSystem(ID));
SolarSystemViewBodies[i].onClick.AddListener(() => SetSolarSystemCanvasActive());
SolarSystemViewBodies[i].onClick.AddListener(() => SetGalaxyCanvasInactive());
}
}
private void SetSolarSystemCanvasActive()
{
SolarSystemCanvas.SetActive(true);
}
private void SetGalaxyCanvasInactive()
{
GalaxyCanvas.SetActive(false);
}
private void DisplaySolarSystem(int iSolarSystemID)
{
NSolarSystem.SolarSystemController.SolarSystemPressedEvent(this, new NSolarSystem.SolarSystemEventArgs(ESolarSystemEvent.SolarSystemClicked, iSolarSystemID));
}
public void SetGameModel(GameModel oGameModel)
{
// Set own game model
this.oGameModel = oGameModel;
// Set sub views game model
oSolarSystemView.SetGameModel(oGameModel);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 986e59cebe2a8974ea09dedf66c5d15f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GalaxyViewSpawnerScript : MonoBehaviour
{
/// <summary>
/// Prefab to instantiate.
/// </summary>
public SolarSystemViewBody SolarSystemViewBodyPrefab;
/// <summary>
/// Instantiates iCountOfSolarSystems PlanetViewBodies and returns the array reference.
/// </summary>
/// <param name="iCountOfSolarSystems"></param>
/// <returns></returns>
public SolarSystemViewBody[] SpawnSolarSystems(int iCountOfSolarSystems)
{
SolarSystemViewBody[] aoSolarSystemViewBodies = new SolarSystemViewBody[iCountOfSolarSystems];
for (int i = 0; i < iCountOfSolarSystems; i++)
{
aoSolarSystemViewBodies[i] = Instantiate(SolarSystemViewBodyPrefab);
}
return aoSolarSystemViewBodies;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 010da97f57e863d428428662cd41af2b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: af8c36fff6ac31a4f99a382dd2a1fee5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,122 @@
public class GameController
{
/// <summary>
/// Reference to Game Model. Set through Game Manager.
/// </summary>
private GameModel oGameModel;
/// <summary>
/// Reference to Game View. Set through Game Manager.
/// </summary>
private GameViewScript oGameView;
/// <summary>
/// Reference to Player Controller.
/// </summary>
public NPlayer.PlayerController oPlayerController;
/// <summary>
/// Reference to Research Queue Controller.
/// </summary>
public NResearchController.ResearchQueueController oResearchQueueController;
/// <summary>
/// Reference to Research Cost Controller.
/// </summary>
public NResearchController.ResearchCostController oResearchCostController;
/// <summary>
/// Reference to Research Tech Controller.
/// </summary>
public NResearchController.ResearchTechController oResearchTechController;
public NGalaxy.GalaxyController oGalaxyController;
public NSolarSystem.SolarSystemController oSolarSystemController;
public NPlanet.PlanetController oPlanetController;
/// <summary>
/// Boolean signals SimulateDay if everything is initiated.
/// </summary>
private bool bEverythingInitiated = false;
/// <summary>
/// Constructor of GameController class. Initializes all necessary parts of logic.
/// </summary>
/// <param name="oGameModel"></param>
/// <param name="oGameView"></param>
public GameController(GameModel oGameModel, GameViewScript oGameView)
{
this.oGameModel = oGameModel;
this.oGameView = oGameView;
InitViewModelRefs();
InitControllers();
// Allows to simulate day after initializing everything
bEverythingInitiated = true;
}
/// <summary>
/// Sets iterative through all views their model reference.
/// Parent views call their childs SetGameModel().
/// </summary>
private void InitViewModelRefs()
{
oGameView.SetGameModel(oGameModel);
}
/// <summary>
/// Initializes the controllers.
/// </summary>
private void InitControllers()
{
// Init player controller
this.oPlayerController = new NPlayer.PlayerController(this.oGameModel.PlayerModel);
// Init research related controllers
this.oResearchQueueController = new NResearchController.ResearchQueueController(oGameModel, oGameView.ResearchView.ResearchQueueView);
this.oResearchCostController = new NResearchController.ResearchCostController(oGameModel, oGameView.ResearchView.ResearchCostView);
this.oResearchTechController = new NResearchController.ResearchTechController(oGameModel, oGameView.ResearchView.ResearchQueueView);
// Init galaxy related controllers
this.oGalaxyController = new NGalaxy.GalaxyController(oGameModel.GalaxyModel, oGameView.GalaxyView);
this.oSolarSystemController = new NSolarSystem.SolarSystemController(oGameModel.GalaxyModel.SolarSystemModels, oGameView.GalaxyView.oSolarSystemView);
this.oPlanetController = new NPlanet.PlanetController(oGameModel.GalaxyModel.SolarSystemModels, oGameView.GalaxyView.oSolarSystemView.oPlanetView);
}
/// <summary>
/// Every n seconds called from GameManager.
/// Simulates a day of the game and updates all models and views by executing child controllers code.
/// </summary>
public void SimulateDay()
{
if (bEverythingInitiated == true)
{
oResearchQueueController.SimulateDay();
SimulateDayPlayerModel();
oGameView.DailyUpdateView();
}
}
private void SimulateDayPlayerModel()
{
PlayerManager[] oPlayerManagers = oGameModel.PlayerModel.GetPlayerManagers();
for (int i = 0; i < oPlayerManagers.Length; i++)
{
oPlayerManagers[i].PlayerAttributes.Resous.Money += (oGameModel.GalaxyModel.GetMoneyOfSolarSystems(i) * oPlayerManagers[i].ResearchModel.Techs.WealthTech.Level);
oPlayerManagers[i].PlayerAttributes.Resous.Science += (oGameModel.GalaxyModel.GetScienceOfSolarSystems(i) * oPlayerManagers[i].ResearchModel.Techs.ScienceTech.Level);
oPlayerManagers[i].PlayerAttributes.Resous.Power = oGameModel.GalaxyModel.GetPowerOfSolarSystems(i);
oPlayerManagers[i].PlayerAttributes.Resous.Food = oGameModel.GalaxyModel.GetFoodOfSolarSystems(i, oPlayerManagers[i].ResearchModel.Techs.FoodTech.Level);
oPlayerManagers[i].PlayerAttributes.Resous.IndustrialCapacity += (oGameModel.GalaxyModel.GetIndustrialCapacityOfSolarSystems(i) * oPlayerManagers[i].ResearchModel.Techs.IndustrialCapacityTech.Level);
oPlayerManagers[i].PlayerAttributes.Resous.Population = oGameModel.GalaxyModel.GetPopulationOfSolarSystems(i);
oPlayerManagers[i].PlayerAttributes.Resous.ActualFood += oGameModel.GalaxyModel.GetActualFoodOfSolarSystems(i);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5ce6c2c053f8b5942a09a1d716f97a3d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
using UnityEngine;
public class GameManager : MonoBehaviour
{
// Clock which counts seconds until new day and updates playerManagers at new day
public Clock oClock;
public GameViewScript oGameView;
public GameModel oGameModel;
public GameController oGameController;
// Start is called before the first frame update
void Start()
{
oClock.GameManager = this;
oGameModel = new GameModel();
oGameController = new GameController(oGameModel, oGameView);
}
// Updates game
public void UpdateGame()
{
oGameController.SimulateDay();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d3b0135fe7978d64aa5acd5b3b207b35
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
public class GameModel
{
public NPlayer.PlayerModel PlayerModel { get; set; }
public NGalaxy.GalaxyModel GalaxyModel { get; set; }
public GameModel()
{
InitModels();
}
private void InitModels()
{
PlayerModel = new NPlayer.PlayerModel();
GalaxyModel = new NGalaxy.GalaxyModel();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 971d3a4a11d1c4447ab0612431a966d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameViewScript : MonoBehaviour
{
public ResearchViewScript ResearchView;
public GalaxyViewScript GalaxyView;
public ResourceViewScript ResourceView;
private GameModel GameModel;
public void SetGameModel(GameModel oGameModel)
{
// Set own game model
this.GameModel = oGameModel;
// Set sub views game model
ResearchView.SetGameModel(oGameModel);
GalaxyView.SetGameModel(oGameModel);
ResourceView.SetGameModel(oGameModel);
}
public void DailyUpdateView()
{
ResearchView.DailyUpdateView();
ResourceView.DailyUpdateView();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c0aac1ed212b74a4f9ede5cb521a7c39
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e6da461d1d37e264a9cf2ba5afa9697b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,4 @@
public interface IUpdateableView
{
public void UpdateView();
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a35e4fd8b53a5d84598de6f49db0c4ab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 99bac0a84088d3f40b4d7dcf03379127
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More