More betterer Time tracking and basic Win/Lose check
This commit is contained in:
parent
1d7a3d5870
commit
93db8ae9e5
File diff suppressed because it is too large
Load Diff
|
@ -1,14 +1,16 @@
|
||||||
using System;
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Utility;
|
using Utility;
|
||||||
|
|
||||||
public class GameManager : MonoBehaviourSingleton<GameManager>
|
public partial class GameManager : MonoBehaviourSingleton<GameManager>
|
||||||
{
|
{
|
||||||
|
[SerializeField] private Difficulty _difficulty = Difficulty.Medium;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private double _baseGameDurationSeconds = 10.0 * 60.0;
|
private double _totalGameDurationSeconds;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private double _remainingGameDurationSeconds = 0.0;
|
private double _remainingGameDurationSeconds = 0.0;
|
||||||
|
@ -22,10 +24,12 @@ public class GameManager : MonoBehaviourSingleton<GameManager>
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private MultiFalsableBool _gameRunning = new(false);
|
private MultiFalsableBool _gameRunning = new(false);
|
||||||
|
|
||||||
|
public Difficulty Difficulty => _difficulty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wie weit das Spiel bereits fortgeschritten ist.
|
/// Wie weit das Spiel bereits fortgeschritten ist.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double GameProgress => 1.0 - (_remainingGameDurationSeconds / _baseGameDurationSeconds);
|
public double GameProgress => 1.0 - (_remainingGameDurationSeconds / _totalGameDurationSeconds);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wie Effizient das Team derzeit arbeitet.
|
/// Wie Effizient das Team derzeit arbeitet.
|
||||||
|
@ -51,8 +55,12 @@ public class GameManager : MonoBehaviourSingleton<GameManager>
|
||||||
[ContextMenu("Start Game")]
|
[ContextMenu("Start Game")]
|
||||||
private void StartGame()
|
private void StartGame()
|
||||||
{
|
{
|
||||||
_remainingGameDurationSeconds = _baseGameDurationSeconds;
|
TimeManager.Instance.Init();
|
||||||
|
|
||||||
|
_totalGameDurationSeconds = TimeManager.Instance.CalculateActualDeveloperTime(_difficulty);
|
||||||
|
|
||||||
|
_remainingGameDurationSeconds = _totalGameDurationSeconds;
|
||||||
|
|
||||||
ResumeGame();
|
ResumeGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,8 +92,41 @@ public class GameManager : MonoBehaviourSingleton<GameManager>
|
||||||
{
|
{
|
||||||
UpdateEfficiency();
|
UpdateEfficiency();
|
||||||
UpdateGameDuration();
|
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()
|
void UpdateEfficiency()
|
||||||
{
|
{
|
||||||
double developerEfficiency = 0.0f;
|
double developerEfficiency = 0.0f;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Serialization;
|
||||||
using Utility;
|
using Utility;
|
||||||
|
|
||||||
public class TimeManager : MonoBehaviourSingleton<TimeManager>
|
public class TimeManager : MonoBehaviourSingleton<TimeManager>
|
||||||
|
@ -10,32 +11,61 @@ public class TimeManager : MonoBehaviourSingleton<TimeManager>
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private double _secondsPerDay = 48;
|
private double _secondsPerDay = 48;
|
||||||
|
|
||||||
[SerializeField]
|
[FormerlySerializedAs("_dayTime")] [SerializeField]
|
||||||
private double _dayTime = 0.0;
|
private double _totalTime = 0.0;
|
||||||
|
|
||||||
[SerializeField] private Light _sun;
|
[SerializeField] private Light _sun;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private Weekday _currentWeekday;
|
private Weekday _currentWeekday;
|
||||||
|
|
||||||
|
private DateTime _startDate;
|
||||||
|
private DateTime _deadline;
|
||||||
|
|
||||||
public int DaysLeft => _daysUntilRelease;
|
public int DaysLeft => _daysUntilRelease;
|
||||||
|
|
||||||
public double DayTime => _dayTime;
|
public Weekday CurrentWeekday => _currentWeekday;
|
||||||
|
|
||||||
public TimeSpan TimeOfDay
|
public TimeSpan TimeOfDay => CurrentDate.TimeOfDay;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
double hour = _dayTime * 24.0;
|
|
||||||
double minute = hour * 60;
|
|
||||||
double seconds = minute * 60;
|
|
||||||
|
|
||||||
return new TimeSpan((int)Math.Floor(hour), (int)Math.Floor(minute % 60), (int)Math.Floor(seconds % 60));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Das Datum zu dem das Spiel begonnen hat.
|
||||||
|
/// </summary>
|
||||||
|
public DateTime StartDate => _startDate;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Das aktuelle Datum und Uhrzeit im Spiel.
|
||||||
|
/// </summary>
|
||||||
|
public DateTime CurrentDate => _startDate.AddDays(_totalTime);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Die Deadline des Spiels.
|
||||||
|
/// </summary>
|
||||||
|
public DateTime Deadline => _deadline;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gibt true zurück, wenn die Deadline verpasst wurde.
|
||||||
|
/// </summary>
|
||||||
|
public bool MissedDeadline => CurrentDate > Deadline;
|
||||||
|
|
||||||
[SerializeField, ShowOnly]
|
[SerializeField, ShowOnly]
|
||||||
private string stringgy;
|
private string stringgy;
|
||||||
|
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
_startDate = new DateTime(2024, 4, 2, 12, 0, 0);
|
||||||
|
_deadline = _startDate.AddDays(_daysUntilRelease);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Berechnet die (real life) Sekunden, die die Entwickler bei 100% Effizienz benötigen um das Spiel bei gegebener Schwierigkeit zu entwickeln.
|
||||||
|
/// </summary>
|
||||||
|
public double CalculateActualDeveloperTime(Difficulty difficulty)
|
||||||
|
{
|
||||||
|
DifficultySettings settings = difficulty.GetSettings();
|
||||||
|
|
||||||
|
return _daysUntilRelease * _secondsPerDay / settings.DaysUntilReleaseFactor;
|
||||||
|
}
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
@ -48,11 +78,11 @@ public class TimeManager : MonoBehaviourSingleton<TimeManager>
|
||||||
|
|
||||||
void UpdateTime()
|
void UpdateTime()
|
||||||
{
|
{
|
||||||
_dayTime += Time.deltaTime / _secondsPerDay;
|
_totalTime += Time.deltaTime / _secondsPerDay;
|
||||||
|
|
||||||
if (_dayTime >= 1.0)
|
if (_totalTime >= 1.0)
|
||||||
{
|
{
|
||||||
_dayTime -= 1.0;
|
_totalTime -= 1.0;
|
||||||
_daysUntilRelease--;
|
_daysUntilRelease--;
|
||||||
_currentWeekday = _currentWeekday.GetNext();
|
_currentWeekday = _currentWeekday.GetNext();
|
||||||
}
|
}
|
||||||
|
@ -62,6 +92,8 @@ public class TimeManager : MonoBehaviourSingleton<TimeManager>
|
||||||
|
|
||||||
private void UpdateSun()
|
private void UpdateSun()
|
||||||
{
|
{
|
||||||
_sun.transform.rotation = Quaternion.Euler(new Vector3(Mathf.LerpAngle(-90, 60, (float)Math.Sin(_dayTime * Math.PI)), (float)(_dayTime * 360.0), 0));
|
float currentTime = (float)TimeOfDay.TotalDays;
|
||||||
|
|
||||||
|
_sun.transform.rotation = Quaternion.Euler(new Vector3(Mathf.LerpAngle(-90, 60, (float)Math.Sin(currentTime * Math.PI)), (float)(currentTime * 360.0), 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Utility
|
||||||
|
{
|
||||||
|
public enum Difficulty
|
||||||
|
{
|
||||||
|
Easy,
|
||||||
|
Medium,
|
||||||
|
Hard
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class DifficultySettings
|
||||||
|
{
|
||||||
|
public Difficulty Difficulty { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Faktor, wie viel mehr Zeit man halt als die Entwickler bei 100% effizienz benötigen.
|
||||||
|
/// </summary>
|
||||||
|
public double DaysUntilReleaseFactor { get; protected set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EasyDifficulty : DifficultySettings
|
||||||
|
{
|
||||||
|
public EasyDifficulty()
|
||||||
|
{
|
||||||
|
Difficulty = Difficulty.Easy;
|
||||||
|
DaysUntilReleaseFactor = 2.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MediumDifficulty : DifficultySettings
|
||||||
|
{
|
||||||
|
public MediumDifficulty()
|
||||||
|
{
|
||||||
|
Difficulty = Difficulty.Medium;
|
||||||
|
DaysUntilReleaseFactor = 1.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class HardDifficulty : DifficultySettings
|
||||||
|
{
|
||||||
|
public HardDifficulty()
|
||||||
|
{
|
||||||
|
Difficulty = Difficulty.Hard;
|
||||||
|
DaysUntilReleaseFactor = 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DifficultyExtensions
|
||||||
|
{
|
||||||
|
public static DifficultySettings GetSettings(this Difficulty difficulty) => difficulty switch
|
||||||
|
{
|
||||||
|
Difficulty.Easy => new EasyDifficulty(),
|
||||||
|
Difficulty.Medium => new MediumDifficulty(),
|
||||||
|
Difficulty.Hard => new HardDifficulty(),
|
||||||
|
_ => throw new ArgumentOutOfRangeException(nameof(difficulty), difficulty, null)
|
||||||
|
};
|
||||||
|
|
||||||
|
public static string GetName(this Difficulty difficulty) =>
|
||||||
|
difficulty switch
|
||||||
|
{
|
||||||
|
Difficulty.Easy => "Entspannt",
|
||||||
|
Difficulty.Medium => "Normal",
|
||||||
|
Difficulty.Hard => "Stressig",
|
||||||
|
_ => "Unbekannt"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9d5811ffae894b2ea0b1a25dbd30ec9f
|
||||||
|
timeCreated: 1712259095
|
|
@ -0,0 +1,33 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Utility
|
||||||
|
{
|
||||||
|
[Flags]
|
||||||
|
public enum EndGameCondition
|
||||||
|
{
|
||||||
|
Win = 0x01,
|
||||||
|
Lose = 0x02,
|
||||||
|
|
||||||
|
Win_GamePublished = Win | 0x04,
|
||||||
|
Lose_NoDevelopersLeft = Lose | 0x08,
|
||||||
|
Lose_DeadlineMissed = Lose | 0x10
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EndGameConditionExtension
|
||||||
|
{
|
||||||
|
public static bool IsWin(this EndGameCondition endGameCondition) =>
|
||||||
|
endGameCondition.HasFlag(EndGameCondition.Win);
|
||||||
|
|
||||||
|
public static bool IsLose(this EndGameCondition endGameCondition) =>
|
||||||
|
endGameCondition.HasFlag(EndGameCondition.Lose);
|
||||||
|
|
||||||
|
public static string GetEndGameMessage(this EndGameCondition endGameCondition) =>
|
||||||
|
endGameCondition switch
|
||||||
|
{
|
||||||
|
EndGameCondition.Win_GamePublished => "Dein Spiel wurde erfolgreich veröffentlicht!",
|
||||||
|
EndGameCondition.Lose_NoDevelopersLeft => "Oh nein, alle deine Entwickler sind weg!",
|
||||||
|
EndGameCondition.Lose_DeadlineMissed => "Oh nein, du hast die Deadline verpasst!",
|
||||||
|
_ => throw new ArgumentOutOfRangeException(nameof(endGameCondition), endGameCondition, null)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ad1840e1e170446a86caf0e316b19b54
|
||||||
|
timeCreated: 1712261399
|
|
@ -25,5 +25,20 @@
|
||||||
/// <param name="days">Die Anzahl an Tagen, die vergehen sollen.</param>
|
/// <param name="days">Die Anzahl an Tagen, die vergehen sollen.</param>
|
||||||
public static Weekday GetFutureDay(this Weekday current, int days) =>
|
public static Weekday GetFutureDay(this Weekday current, int days) =>
|
||||||
(Weekday)(((int)current + days) % 7);
|
(Weekday)(((int)current + days) % 7);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gibt den deutschen Namen des Wochentags zurück.
|
||||||
|
/// </summary>
|
||||||
|
public static string GetName(this Weekday weekday) => weekday switch
|
||||||
|
{
|
||||||
|
Weekday.Monday => "Montag",
|
||||||
|
Weekday.Tuesday => "Dienstag",
|
||||||
|
Weekday.Wednesday => "Mittwoch",
|
||||||
|
Weekday.Thursday => "Donnerstag",
|
||||||
|
Weekday.Friday => "Freitag",
|
||||||
|
Weekday.Saturday => "Samstag",
|
||||||
|
Weekday.Sunday => "Sonntag",
|
||||||
|
_ => "Unbekannt"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Serialization;
|
||||||
|
using Utility;
|
||||||
|
|
||||||
|
public class TerribleUiController : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField]
|
||||||
|
private TextMeshProUGUI _weekdayText;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private TextMeshProUGUI _dayTimeText;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private TextMeshProUGUI _progressText;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private TextMeshProUGUI _startDateText;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private TextMeshProUGUI _deadlineText;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private TextMeshProUGUI _currentDateText;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private TextMeshProUGUI _daysLeftText;
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
_weekdayText.text = TimeManager.Instance.CurrentWeekday.GetName();
|
||||||
|
_dayTimeText.text = $"Day Time: {TimeManager.Instance.TimeOfDay:h\\:mm\\:ss}";
|
||||||
|
_progressText.text = $"Progress: {(GameManager.Instance.GameProgress * 100.0):F3}%";
|
||||||
|
|
||||||
|
_startDateText.text = $"Start Date: {TimeManager.Instance.StartDate}";
|
||||||
|
_currentDateText.text = $"Current Date: {TimeManager.Instance.CurrentDate}";
|
||||||
|
_deadlineText.text = $"Deadline: {TimeManager.Instance.Deadline}";
|
||||||
|
|
||||||
|
_daysLeftText.text = $"Days left: {TimeManager.Instance.DaysLeft}";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7c4408689a1cdac4f86c298d6e6bae3a
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue