Commit 97452fe6 authored by Jonas's avatar Jonas

Score Calculation

parent 17f8d808
......@@ -14,12 +14,19 @@ namespace _Game.Scripts.GameManager {
public Color color;
public bool isWinner;
public void Reset(string name, Color color) {
public void Reset(string name, Color color, Role initRole) {
this.name = name;
score = 0f;
scoreLastRound = 0f;
this.color = color;
isWinner = false;
role = initRole;
Debug.Log("Player Reset aufgerufen");
}
public void UpdateScore(float scoreNew)
{
this.score += scoreNew;
}
}
......
......@@ -5,29 +5,35 @@ using UnityEngine;
using UnityEngine.InputSystem.Interactions;
using UnityEngine.SceneManagement;
namespace _Game.Scripts.GameManager {
public class GameHandler : SingletonMonobehaviour<GameHandler> {
namespace _Game.Scripts.GameManager
{
public class GameHandler : SingletonMonobehaviour<GameHandler>
{
[SerializeField] private GameData data;
[SerializeField] private Countdown startDelay;
[SerializeField] private Countdown roundTime;
[SerializeField] private Transform _handler1, _handler2;
private Transform _head, _body;
private void OnEnable() {
private void OnEnable()
{
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnDisable() {
private void OnDisable()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode) {
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
print("On Scene Loaded " + scene.ToString() + " Mode : " + mode.ToString());
SetReferences();
StartLogic();
}
private void SetReferences() {
private void SetReferences()
{
_head = GameObject.FindWithTag("HeadPlayer").transform;
_body = GameObject.FindWithTag("BodyPlayer").transform;
......@@ -38,11 +44,13 @@ namespace _Game.Scripts.GameManager {
startDelay.Register(OnStartRound);
}
private void StartLogic() {
private void StartLogic()
{
StartCoroutine(startDelay.StartCountdown());
}
private void OnStartRound() {
private void OnStartRound()
{
print("Round Start");
roundTime.Clear();
roundTime.Duration = data.roundTime;
......@@ -51,26 +59,106 @@ namespace _Game.Scripts.GameManager {
StartCoroutine(roundTime.StartCountdown());
}
private void OnRoundEnd() {
private void OnRoundEnd()
{
print("Round End");
roundTime.StopCountdown = true;
UpdateScorePoints();
SwitchRolesOfPlayers(); // changes playerX.role in GameData
data.RoundsPlayed++;
print("Rounds Played = " + data.RoundsPlayed);
if (data.RoundsPlayed >= data.roundsToPlay) {
if (data.RoundsPlayed >= data.roundsToPlay)
{
print("Game Ends");
SceneManager.LoadScene("StartMenu");
return;
}
if (data.IsSwitched) {
if (data.IsSwitched)
{
data.IsSwitched = false;
SceneManager.LoadScene("MainLevel");
}
else {
else
{
data.IsSwitched = true;
SceneManager.LoadScene("MainLevelSwitched");
}
}
private void UpdateScorePoints()
{
Debug.Log("Updated Scores");
if (data.player1.role == GameData.Role.Body)
{
// Punkte = [Punkte von letzter Runde] + ( [MaxRundenzeit] - [Noch Übrige Zeit] );
data.player1.UpdateScore(data.player1.scoreLastRound + data.roundTime - roundTime.CurrentTime);
}
else if (data.player1.role == GameData.Role.Head)
{
// Punkte = [Punkte von letzter Runde] + ( Rundenzeit ) - ( [ Rundenzeit ] - [ noch übrige Zeit ] ) )
data.player1.UpdateScore(data.player1.scoreLastRound +
((data.roundTime) - (data.roundTime - roundTime.CurrentTime)));
}
else
{
throw new UnityException(
"Can't update score of player 1 because he didn't does not have a role (Head or Body)");
}
if (data.player2.role == GameData.Role.Body)
{
// Punkte = [Punkte von letzter Runde] + ( [MaxRundenzeit] - [Noch Übrige Zeit] );
data.player2.UpdateScore(data.player2.scoreLastRound + data.roundTime - roundTime.CurrentTime);
}
else if (data.player2.role == GameData.Role.Head)
{
// Punkte = [Punkte von letzter Runde] + ( Rundenzeit ) - ( [ Rundenzeit ] - [ noch übrige Zeit ] ) )
data.player2.UpdateScore(data.player2.scoreLastRound +
((data.roundTime) - (data.roundTime - roundTime.CurrentTime)));
}
else
{
throw new UnityException(
"Can't update score of player 2 because he didn't does not have a role (Head or Body)");
}
}
void SwitchRolesOfPlayers()
{
Debug.Log("Switching Roles of Players");
switch (data.player1.role)
{
case GameData.Role.Body:
data.player1.role = GameData.Role.Head;
break;
case GameData.Role.Head:
data.player1.role = GameData.Role.Body;
break;
default:
throw new UnityException(
"Can't update roles of player 1 because he didn't does not have a role (Head or Body)");
break;
}
switch (data.player2.role)
{
case GameData.Role.Body:
data.player2.role = GameData.Role.Head;
break;
case GameData.Role.Head:
data.player2.role = GameData.Role.Body;
break;
default:
throw new UnityException(
"Can't update roles of player 2 because he didn't does not have a role (Head or Body)");
break;
}
}
}
......
......@@ -31,8 +31,8 @@ public class CharacterCustomization : MonoBehaviour {
public void GoToGameScene() {
data.Reset();
data.player1.Reset(player1InputField.text, Color.green);
data.player2.Reset(player2InputField.text, Color.red);
data.player1.Reset(player1InputField.text, Color.green, GameData.Role.Head);
data.player2.Reset(player2InputField.text, Color.red, GameData.Role.Body);
SceneManager.LoadScene("MainLevel");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment