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

View File

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

View File

@ -66,6 +66,7 @@ namespace GameLogic
/// Indicates whether a round or the whole match was won
/// </summary>
public bool IsMatchWon { get; private set; }
public bool IsRoundWon { get; set; }
public int RoundsPlayed { get; private set; }
public Player Winner { get; private set; }
public List<Player> Opponents { get; private set; }
@ -86,25 +87,35 @@ namespace GameLogic
Opponents = mps.Keys.Where(player => player != Winner).ToList();
mps[Winner].RoundsWon += 1;
RoundsPlayed += 1;
IsRoundWon = true;
}
else
{
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)
{
IsMatchWon = true;
Winner = mps.Aggregate((p1, p2) =>
p1.Value.RoundsWon > p2.Value.RoundsWon ? p1 : p2).Key;
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;
}
}
}

View File

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