Files
unity-application/Assets/SpellingBee/Scripts/SpellingBeeGameEndedPanel.cs
2023-05-14 20:18:29 +00:00

106 lines
2.8 KiB
C#

using System;
using TMPro;
/// <summary>
/// The SpellingBee-variant of the ScoreBoard
/// </summary>
public class SpellingBeeGameEndedPanel : AbstractGameEndedPanel
{
/// <summary>
/// Tell the scoreboard that the scoreboard is for SpellingBee
/// </summary>
protected override MinigameIndex minigameIndex
{
get { return MinigameIndex.SPELLING_BEE; }
}
/// <summary>
/// "VERLOREN" or "GEWONNEN"
/// </summary>
public TMP_Text endText;
/// <summary>
/// LPM
/// </summary>
public TMP_Text lpmText;
/// <summary>
/// Letters ( right | wrong )
/// </summary>
public TMP_Text lettersRightText;
/// <summary>
/// Letters ( right | wrong )
/// </summary>
public TMP_Text lettersWrongText;
/// <summary>
/// Letters
/// </summary>
public TMP_Text lettersTotalText;
/// <summary>
/// Accuracy
/// </summary>
public TMP_Text accuracyText;
/// <summary>
/// Words
/// </summary>
public TMP_Text wordsText;
/// <summary>
/// Time
/// </summary>
public TMP_Text timeText;
/// <summary>
/// Score
/// </summary>
public TMP_Text scoreText;
/// <summary>
/// Generate the content of the GameEnded panel
/// </summary>
/// <param name="startTime">Time of starting the minigame</param>
/// <param name="totalWords">Total number of words</param>
/// <param name="correctLetters">Total number of correctly spelled letters</param>
/// <param name="incorrectLetters">Total number of incorrectly spelled letters</param>
/// <param name="result">"VERLOREN" or "GEWONNEN"</param>
/// <param name="score">Final score</param>
public void GenerateContent(DateTime startTime, int totalWords, int correctLetters, int incorrectLetters, string result, int score)
{
// Final result
endText.text = result;
// LPM
TimeSpan duration = DateTime.Now.Subtract(startTime);
lpmText.text = (60f * correctLetters / duration.TotalSeconds).ToString("#") + " LPM";
// Letters ( right | wrong ) total
lettersRightText.text = correctLetters.ToString();
lettersWrongText.text = incorrectLetters.ToString();
lettersTotalText.text = (correctLetters + incorrectLetters).ToString();
// Accuracy
if (correctLetters + incorrectLetters > 0)
{
accuracyText.text = ((correctLetters) * 100f / (correctLetters + incorrectLetters)).ToString("#.##") + "%";
}
else
{
accuracyText.text = "-";
}
// Words
wordsText.text = $"{totalWords}";
// Time
timeText.text = duration.ToString(@"mm\:ss");
// Score
scoreText.text = $"Score: {score}";
SetScoreBoard();
}
}