Implemented end of game screen
This commit is contained in:
parent
ac10c8a2fc
commit
3651adbef8
23 changed files with 20035 additions and 19365 deletions
|
|
@ -3,9 +3,33 @@ using UnityEngine;
|
|||
using Object = UnityEngine.Object;
|
||||
using System.Collections.Generic;
|
||||
using Abilities;
|
||||
using DungeonSelection;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
|
||||
public class EndOfGameEventArgs : EventArgs
|
||||
{
|
||||
public EndOfGameEventArgs(
|
||||
string message,
|
||||
bool died,
|
||||
int diamonds,
|
||||
int pointsFromHealth,
|
||||
int finalScore)
|
||||
{
|
||||
Message = message;
|
||||
Died = died;
|
||||
Diamonds = diamonds;
|
||||
PointsFromHealth = pointsFromHealth;
|
||||
FinalScore = finalScore;
|
||||
}
|
||||
|
||||
public bool Died { get; private set; }
|
||||
public int Diamonds { get; private set; }
|
||||
public readonly int DiamondsMultiplier = 3;
|
||||
public int PointsFromHealth { get; private set; }
|
||||
public int FinalScore { get; private set; }
|
||||
public string Message { get; private set; }
|
||||
}
|
||||
public enum GameState
|
||||
{
|
||||
RollDice,
|
||||
|
|
@ -21,12 +45,28 @@ public class GameManager : MonoBehaviour
|
|||
[SerializeField] private DiceRoller diceRoller;
|
||||
[SerializeField] private PassManager passManager;
|
||||
[SerializeField] private Player player;
|
||||
[SerializeField] private DungeonData dungeonData;
|
||||
|
||||
private DicePair _dicePairOne = new();
|
||||
private DicePair _dicePairTwo = new();
|
||||
|
||||
private int monstersLeft = 0; // Includes boss monster. Used for detecting end of game.
|
||||
public static event Action<GameState> StateChanged;
|
||||
public static event Action<DicePair> DiceSelected;
|
||||
public static event Action DiceUnselected;
|
||||
public static event EventHandler<EndOfGameEventArgs> EndOfGame;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
MonsterRoom.MonsterRoomExplored += HandleMonsterRoomExplored;
|
||||
player.Died += HandlePlayerDied;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
MonsterRoom.MonsterRoomExplored -= HandleMonsterRoomExplored;
|
||||
player.Died -= HandlePlayerDied;
|
||||
}
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
|
|
@ -36,7 +76,12 @@ public class GameManager : MonoBehaviour
|
|||
rooms = GameObject.FindWithTag("RoomsParent");
|
||||
foreach (Transform roomTransform in rooms.transform)
|
||||
{
|
||||
roomTransform.gameObject.GetComponent<Room>().RoomExploredByDice += HandleRoomExploredByDice;
|
||||
Room roomComponent = roomTransform.gameObject.GetComponent<Room>();
|
||||
roomComponent.RoomExploredByDice += HandleRoomExploredByDice;
|
||||
if (roomComponent is MonsterRoom)
|
||||
{
|
||||
monstersLeft++;
|
||||
}
|
||||
}
|
||||
foreach (Transform diceTransform in diceRoller.dice.transform)
|
||||
{
|
||||
|
|
@ -149,4 +194,49 @@ public class GameManager : MonoBehaviour
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleMonsterRoomExplored()
|
||||
{
|
||||
monstersLeft--;
|
||||
if (monstersLeft <= 0)
|
||||
{
|
||||
ResolveEndOfGame(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void HandlePlayerDied()
|
||||
{
|
||||
ResolveEndOfGame(false);
|
||||
}
|
||||
|
||||
private void ResolveEndOfGame(bool allMonstersKilled)
|
||||
{
|
||||
string message;
|
||||
if (allMonstersKilled)
|
||||
{
|
||||
message = dungeonData.WinMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
message = dungeonData.DieMessage;
|
||||
}
|
||||
|
||||
int finalScore = CalculateScore();
|
||||
Debug.Log($"Final score: {finalScore}");
|
||||
EndOfGame?.Invoke(this, new EndOfGameEventArgs(
|
||||
message,
|
||||
!allMonstersKilled,
|
||||
player.GetDiamondCount(),
|
||||
player.GetHealthScore(),
|
||||
finalScore));
|
||||
}
|
||||
|
||||
private int CalculateScore()
|
||||
{
|
||||
int sum = 0;
|
||||
sum += player.GetDiamondCount() * 3;
|
||||
sum += player.GetHealthScore();
|
||||
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue