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

92 lines
2.5 KiB
C#

using TMPro;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// The Hangman-variant of the ScoreBoard
/// </summary>
public class HangmanGameEndedPanel : AbstractGameEndedPanel
{
/// <summary>
/// Tell the scoreboard that the scoreboard is for HangMan
/// </summary>
protected override MinigameIndex minigameIndex
{
get { return MinigameIndex.HANGMAN; }
}
/// <summary>
/// "VERLOREN" or "GEWONNEN"
/// </summary>
public TMP_Text endText;
/// <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>
/// Word that needed to be guessed
/// </summary>
public TMP_Text wordText;
/// <summary>
/// Score
/// </summary>
public TMP_Text scoreText;
/// <summary>
/// Reference to the end result image
/// </summary>
public Image image;
/// <summary>
/// Generate the content of the GameEnded panel
/// </summary>
/// <param name="guessWord">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="sprite">Sprite to be displayed alongside the final score</param>
/// <param name="result">"VERLOREN" or "GEWONNEN"</param>
/// <param name="score">Final score</param>
public void GenerateContent(string guessWord, int correctLetters, int incorrectLetters, Sprite sprite, string result, int score)
{
// Final result
endText.text = result;
image.sprite = sprite;
// Letters ( right | wrong ) total
lettersRightText.text = correctLetters.ToString();
lettersWrongText.text = incorrectLetters.ToString();
lettersTotalText.text = (correctLetters + incorrectLetters).ToString();
// Accuracy, should always be true
if (correctLetters + incorrectLetters > 0)
{
accuracyText.text = ((correctLetters) * 100f / (correctLetters + incorrectLetters)).ToString("#.##") + "%";
}
// Words
wordText.text = guessWord;
// Score
scoreText.text = $"Score: {score}";
SetScoreBoard();
}
}