diff --git a/Space4x/Assets/Scripts/Game/Clock.cs b/Space4x/Assets/Scripts/Game/Clock.cs new file mode 100644 index 0000000..4db16ee --- /dev/null +++ b/Space4x/Assets/Scripts/Game/Clock.cs @@ -0,0 +1,61 @@ +/** + * @file + * + * @author Aaron Moser + * + * @package Assets.Scripts.Game + */ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/** + * @section DESCRIPTION + * + * Class contains functionality to simulate a day after n seconds. + */ +public class Clock : MonoBehaviour +{ + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Public values + + /** + * Array of references to player managers. + */ + public GameManager GameManager { private get; set; } + + /** + * Length of a game day in seconds. + */ + public float DayTime = 10.0f; + + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Private values + + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Public functions + + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Private functions + + /** + * Start is called before the first frame update. + * Sets up environment that @seeCallUpdateGame() is called every DayTime seconds. + */ + void Start() + { + // CallUpdateGame will be called once each DayTime seconds + InvokeRepeating("CallUpdateGame", 0.0f, DayTime); + } + + /** + * Calls update game of game manager. + */ + private void CallUpdateGame() + { + if (GameManager != null) + { + GameManager.UpdateGame(); + } + } +} diff --git a/Space4x/Assets/Scripts/Game/Clock.cs.meta b/Space4x/Assets/Scripts/Game/Clock.cs.meta new file mode 100644 index 0000000..e05a25c --- /dev/null +++ b/Space4x/Assets/Scripts/Game/Clock.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0128bb3b379e8144eae3b33ceb9c4bfd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Space4x/Assets/Scripts/Game/GameController.cs b/Space4x/Assets/Scripts/Game/GameController.cs index cf26c05..494c7a7 100644 --- a/Space4x/Assets/Scripts/Game/GameController.cs +++ b/Space4x/Assets/Scripts/Game/GameController.cs @@ -1,51 +1,86 @@ +/** + * @file + * + * @author Aaron Moser + * + * @package Assets.Scripts.Game.Controller + */ + +/** + * @section DESCRIPTION + * + * Class containing all controllers. + * + * @todo should care about communication between controllers and models through interfaces. + */ public class GameController { - /// - /// Reference to Game Model. Set through Game Manager. - /// - private GameModel oGameModel; + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Public values - /// - /// Reference to Game View. Set through Game Manager. - /// - private GameViewScript oGameView; - - /// - /// Reference to Player Controller. - /// + /** + * Reference to Player Controller. + */ public NPlayer.PlayerController oPlayerController; - /// - /// Reference to Research Queue Controller. - /// + /** + * Reference to Research Queue Controller. + */ public NResearchController.ResearchQueueController oResearchQueueController; - /// - /// Reference to Research Cost Controller. - /// + /** + * Reference to Research Cost Controller. + */ public NResearchController.ResearchCostController oResearchCostController; - /// - /// Reference to Research Tech Controller. - /// + /** + * Reference to Research Tech Controller. + */ public NResearchController.ResearchTechController oResearchTechController; + + /** + * Reference to Galaxy Controller. + */ public NGalaxy.GalaxyController oGalaxyController; + /** + * Reference to Solar System Controller. + */ public NSolarSystem.SolarSystemController oSolarSystemController; + /** + * Reference to Planet Controller. + */ public NPlanet.PlanetController oPlanetController; - /// - /// Boolean signals SimulateDay if everything is initiated. - /// + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Private values + + /** + * Reference to Game Model. Set through Game Manager. + */ + private GameModel oGameModel; + + /** + * Reference to Game View. Set through Game Manager. + */ + private GameViewScript oGameView; + + /** + * Boolean signals SimulateDay if everything is initiated. + */ private bool bEverythingInitiated = false; - /// - /// Constructor of GameController class. Initializes all necessary parts of logic. - /// - /// - /// + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Public functions + + /** + * Constructor of GameController class. Initializes all necessary parts of logic. + * + * @param oGameModel, reference to game model. + * @param oGameView, reference to game view. + */ public GameController(GameModel oGameModel, GameViewScript oGameView) { this.oGameModel = oGameModel; @@ -60,18 +95,37 @@ public class GameController bEverythingInitiated = true; } - /// - /// Sets iterative through all views their model reference. - /// Parent views call their childs SetGameModel(). - /// + /** + * Every n seconds called from GameManager. + * Simulates a day of the game and updates all models and views by executing child controllers code. + */ + public void SimulateDay() + { + if (bEverythingInitiated == true) + { + oResearchQueueController.SimulateDay(); + + SimulateDayPlayerModel(); + + oGameView.DailyUpdateView(); + } + } + + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Private functions + + /** + * Sets iterative through all views their model reference. + * Parent views call their childs SetGameModel(). + */ private void InitViewModelRefs() { oGameView.SetGameModel(oGameModel); } - /// - /// Initializes the controllers. - /// + /** + * Initializes the controllers. + */ private void InitControllers() { // Init player controller @@ -88,22 +142,10 @@ public class GameController this.oPlanetController = new NPlanet.PlanetController(oGameModel.GalaxyModel.SolarSystemModels, oGameView.GalaxyView.oSolarSystemView.oPlanetView); } - /// - /// Every n seconds called from GameManager. - /// Simulates a day of the game and updates all models and views by executing child controllers code. - /// - public void SimulateDay() - { - if (bEverythingInitiated == true) - { - oResearchQueueController.SimulateDay(); - - SimulateDayPlayerModel(); - - oGameView.DailyUpdateView(); - } - } - + /** + * Called from @see SimulateDay(). + * Simulates day for each player, updating their values. + */ private void SimulateDayPlayerModel() { PlayerManager[] oPlayerManagers = oGameModel.PlayerModel.GetPlayerManagers(); diff --git a/Space4x/Assets/Scripts/Game/GameManager.cs b/Space4x/Assets/Scripts/Game/GameManager.cs index 920f058..14137bb 100644 --- a/Space4x/Assets/Scripts/Game/GameManager.cs +++ b/Space4x/Assets/Scripts/Game/GameManager.cs @@ -1,17 +1,70 @@ +/** + * @file + * + * @author Aaron Moser + * + * @package Assets.Scripts.Game + */ using UnityEngine; +/** + * @section DESCRIPTION + * + * Class administrates top level of game. + */ public class GameManager : MonoBehaviour { - // Clock which counts seconds until new day and updates playerManagers at new day + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Public values + + // + + /** + * Clock reference, clock counts seconds until new day and calls @see UpdateGame() at new day + */ public Clock oClock; + /** + * Reference to game view. + * + * InvisibleObjectsCanvas.GameView + */ public GameViewScript oGameView; + /** + * Reference to game model. + */ public GameModel oGameModel; + /** + * Reference to game controller. + */ public GameController oGameController; - // Start is called before the first frame update + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Private values + + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Public functions + + /** + * Updates game by calling SimulateDay() of game controller. + */ + public void UpdateGame() + { + oGameController.SimulateDay(); + } + + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Private functions + + // + + /** + * Start is called before the first frame update. + * + * Sets clock, game model and game controller references. + */ void Start() { oClock.GameManager = this; @@ -21,9 +74,5 @@ public class GameManager : MonoBehaviour oGameController = new GameController(oGameModel, oGameView); } - // Updates game - public void UpdateGame() - { - oGameController.SimulateDay(); - } + } diff --git a/Space4x/Assets/Scripts/Game/GameModel.cs b/Space4x/Assets/Scripts/Game/GameModel.cs index e4f408a..2e7a73f 100644 --- a/Space4x/Assets/Scripts/Game/GameModel.cs +++ b/Space4x/Assets/Scripts/Game/GameModel.cs @@ -1,14 +1,51 @@ +/** + * @file + * + * @author Aaron Moser + * + * @package Assets.Scripts.Game.Model + */ + +/** + * @section DESCRIPTION + * + * Class contains model of game. + */ public class GameModel { + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Public values + + /** + * Reference to player model. + */ public NPlayer.PlayerModel PlayerModel { get; set; } + /** + * Reference to galaxy model. + */ public NGalaxy.GalaxyModel GalaxyModel { get; set; } + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Private values + + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Public functions + + /** + * Calls @see InitModels(). + */ public GameModel() { InitModels(); } + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Private functions + + /** + * Instantiates player and galaxy model. + */ private void InitModels() { PlayerModel = new NPlayer.PlayerModel(); diff --git a/Space4x/Assets/Scripts/Game/GameViewScript.cs b/Space4x/Assets/Scripts/Game/GameViewScript.cs index b141555..b6213fd 100644 --- a/Space4x/Assets/Scripts/Game/GameViewScript.cs +++ b/Space4x/Assets/Scripts/Game/GameViewScript.cs @@ -1,17 +1,61 @@ +/** + * @file + * + * @author Aaron Moser + * + * @package Assets.Scripts.Game.View + */ using System.Collections; using System.Collections.Generic; using UnityEngine; +/** + * @section DESCRIPTION + * + * Class contains game view related functionality. + */ public class GameViewScript : MonoBehaviour { + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Public values + + /** + * Reference to research view. + * + * InvisibleObjectsCanvas.GameView.ResearchView + */ public ResearchViewScript ResearchView; + /** + * Reference to galaxy view. + * + * InvisibleObjectsCanvas.GameView.GalaxyView + */ public GalaxyViewScript GalaxyView; + /** + * Reference to resource view. + * + * InvisibleObjectsCanvas.GameView.ResourceView + */ public ResourceViewScript ResourceView; + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Private values + + /** + * Reference to game model. + */ private GameModel GameModel; + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Public functions + + /** + * Sets reference of game model to oGameModel. + * + * @param oGameModel, reference to game model. + */ public void SetGameModel(GameModel oGameModel) { // Set own game model @@ -23,9 +67,15 @@ public class GameViewScript : MonoBehaviour ResourceView.SetGameModel(oGameModel); } + /** + * Updates views every day. + */ public void DailyUpdateView() { ResearchView.DailyUpdateView(); ResourceView.DailyUpdateView(); } + + //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // Private functions }