More betterer Time tracking and basic Win/Lose check

This commit is contained in:
Simon Lübeß
2024-04-04 22:57:07 +02:00
parent 1d7a3d5870
commit 93db8ae9e5
10 changed files with 1414 additions and 27 deletions

View File

@ -1,14 +1,16 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using Utility;
public class GameManager : MonoBehaviourSingleton<GameManager>
public partial class GameManager : MonoBehaviourSingleton<GameManager>
{
[SerializeField] private Difficulty _difficulty = Difficulty.Medium;
[SerializeField]
private double _baseGameDurationSeconds = 10.0 * 60.0;
private double _totalGameDurationSeconds;
[SerializeField]
private double _remainingGameDurationSeconds = 0.0;
@ -22,10 +24,12 @@ public class GameManager : MonoBehaviourSingleton<GameManager>
[SerializeField]
private MultiFalsableBool _gameRunning = new(false);
public Difficulty Difficulty => _difficulty;
/// <summary>
/// Wie weit das Spiel bereits fortgeschritten ist.
/// </summary>
public double GameProgress => 1.0 - (_remainingGameDurationSeconds / _baseGameDurationSeconds);
public double GameProgress => 1.0 - (_remainingGameDurationSeconds / _totalGameDurationSeconds);
/// <summary>
/// Wie Effizient das Team derzeit arbeitet.
@ -51,8 +55,12 @@ public class GameManager : MonoBehaviourSingleton<GameManager>
[ContextMenu("Start Game")]
private void StartGame()
{
_remainingGameDurationSeconds = _baseGameDurationSeconds;
TimeManager.Instance.Init();
_totalGameDurationSeconds = TimeManager.Instance.CalculateActualDeveloperTime(_difficulty);
_remainingGameDurationSeconds = _totalGameDurationSeconds;
ResumeGame();
}
@ -84,8 +92,41 @@ public class GameManager : MonoBehaviourSingleton<GameManager>
{
UpdateEfficiency();
UpdateGameDuration();
CheckGameEndConditions();
}
private void CheckGameEndConditions()
{
if (_remainingGameDurationSeconds <= 0.0)
{
EndGame(EndGameCondition.Win_GamePublished);
}
else if (_developers.Count == 0)
{
EndGame(EndGameCondition.Lose_NoDevelopersLeft);
}
else if (TimeManager.Instance.MissedDeadline)
{
EndGame(EndGameCondition.Lose_DeadlineMissed);
}
}
private void EndGame(EndGameCondition endGameCondition)
{
if (endGameCondition.IsWin())
{
Debug.Log("You won!");
}
else if (endGameCondition.IsLose())
{
Debug.Log("You lost!");
}
Debug.Log(endGameCondition.GetEndGameMessage());
PauseGame();
}
void UpdateEfficiency()
{
double developerEfficiency = 0.0f;