fix: match logic for rounds, hide HUD when in menu

This commit is contained in:
Jakob Feldmann 2024-04-22 13:34:37 +02:00
parent a3fa41eae2
commit 4610120329
4 changed files with 46 additions and 10 deletions

View File

@ -140,6 +140,9 @@ namespace Managers
/// <param name="update">A change in the matches progression.</param> /// <param name="update">A change in the matches progression.</param>
public void UpdateMatchCondition(MatchConditionUpdate update) public void UpdateMatchCondition(MatchConditionUpdate update)
{ {
// Quit updating when the round is over
if (CurrentMatchResult.IsRoundWon)
return;
Player updatedPlayer = null; Player updatedPlayer = null;
foreach (Player p in PlayerManager.G.MatchPlayers) foreach (Player p in PlayerManager.G.MatchPlayers)
{ {
@ -169,7 +172,7 @@ namespace Managers
else else
{ {
Log.Info($"Round {CurrentMatchResult.RoundsPlayed} of {MatchRule.rounds} has ended." + Log.Info($"Round {CurrentMatchResult.RoundsPlayed} of {MatchRule.rounds} has ended." +
$"{CurrentMatchResult.Winner?.name} won this round."); $"{CurrentMatchResult.Winner?.playerName} won this round.");
AnnounceRoundWinner(CurrentMatchResult); AnnounceRoundWinner(CurrentMatchResult);
} }
} }
@ -278,11 +281,12 @@ namespace Managers
UIManager.G.Announcments.QueueAnnounceText($"{mr.Winner.playerName}" + UIManager.G.Announcments.QueueAnnounceText($"{mr.Winner.playerName}" +
" has won the Round! \n" + " has won the Round! \n" +
$"They won {winnerStats.RoundsWon} out of {MatchRule.rounds}.", $"They won {winnerStats.RoundsWon} out of {MatchRule.rounds}.",
1.618f); 3f);
await Tween.Delay(1.618f * 0.33f); await Tween.Delay(3f * 0.33f);
matchState = MatchState.Pause; matchState = MatchState.Pause;
await Tween.Delay(1.618f * 0.66f); ResetRound();
await Tween.Delay(3f * 0.66f);
ResetMatchCharacters(); ResetMatchCharacters();
@ -305,6 +309,14 @@ namespace Managers
SetupMatchPlayerStatistics(); SetupMatchPlayerStatistics();
} }
/// <summary>
/// Resets the round statistics.
/// </summary>
public void ResetRound()
{
CurrentMatchResult.IsRoundWon = false;
}
/// <summary> /// <summary>
/// Initializes the match, waits for match begin /// Initializes the match, waits for match begin
/// confirmation by the players and counts down to start. /// confirmation by the players and counts down to start.

View File

@ -129,21 +129,29 @@ namespace Managers
public void ShowPauseMenu(Transform transform) public void ShowPauseMenu(Transform transform)
{ {
hUD?.Hide();
PauseMenu?.Show(transform); PauseMenu?.Show(transform);
} }
public void HidePauseMenu() public void HidePauseMenu()
{ {
PauseMenu?.Hide(); PauseMenu?.Hide();
hUD?.Show();
} }
public void ShowMatchEndMenu(Transform transform) public void ShowMatchEndMenu(Transform transform)
{ {
hUD?.Hide();
MatchEndMenu?.Show(transform); MatchEndMenu?.Show(transform);
} }
public void HideMatchEndMenu() public void HideMatchEndMenu()
{ {
MatchEndMenu?.Hide(); MatchEndMenu?.Hide();
hUD?.Show();
}
public void ShowHUD()
{
hUD?.Show();
} }
public void HideHUD() public void HideHUD()

View File

@ -66,6 +66,7 @@ namespace GameLogic
/// Indicates whether a round or the whole match was won /// Indicates whether a round or the whole match was won
/// </summary> /// </summary>
public bool IsMatchWon { get; private set; } public bool IsMatchWon { get; private set; }
public bool IsRoundWon { get; set; }
public int RoundsPlayed { get; private set; } public int RoundsPlayed { get; private set; }
public Player Winner { get; private set; } public Player Winner { get; private set; }
public List<Player> Opponents { get; private set; } public List<Player> Opponents { get; private set; }
@ -86,21 +87,32 @@ namespace GameLogic
Opponents = mps.Keys.Where(player => player != Winner).ToList(); Opponents = mps.Keys.Where(player => player != Winner).ToList();
mps[Winner].RoundsWon += 1; mps[Winner].RoundsWon += 1;
RoundsPlayed += 1; RoundsPlayed += 1;
IsRoundWon = true;
} }
else else
{ {
Winner = null; Winner = null;
} }
// TODO: this is wrong winning 2 rounds can decide the match
foreach (Player p in mps.Keys)
{
if (mps[p].RoundsWon > rules.rounds / 2)
{
IsMatchWon = true;
Winner = p;
Opponents = mps.Keys.Where(player => player != Winner).ToList();
return;
}
}
if (RoundsPlayed == rules.rounds) if (RoundsPlayed == rules.rounds)
{ {
IsMatchWon = true; IsMatchWon = true;
Winner = mps.Aggregate((p1, p2) => Winner = mps.Aggregate((p1, p2) =>
p1.Value.RoundsWon > p2.Value.RoundsWon ? p1 : p2).Key; p1.Value.RoundsWon > p2.Value.RoundsWon ? p1 : p2).Key;
Opponents = mps.Keys.Where(player => player != Winner).ToList(); Opponents = mps.Keys.Where(player => player != Winner).ToList();
return;
} }
else
{
foreach (var statistic in mps.Values) foreach (var statistic in mps.Values)
{ {
statistic.IsOut = false; statistic.IsOut = false;
@ -108,4 +120,3 @@ namespace GameLogic
} }
} }
} }
}

View File

@ -36,4 +36,9 @@ public class HUD : MonoBehaviour
canvas.enabled = false; canvas.enabled = false;
} }
public void Show()
{
canvas.enabled = true;
}
} }