Game scripts commented
This commit is contained in:
61
Space4x/Assets/Scripts/Game/Clock.cs
Normal file
61
Space4x/Assets/Scripts/Game/Clock.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Space4x/Assets/Scripts/Game/Clock.cs.meta
Normal file
11
Space4x/Assets/Scripts/Game/Clock.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0128bb3b379e8144eae3b33ceb9c4bfd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference to Game Model. Set through Game Manager.
|
||||
/// </summary>
|
||||
private GameModel oGameModel;
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Public values
|
||||
|
||||
/// <summary>
|
||||
/// Reference to Game View. Set through Game Manager.
|
||||
/// </summary>
|
||||
private GameViewScript oGameView;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to Player Controller.
|
||||
/// </summary>
|
||||
/**
|
||||
* Reference to Player Controller.
|
||||
*/
|
||||
public NPlayer.PlayerController oPlayerController;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to Research Queue Controller.
|
||||
/// </summary>
|
||||
/**
|
||||
* Reference to Research Queue Controller.
|
||||
*/
|
||||
public NResearchController.ResearchQueueController oResearchQueueController;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to Research Cost Controller.
|
||||
/// </summary>
|
||||
/**
|
||||
* Reference to Research Cost Controller.
|
||||
*/
|
||||
public NResearchController.ResearchCostController oResearchCostController;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to Research Tech Controller.
|
||||
/// </summary>
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/// <summary>
|
||||
/// Boolean signals SimulateDay if everything is initiated.
|
||||
/// </summary>
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// 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;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor of GameController class. Initializes all necessary parts of logic.
|
||||
/// </summary>
|
||||
/// <param name="oGameModel"></param>
|
||||
/// <param name="oGameView"></param>
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets iterative through all views their model reference.
|
||||
/// Parent views call their childs SetGameModel().
|
||||
/// </summary>
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the controllers.
|
||||
/// </summary>
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/// <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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from @see SimulateDay().
|
||||
* Simulates day for each player, updating their values.
|
||||
*/
|
||||
private void SimulateDayPlayerModel()
|
||||
{
|
||||
PlayerManager[] oPlayerManagers = oGameModel.PlayerModel.GetPlayerManagers();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user