1.Commit
This commit is contained in:
30
Assets/Scripts/Clock.cs
Normal file
30
Assets/Scripts/Clock.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
88
Assets/Scripts/Fleet.cs
Normal file
88
Assets/Scripts/Fleet.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using UnityEngine;
|
||||
|
||||
public class Fleet : MonoBehaviour
|
||||
{
|
||||
public float TravelDistanceTotal = 0;
|
||||
public int TravelTimeTotal = 0;
|
||||
public string Name { get; set; }
|
||||
public GameObject CurrentLocation;
|
||||
public GameObject Destination;
|
||||
public List<Ship> Ships = new();
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
public int GetNumberOfShips()
|
||||
{
|
||||
return Ships.Count;
|
||||
}
|
||||
public int GetStrength()
|
||||
{
|
||||
int result = 0;
|
||||
foreach (Ship g in Ships)
|
||||
{
|
||||
result += g.Strength;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int GetSpeed()
|
||||
{
|
||||
int result = FleetManager.maxSpeed;
|
||||
foreach (Ship g in Ships)
|
||||
{
|
||||
if (g.Speed < result)
|
||||
{
|
||||
result = g.Speed;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public float GetTravelDistanceTotal()
|
||||
{
|
||||
float result = 0;
|
||||
Vector3 dest = Destination.transform.position;
|
||||
Vector3 curr = CurrentLocation.transform.position;
|
||||
Vector3 path = dest - curr;
|
||||
result = path.magnitude;
|
||||
return result;
|
||||
}
|
||||
|
||||
public int GetTravelTimeTotal()
|
||||
{
|
||||
int result = 0;
|
||||
result = (int) (this.TravelDistanceTotal / this.GetSpeed());
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SetDestination(GameObject destStarSystem)
|
||||
{
|
||||
if(this.CurrentLocation == destStarSystem)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.Destination = destStarSystem;
|
||||
this.TravelDistanceTotal = GetTravelDistanceTotal();
|
||||
this.TravelTimeTotal = GetTravelTimeTotal();
|
||||
//TODO: make fleet invisible
|
||||
}
|
||||
public void Travel()
|
||||
{
|
||||
this.TravelTimeTotal--;
|
||||
if (this.TravelTimeTotal == 0) //fleet arrived
|
||||
{
|
||||
//TODO put fleet into ui of destination Star System
|
||||
this.CurrentLocation = this.Destination;
|
||||
}
|
||||
}
|
||||
}
|
||||
40
Assets/Scripts/FleetManager.cs
Normal file
40
Assets/Scripts/FleetManager.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FleetManager : MonoBehaviour
|
||||
{
|
||||
|
||||
public static int maxSpeed = 10000;
|
||||
public List<Fleet> Fleets = new();
|
||||
public Fleet selectedFleet;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
}
|
||||
|
||||
public void UpdateFleetsList()
|
||||
{
|
||||
for (int i = 0; i < Fleets.Count; i++)
|
||||
{
|
||||
if (Fleets[i] ==null || !Fleets[i].isActiveAndEnabled)
|
||||
{
|
||||
Fleets.Remove(Fleets[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void UpdateTravelTime()
|
||||
{
|
||||
foreach (Fleet g in Fleets)
|
||||
{
|
||||
g.Travel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
55
Assets/Scripts/GameManager.cs
Normal file
55
Assets/Scripts/GameManager.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
// Array will contain objects which contain all information about all players
|
||||
public PlayerManager[] playerManagers { get; private set; }
|
||||
|
||||
// Clock which counts seconds until new day and updates playerManagers at new day
|
||||
public Clock clock;
|
||||
|
||||
public ScienceManager sm;
|
||||
|
||||
public int numberOfPlayers { get; set; }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
DontDestroyOnLoad(this.gameObject);
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
initPlayerManagers(1);
|
||||
clock.gameManager = this;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){}
|
||||
|
||||
// Initializes numberOfPlayers player managers and puts them into array
|
||||
public void initPlayerManagers(int numberOfPlayers)
|
||||
{
|
||||
this.playerManagers = new PlayerManager[numberOfPlayers];
|
||||
for (int i = 0; i < numberOfPlayers; i++)
|
||||
{
|
||||
this.playerManagers[i] = new PlayerManager(sm);
|
||||
}
|
||||
}
|
||||
|
||||
// Updates game
|
||||
public void updateGame()
|
||||
{
|
||||
if (playerManagers != null)
|
||||
{
|
||||
// Simulate day for each player
|
||||
foreach (var playerManager in playerManagers)
|
||||
{
|
||||
playerManager.simulateDay();
|
||||
}
|
||||
}
|
||||
// TODO update view, do we need to update view?
|
||||
}
|
||||
}
|
||||
94
Assets/Scripts/PlayerManager.cs
Normal file
94
Assets/Scripts/PlayerManager.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class PlayerManager
|
||||
{
|
||||
// Contains all star systems of player
|
||||
//private List<GameObject> starSystems = new List<GameObject>();
|
||||
|
||||
// Contains all fleets of player
|
||||
//private List<GameObject> fleets = new List<GameObject>();
|
||||
|
||||
private ScienceManager _scienceManager;
|
||||
|
||||
public int ScienceAcumulated; // this int has to be moved to player manager later
|
||||
|
||||
public enum PlayerColor
|
||||
{
|
||||
None,
|
||||
Red,
|
||||
Blue,
|
||||
Green,
|
||||
Yellow
|
||||
}
|
||||
|
||||
public PlayerColor PlayerColor2
|
||||
{
|
||||
get
|
||||
{
|
||||
return _playerColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
_playerColor = value;
|
||||
}
|
||||
}
|
||||
|
||||
private PlayerColor _playerColor;
|
||||
|
||||
|
||||
// Player values
|
||||
public PlayerValues PlayerAttributes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_playerAttributes == null)
|
||||
{
|
||||
_playerAttributes = new PlayerValues();
|
||||
}
|
||||
return new PlayerValues();
|
||||
}
|
||||
set
|
||||
{
|
||||
_playerAttributes = value;
|
||||
}
|
||||
}
|
||||
|
||||
private PlayerValues _playerAttributes;
|
||||
|
||||
public PlayerManager(ScienceManager sm)
|
||||
{
|
||||
this._scienceManager = sm;
|
||||
this._playerAttributes = new PlayerValues();
|
||||
}
|
||||
|
||||
// Called by clock over game manager, once per day
|
||||
public void simulateDay()
|
||||
{
|
||||
//if (starSystems != null)
|
||||
//{
|
||||
// Add resources for each part of each starSystem which belongs to this player
|
||||
//foreach (var starSystem in starSystems)
|
||||
//{
|
||||
// int playerID = this._playerAttributes.id;
|
||||
// // StarSystem.getComponent<Script>().getMoney();
|
||||
// this._playerAttributes.money += (1 + ScienceManager.repeatableWealth) * ((StarSystem)starSystem).getMoney(playerID);
|
||||
|
||||
// this._playerAttributes.science += ((StarSystem)starSystem).getScience(playerID);
|
||||
// this._playerAttributes.power += ((StarSystem)starSystem).getPower(playerID);
|
||||
// this._playerAttributes.food += ((StarSystem)starSystem).getFood(playerID);
|
||||
// this._playerAttributes.industrialCapacity += ((StarSystem)starSystem).getIC(playerID);
|
||||
this._playerAttributes.science += 5;
|
||||
_scienceManager.UpdateScience(this._playerAttributes.science);
|
||||
this._playerAttributes.science = _scienceManager.PublicScienceAcumulated;
|
||||
//}
|
||||
//}
|
||||
}
|
||||
|
||||
// Deletes overhanded referrence from fleets list
|
||||
// If not null
|
||||
//public void deleteFleet(ref GameObject fleet)
|
||||
//{
|
||||
// this.fleets.Remove(fleet);
|
||||
//}
|
||||
}
|
||||
36
Assets/Scripts/PlayerValues.cs
Normal file
36
Assets/Scripts/PlayerValues.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
public class PlayerValues
|
||||
{
|
||||
// Player id
|
||||
public int id { get; set; }
|
||||
|
||||
// Player values
|
||||
public int money { get; set; }
|
||||
public int science { get; set; }
|
||||
public int power { get; set; }
|
||||
public int food { get; set; }
|
||||
public int industrialCapacity { get; set; }
|
||||
|
||||
// Default constructor
|
||||
public PlayerValues()
|
||||
{
|
||||
this.id = 0;
|
||||
|
||||
this.money = 0;
|
||||
this.science = 0;
|
||||
this.power = 0;
|
||||
this.food = 0;
|
||||
this.industrialCapacity = 0;
|
||||
}
|
||||
|
||||
// Constructor to init values
|
||||
public PlayerValues(int id, int newMoney, int newScience, int newPower, int newFood, int newIC)
|
||||
{
|
||||
this.id = id;
|
||||
|
||||
this.money = newMoney;
|
||||
this.science = newScience;
|
||||
this.power = newPower;
|
||||
this.food = newFood;
|
||||
this.industrialCapacity = newIC;
|
||||
}
|
||||
}
|
||||
239
Assets/Scripts/ScienceManager.cs
Normal file
239
Assets/Scripts/ScienceManager.cs
Normal file
@@ -0,0 +1,239 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Reflection.Emit;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
public class ScienceManager : MonoBehaviour
|
||||
{
|
||||
public int ScienceCostCurrentTech;
|
||||
public GameObject ScienceUI;
|
||||
public Text AccScienceLabel;
|
||||
|
||||
public static int TechnologiesTotal = 4;
|
||||
public Tech[] techs = new Tech[TechnologiesTotal];
|
||||
|
||||
|
||||
public Text CostText;
|
||||
public Text[] TechQueueUIArr = new Text[4];
|
||||
public Text[] TechLevelLabels = new Text[4];
|
||||
|
||||
public List<Tech> TechQueue = new();
|
||||
public int Amount = 0;
|
||||
|
||||
private int ScienceAcumulated = 0;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
techs[0] = new Tech(1,1, "IndustryTech");
|
||||
techs[1] = new Tech(1,1, "WealthTech");
|
||||
techs[2] = new Tech(1,1, "ScienceTech");
|
||||
techs[3] = new Tech(1,1, "FoodTech");
|
||||
UpdateScience(0);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Amount = techs.Length ;
|
||||
}
|
||||
/// <summary>
|
||||
/// blend in/out science window
|
||||
/// </summary>
|
||||
public void SwitchScienceUI()
|
||||
{
|
||||
if (ScienceUI.activeInHierarchy == true)
|
||||
{
|
||||
ScienceUI.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ScienceUI.SetActive(true);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// increase tech level
|
||||
/// reduce acumulated Science
|
||||
/// remove Tech from TechQueue
|
||||
/// </summary>
|
||||
public void UpdateScience(int actualScience)
|
||||
{
|
||||
this.ScienceAcumulated = actualScience;
|
||||
if ( this.TechQueue.Count > 0 )
|
||||
{
|
||||
ScienceCostCurrentTech = this.CalcScienceCost(this.TechQueue[0]);
|
||||
if (ScienceCostCurrentTech <= this.ScienceAcumulated)
|
||||
{
|
||||
for (int i = 0; i < this.techs.Length; i++)
|
||||
{
|
||||
if (String.Equals(TechQueue[0].Name, techs[i].Name))
|
||||
{
|
||||
techs[i].Level++;
|
||||
}
|
||||
}
|
||||
this.ScienceAcumulated -= ScienceCostCurrentTech;
|
||||
this.RemoveTechFromQueue(true);
|
||||
Debug.Log("TechQueue Count: " + TechQueue.Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Nicht genug Science Punkte");
|
||||
}
|
||||
}
|
||||
UpdateScienceUI();
|
||||
}
|
||||
|
||||
public int PublicScienceAcumulated => this.ScienceAcumulated;
|
||||
|
||||
/// <summary>
|
||||
/// calculates the cost of next level of tech based on base cost and level
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <returns></returns>
|
||||
public int CalcScienceCost(Tech t)
|
||||
{
|
||||
int lvl = t.Level;
|
||||
int result = (lvl * lvl )* t.Cost;
|
||||
//Debug.Log("Cost:" + result);
|
||||
ScienceCostCurrentTech = result;
|
||||
Debug.Log("Result: " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// calculates the cost of next level of tech based on base cost and level
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <returns></returns>
|
||||
public int CalcScienceCost(Tech t, int InQueue)
|
||||
{
|
||||
int lvl = t.Level + InQueue;
|
||||
int result = (lvl * lvl) * t.Cost;
|
||||
//Debug.Log("Cost:" + result);
|
||||
ScienceCostCurrentTech = result;
|
||||
Debug.Log("Result: " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public void AddToQueue(String name)
|
||||
{
|
||||
|
||||
//safequard agains queue overlfow
|
||||
if (TechQueue.Count >= 4)
|
||||
{
|
||||
Debug.Log("Queue full");
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < this.techs.Length; i++)
|
||||
{
|
||||
|
||||
if (String.Equals(name, techs[i].Name))
|
||||
{
|
||||
Debug.Log("i: " + i);
|
||||
TechQueue.Add(this.techs[i]);
|
||||
}
|
||||
}
|
||||
UpdateScienceUI();
|
||||
Debug.Log("TechQueue.Count: " + TechQueue.Count);
|
||||
}
|
||||
/// <summary>
|
||||
/// first=true is first element, first=false is last index
|
||||
/// </summary>
|
||||
/// <param name="first"></param>
|
||||
public void RemoveTechFromQueue(bool first)
|
||||
{
|
||||
//safeguard against TechQueue underflow
|
||||
if (TechQueue.Count < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (first == true)
|
||||
{
|
||||
//remove first
|
||||
TechQueue.RemoveAt(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
//remove last
|
||||
TechQueue.RemoveAt(TechQueue.Count-1);
|
||||
}
|
||||
UpdateScienceUI();
|
||||
}
|
||||
public void UpdateQueueText()
|
||||
{
|
||||
|
||||
//empty queue ui
|
||||
for (int i = 0; i < TechQueueUIArr.Length; i++)
|
||||
{
|
||||
TechQueueUIArr[i].text = "--";
|
||||
}
|
||||
// fill queue ui
|
||||
|
||||
for (int i = 0; i < TechQueue.Count ; i++)
|
||||
{
|
||||
Debug.Log("TechQueue.Count: " + TechQueue.Count);
|
||||
TechQueueUIArr[i].text = TechQueue[i].Name;
|
||||
}
|
||||
}
|
||||
public void UpdateScienceUI()
|
||||
{
|
||||
UpdateQueueText();
|
||||
AccScienceLabel.text = ScienceAcumulated.ToString();
|
||||
for (int i = 0; i < TechLevelLabels.Length; i++)
|
||||
{
|
||||
TechLevelLabels[i].text = techs[i].Level.ToString();
|
||||
}
|
||||
CostText.text = ScienceCostCurrentTech.ToString();
|
||||
}
|
||||
public void ResetPoints()
|
||||
{
|
||||
this.ScienceAcumulated += 20;
|
||||
UpdateScienceUI();
|
||||
}
|
||||
public void DisplayCostReset()
|
||||
{
|
||||
CostText.text = "0";
|
||||
}
|
||||
public void DisplayCost(String name)
|
||||
{
|
||||
int NumberOcc = 0;
|
||||
for (int i = 0; i < this.TechQueue.Count; i++)
|
||||
{
|
||||
if (String.Equals(TechQueue[i].Name, name))
|
||||
{
|
||||
NumberOcc++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.techs.Length; i++)
|
||||
{
|
||||
if (String.Equals(name, techs[i].Name))
|
||||
{
|
||||
CostText.text = CalcScienceCost(techs[i], NumberOcc).ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public class Tech
|
||||
{
|
||||
public int Cost;
|
||||
public int Level;
|
||||
public String Name;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="c"></param>
|
||||
/// <param name="l"></param>
|
||||
/// <param name="n"></param>
|
||||
public Tech(int c, int l, String n)
|
||||
{
|
||||
this.Cost = c;
|
||||
this.Level = l;
|
||||
this.Name = n;
|
||||
}
|
||||
}
|
||||
|
||||
20
Assets/Scripts/Ship.cs
Normal file
20
Assets/Scripts/Ship.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Ship : MonoBehaviour
|
||||
{
|
||||
public int Speed = 10;
|
||||
public int Strength = 1;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user