This commit is contained in:
Jelle De Geest
2023-04-26 19:04:34 +02:00
parent 172938cec8
commit 47f8b96122
1004 changed files with 60756 additions and 117444 deletions

View File

@@ -1,78 +0,0 @@
using System.Collections;
using System.Linq;
using System.IO;
using NUnit.Framework;
using TMPro;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.SceneManagement;
public class GameControllerTests
{
[UnitySetUp]
public IEnumerator SetupFunction()
{
string path = $"{Application.persistentDataPath}/unit_test_users.json";
var oneUser = "{\"currentUserIndex\": 0,\"storedUsers\": [{\"username\": \"TEST\",\"avatar\": {\"instanceID\": 40848},\"playtime\": 0.0,\"courses\": [],\"minigames\": []}]}";
using (StreamWriter writer = new StreamWriter(path))
{
writer.Write(oneUser);
}
SystemController.GetInstance().LoadNextScene("SpellingBee/Scenes/Game");
yield return new WaitForSeconds(0.2f);
}
[UnityTest]
public IEnumerator CheckScoreTest()
{
GameController gameController = (GameController)GameObject.FindObjectOfType(typeof(GameController));
yield return new WaitForSeconds(0.2f);
Assert.AreEqual(0, gameController.CalculateScore());
gameController.NextWord();
Assert.AreEqual(5, gameController.CalculateScore());
gameController.NextLetter(true);
Assert.AreEqual(6, gameController.CalculateScore());
}
[UnityTest]
public IEnumerator ActivateGameOverTest()
{
GameController gameController = (GameController)GameObject.FindObjectOfType(typeof(GameController));
gameController.ActivateGameOver();
yield return new WaitForSeconds(0.2f);
GameEndedPanel gameEndedPanel = (GameEndedPanel)GameObject.FindObjectOfType(typeof(GameEndedPanel));
Assert.NotNull(gameEndedPanel);
Assert.AreEqual("VERLOREN", gameEndedPanel.endText.text);
}
[UnityTest]
public IEnumerator ActivateWinTests()
{
GameController gameController = (GameController)GameObject.FindObjectOfType(typeof(GameController));
gameController.ActivateWin();
yield return new WaitForSeconds(0.2f);
GameEndedPanel gameEndedPanel = (GameEndedPanel)GameObject.FindObjectOfType(typeof(GameEndedPanel));
Assert.NotNull(gameEndedPanel);
Assert.AreEqual("GEWONNEN", gameEndedPanel.endText.text);
}
[UnityTest]
public IEnumerator CheckGameOverTest()
{
GameController gameController = (GameController)GameObject.FindObjectOfType(typeof(GameController));
gameController.AddSeconds(-60);
yield return new WaitForSeconds(0.1f);
GameEndedPanel gameEndedPanel = (GameEndedPanel)GameObject.FindObjectOfType(typeof(GameEndedPanel));
Assert.NotNull(gameEndedPanel);
Assert.AreEqual("VERLOREN", gameEndedPanel.endText.text);
}
}

View File

@@ -1,52 +1,45 @@
using System.Collections;
using System.Linq;
using System.IO;
using NUnit.Framework;
using TMPro;
using System.Collections;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.SceneManagement;
public class GameEndedPanelTests
public class SpellingBeeGameEndedPanelTests
{
[UnitySetUp]
public IEnumerator SetupFunction()
{
string path = $"{Application.persistentDataPath}/unit_test_users.json";
var oneUser = "{\"currentUserIndex\": 0,\"storedUsers\": [{\"username\": \"TEST\",\"avatar\": {\"instanceID\": 40848},\"playtime\": 0.0,\"courses\": [],\"minigames\": []}]}";
string oneUser = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
using (StreamWriter writer = new StreamWriter(path))
{
writer.Write(oneUser);
}
SystemController.GetInstance().LoadNextScene("SpellingBee/Scenes/Game");
File.WriteAllText(path, oneUser);
PersistentDataController.GetInstance().Load();
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
SystemController.GetInstance().LoadNextScene("SpellingBee/Scenes/SpellingBeeGame");
yield return new WaitForSeconds(0.2f);
}
[UnityTest]
public IEnumerator ScoreTest()
{
GameController gameController = (GameController)GameObject.FindObjectOfType(typeof(GameController));
gameController.NextWord();
gameController.NextLetter(false);
gameController.NextLetter(true);
gameController.NextLetter(false);
SpellingBeeController spellingBeeController = (SpellingBeeController)GameObject.FindObjectOfType(typeof(SpellingBeeController));
spellingBeeController.NextWord();
spellingBeeController.NextLetter(false);
spellingBeeController.NextLetter(true);
spellingBeeController.NextLetter(false);
yield return new WaitForSeconds(1f);
gameController.ActivateWin();
spellingBeeController.ActivateEnd(true);
GameEndedPanel gameEndedPanel = (GameEndedPanel)GameObject.FindObjectOfType(typeof(GameEndedPanel));
Assert.NotNull(gameEndedPanel);
Assert.AreEqual("Score: 6", gameEndedPanel.scoreText.text);
Assert.AreEqual("1", gameEndedPanel.lettersRightText.text);
Assert.AreEqual("2", gameEndedPanel.lettersWrongText.text);
Assert.AreEqual("3", gameEndedPanel.lettersTotalText.text);
Assert.AreEqual("00:01", gameEndedPanel.timeText.text);
SpellingBeeGameEndedPanel SpellingBeeGameEndedPanel = (SpellingBeeGameEndedPanel)GameObject.FindObjectOfType(typeof(SpellingBeeGameEndedPanel));
Assert.NotNull(SpellingBeeGameEndedPanel);
Assert.AreEqual("Score: 0", SpellingBeeGameEndedPanel.scoreText.text);
Assert.AreEqual("1", SpellingBeeGameEndedPanel.lettersRightText.text);
Assert.AreEqual("2", SpellingBeeGameEndedPanel.lettersWrongText.text);
Assert.AreEqual("3", SpellingBeeGameEndedPanel.lettersTotalText.text);
Assert.AreEqual("00:01", SpellingBeeGameEndedPanel.timeText.text);
}
}

View File

@@ -0,0 +1,71 @@
using NUnit.Framework;
using System.Collections;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.TestTools;
public class SpellingBeeControllerTests
{
[UnitySetUp]
public IEnumerator SetupFunction()
{
string path = $"{Application.persistentDataPath}/unit_test_users.json";
string oneUser = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
File.WriteAllText(path, oneUser);
PersistentDataController.GetInstance().Load();
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
SystemController.GetInstance().LoadNextScene("SpellingBee/Scenes/SpellingBeeGame");
yield return new WaitForSeconds(0.2f);
}
[UnityTest]
public IEnumerator CheckScoreTest()
{
SpellingBeeController spellingBeeController = (SpellingBeeController)GameObject.FindObjectOfType(typeof(SpellingBeeController));
yield return new WaitForSeconds(0.2f);
Assert.AreEqual(0, spellingBeeController.CalculateScore());
spellingBeeController.NextWord();
Assert.AreEqual(0, spellingBeeController.CalculateScore());
spellingBeeController.NextLetter(true);
Assert.AreEqual(10, spellingBeeController.CalculateScore());
}
[UnityTest]
public IEnumerator ActivateGameOverTest()
{
SpellingBeeController spellingBeeController = (SpellingBeeController)GameObject.FindObjectOfType(typeof(SpellingBeeController));
spellingBeeController.ActivateEnd(false);
yield return new WaitForSeconds(0.2f);
SpellingBeeGameEndedPanel SpellingBeeGameEndedPanel = (SpellingBeeGameEndedPanel)GameObject.FindObjectOfType(typeof(SpellingBeeGameEndedPanel));
Assert.NotNull(SpellingBeeGameEndedPanel);
Assert.AreEqual("VERLOREN", SpellingBeeGameEndedPanel.endText.text);
}
[UnityTest]
public IEnumerator ActivateWinTests()
{
SpellingBeeController spellingBeeController = (SpellingBeeController)GameObject.FindObjectOfType(typeof(SpellingBeeController));
spellingBeeController.ActivateEnd(true);
yield return new WaitForSeconds(0.2f);
SpellingBeeGameEndedPanel SpellingBeeGameEndedPanel = (SpellingBeeGameEndedPanel)GameObject.FindObjectOfType(typeof(SpellingBeeGameEndedPanel));
Assert.NotNull(SpellingBeeGameEndedPanel);
Assert.AreEqual("GEWONNEN", SpellingBeeGameEndedPanel.endText.text);
}
[UnityTest]
public IEnumerator CheckGameOverTest()
{
SpellingBeeController spellingBeeController = (SpellingBeeController)GameObject.FindObjectOfType(typeof(SpellingBeeController));
spellingBeeController.AddSeconds(-60);
yield return new WaitForSeconds(0.1f);
SpellingBeeGameEndedPanel SpellingBeeGameEndedPanel = (SpellingBeeGameEndedPanel)GameObject.FindObjectOfType(typeof(SpellingBeeGameEndedPanel));
Assert.NotNull(SpellingBeeGameEndedPanel);
Assert.AreEqual("VERLOREN", SpellingBeeGameEndedPanel.endText.text);
}
}

View File

@@ -7,7 +7,10 @@
"InterfacesScripts",
"Unity.TextMeshPro",
"SpellingBeeScripts",
"AccountsScripts"
"AccountsScripts",
"ArchitectureScripts",
"SignPredictor",
"MinigameScripts"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -145,8 +145,8 @@ MonoBehaviour:
m_Calls: []
m_text: A
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_fontAsset: {fileID: 11400000, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
m_sharedMaterial: {fileID: -2577534979213189211, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []

View File

@@ -68,8 +68,8 @@ MonoBehaviour:
m_Calls: []
m_text: Player name
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_fontAsset: {fileID: 11400000, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
m_sharedMaterial: {fileID: -2577534979213189211, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
@@ -279,8 +279,8 @@ MonoBehaviour:
m_Calls: []
m_text: xh
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_fontAsset: {fileID: 11400000, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
m_sharedMaterial: {fileID: -2577534979213189211, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
@@ -414,8 +414,8 @@ MonoBehaviour:
m_Calls: []
m_text: xxx
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_fontAsset: {fileID: 11400000, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
m_sharedMaterial: {fileID: -2577534979213189211, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
@@ -549,8 +549,8 @@ MonoBehaviour:
m_Calls: []
m_text: 1
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_fontAsset: {fileID: 11400000, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
m_sharedMaterial: {fileID: -2577534979213189211, guid: 1baf2eae62f542f4585aaf3c9c3e229a, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []

View File

@@ -14,11 +14,9 @@ MonoBehaviour:
m_EditorClassIdentifier:
index: 0
title: Spelling Bee
description: In deze minigame krijg je verschillende woorden voorgeschoteld die
je zo snel mogelijk moet spellen met behulp van het vingeralfabet
description: Leer spellen als een pro
themeList: {fileID: 11400000, guid: a247e2ce790f0f746a3bc521e6ab7d58, type: 2}
thumbnail: {fileID: 21300000, guid: f2a020e24bfa24842bccecf6b36d5b79, type: 3}
minigameEntryPoint: SpellingBee/Scenes/Game
controls: Je begint dit spel met 5 seconden tijd, voor elk juist antwoord krijg
je extra tijd. Hoe sneller je het spel uitspeelt, hoe meer punten je scoort.
Verloopt de timer, dan heb je het spelletje verloren
thumbnail: {fileID: 21300000, guid: 99ff017f7243eeb4db0c08a6b832d744, type: 3}
minigameEntryPoint: SpellingBee/Scenes/SpellingBeeGame
controls: Een spelletje tegen de tijd. Spel zoveel mogelijk woorden binnen de tijd!
Voor elke juiste letter krijg je extra tijd, hou het zo lang mogelijk uit.

View File

@@ -1,456 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public partial class GameController : MonoBehaviour
{
/// <summary>
/// All of the words that can be used in this session
/// </summary>
//private string[] words;
private List<Learnable> words = new List<Learnable>();
/// <summary>
/// Where we currently are in the word
/// </summary>
private int letterIndex;
/// <summary>
/// Where we currently are in the word list
/// </summary>
private int wordIndex;
/// <summary>
/// The word that is currently being spelled
/// </summary>
private string currentWord;
/// <summary>
/// All of the available themes
/// </summary>
public ThemeList themeList;
/// <summary>
/// The theme we are currently using
/// </summary>
private Theme currentTheme;
/// <summary>
/// Current value of timer in seconds
/// </summary>
private float timerValue;
/// <summary>
/// Indicates if the game is still going
/// </summary>
private bool gameEnded;
/// <summary>
/// Amount of seconds user gets per letter of the current word
/// Set to 1 for testing; should be increased later
/// </summary>
private const int secondsPerLetter = 5;
/// <summary>
/// Counter that keeps track of how many letters have been spelled correctly
/// </summary>
private int correctLetters;
/// <summary>
/// Counter that keeps track of how many letters have been spelled incorrectly
/// </summary>
private int incorrectLetters;
/// <summary>
/// Counter that keeps track of how many words have been spelled correctly
/// </summary>
private int spelledWords;
/// <summary>
/// Timer that keeps track of when the game was started
/// </summary>
private DateTime startTime;
/// <summary>
/// Reference to the user list to access the current user
/// </summary>
public UserList userList;
/// <summary>
/// Reference to the current user
/// </summary>
private User user;
/// <summary>
/// Reference to the minigame ScriptableObject
/// </summary>
public Minigame minigame;
/// <summary>
/// We keep the minigamelist as well so that the minigame-index doesn't get reset
/// DO NOT REMOVE
/// </summary>
public MinigameList minigamelist;
/// <summary>
/// Letter prefab
/// </summary>
public GameObject letterPrefab;
/// <summary>
/// Reference to letter container
/// </summary>
public Transform letterContainer;
/// <summary>
/// The Image component for displaying the appropriate sprite
/// </summary>
public Image wordImage;
/// <summary>
/// Timer display
/// </summary>
public TMP_Text timerText;
/// <summary>
/// Bonus time display
/// </summary>
public GameObject bonusTimeText;
/// <summary>
/// Timer to display the bonus time
/// </summary>
private float bonusActiveRemaining = 0.0f;
/// <summary>
/// The GameObjects representing the letters
/// </summary>
private List<GameObject> letters = new List<GameObject>();
/// <summary>
/// Reference to the scoreboard
/// </summary>
public Transform Scoreboard;
/// <summary>
/// Accuracy feeback object
/// </summary>
public Feedback feedback;
/// <summary>
/// Reference to the gameEnded panel, so we can update its display
/// </summary>
public GameObject gameEndedPanel;
/// <summary>
/// Start is called before the first frame update
/// </summary>
public void Start()
{
correctLetters = 0;
incorrectLetters = 0;
words.Clear();
// We use -1 instead of 0 so SetNextWord can simply increment it each time
spelledWords = -1;
wordIndex = 0;
gameEnded = false;
timerValue = 30.0f;
bonusActiveRemaining = 0.0f;
startTime = DateTime.Now;
gameEndedPanel.SetActive(false);
bonusTimeText.SetActive(false);
// Create entry in current user for keeping track of progress
userList.Load();
user = userList.GetCurrentUser();
Progress progress = user.GetMinigameProgress(minigame.index);
if (progress == null)
{
progress = new Progress();
progress.AddOrUpdate<MinigameIndex>("minigameIndex", MinigameIndex.SPELLING_BEE);
progress.AddOrUpdate<List<Score>>("highestScores", new List<Score>());
progress.AddOrUpdate<List<Score>>("latestScores", new List<Score>());
user.minigames.Add(progress);
}
userList.Save();
currentTheme = minigame.themeList.themes[minigame.themeList.currentThemeIndex];
feedback.signPredictor.model = currentTheme.model;
words.AddRange(currentTheme.learnables);
ShuffleWords();
NextWord();
// Set calllbacks
feedback.getSignCallback = () =>
{
if (letterIndex < currentWord.Length)
{
return currentWord[letterIndex].ToString().ToUpper();
}
return null;
};
feedback.predictSignCallback = (sign) =>
{
bool successful = sign.ToUpper() == currentWord[letterIndex].ToString().ToUpper();
if (successful)
{
AddSeconds(secondsPerLetter);
}
NextLetter(successful);
};
}
/// <summary>
/// Update is called once per frame
/// </summary>
public void Update()
{
if (!gameEnded)
{
timerValue -= Time.deltaTime;
if (bonusActiveRemaining <= 0.0 && bonusTimeText.activeSelf)
{
bonusTimeText.SetActive(false);
}
else
{
bonusActiveRemaining -= Time.deltaTime;
}
if (timerValue <= 0.0f)
{
timerValue = 0.0f;
ActivateGameOver();
}
int minutes = Mathf.FloorToInt(timerValue / 60.0f);
int seconds = Mathf.FloorToInt(timerValue % 60.0f);
timerText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
}
}
/// <summary>
/// Randomly shuffle the list of words
/// </summary>
public void ShuffleWords()
{
for (int i = words.Count - 1; i > 0; i--)
{
// Generate a random index between 0 and i (inclusive)
int j = UnityEngine.Random.Range(0, i + 1);
// Swap the values at indices i and j
(words[j], words[i]) = (words[i], words[j]);
}
}
/// <summary>
/// Calculate the score
/// </summary>
/// <returns>The calculated score</returns>
public int CalculateScore()
{
return spelledWords * 5 + correctLetters;
}
/// <summary>
/// Displays the game over panel and score values
/// </summary>
public void ActivateGameOver()
{
gameEnded = true;
DeleteWord();
// Save the scores and show the scoreboard
SaveScores();
gameEndedPanel.GetComponent<GameEndedPanel>().GenerateContent(
startTime: startTime,
totalWords: spelledWords,
correctLetters: correctLetters,
incorrectLetters: incorrectLetters,
result: "VERLOREN",
score: CalculateScore()
);
gameEndedPanel.SetActive(true);
}
/// <summary>
/// Display win screen
/// </summary>
public void ActivateWin()
{
gameEnded = true;
DeleteWord();
// Save the scores and show the scoreboard
SaveScores();
gameEndedPanel.GetComponent<GameEndedPanel>().GenerateContent(
startTime: startTime,
totalWords: spelledWords,
correctLetters: correctLetters,
incorrectLetters: incorrectLetters,
result: "GEWONNEN",
score: CalculateScore()
);
gameEndedPanel.SetActive(true);
}
/// <summary>
/// Update and save the scores
/// </summary>
public void SaveScores()
{
// Calculate new score
int newScore = CalculateScore();
// Save the score as a tuple: < int score, string time ago>
Score score = new Score();
score.scoreValue = newScore;
score.time = DateTime.Now.ToString();
// Save the new score
user = userList.GetCurrentUser();
Progress progress = user.GetMinigameProgress(minigame.index);
// Get the current list of scores
List<Score> latestScores = progress.Get<List<Score>>("latestScores");
List<Score> highestScores = progress.Get<List<Score>>("highestScores");
// Add the new score
latestScores.Add(score);
highestScores.Add(score);
// Sort the scores
highestScores.Sort((a, b) => b.scoreValue.CompareTo(a.scoreValue));
// Only save the top 10 scores, so this list doesn't keep growing endlessly
progress.AddOrUpdate<List<Score>>("latestScores", latestScores.Take(10).ToList());
progress.AddOrUpdate<List<Score>>("highestScores", highestScores.Take(10).ToList());
userList.Save();
}
/// <summary>
/// Delete all letter objects
/// </summary>
public void DeleteWord()
{
for (int i = 0; i < letters.Count; i++)
{
Destroy(letters[i]);
}
letters.Clear();
}
/// <summary>
/// Adds seconds to timer
/// </summary>
/// <param name="seconds"></param>
public void AddSeconds(int seconds)
{
timerValue += (float)seconds;
bonusTimeText.SetActive(true);
bonusActiveRemaining = 2.0f;
}
/// <summary>
/// Display the next letter
/// </summary>
/// <param name="successful">true if the letter was correctly signed, false otherwise</param>
public void NextLetter(bool successful)
{
if (gameEnded) { return; }
// Change color of current letter (skip spaces)
if (successful)
{
correctLetters++;
letters[letterIndex].GetComponent<Image>().color = Color.green;
}
else
{
incorrectLetters++;
letters[letterIndex].GetComponent<Image>().color = new Color(0.5f, 0.0f, 0.0f);
}
do
{
letterIndex++;
} while (letterIndex < currentWord.Length && currentWord[letterIndex] == ' ');
// Change the color of the next letter or change to new word
if (letterIndex < currentWord.Length)
{
letters[letterIndex].GetComponent<Image>().color = Color.yellow;
}
else
{
StartCoroutine(Wait());
NextWord();
}
}
/// <summary>
/// Display next word in the series
/// </summary>
public void NextWord()
{
DeleteWord();
spelledWords++;
if (wordIndex < words.Count)
{
currentWord = words[wordIndex].name;
letterIndex = 0;
DisplayWord(currentWord);
wordIndex++;
}
else
{
ActivateWin();
}
}
/// <summary>
/// Displays the word that needs to be spelled
/// </summary>
/// <param name="word">The word to display</param>
public void DisplayWord(string word)
{
for (int i = 0; i < word.Length; i++)
{
// Create instance of prefab
GameObject instance = GameObject.Instantiate(letterPrefab, letterContainer);
letters.Add(instance);
// Dynamically load appearance
char c = Char.ToUpper(word[i]);
Image background = instance.GetComponent<Image>();
background.color = i == 0 ? Color.yellow : c != ' ' ? Color.red : Color.clear;
TMP_Text txt = instance.GetComponentInChildren<TMP_Text>();
txt.text = Char.ToString(c);
}
wordImage.sprite = words[wordIndex].image;
}
/// <summary>
/// wait for 2 seconds
/// </summary>
/// <returns></returns>
private IEnumerator Wait()
{
yield return new WaitForSecondsRealtime(2);
}
}

View File

@@ -1,25 +0,0 @@
fileFormatVersion: 2
guid: 44fbed5ae228de39b9f727def7578d06
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- input: {instanceID: 0}
- endText: {instanceID: 0}
- correctWordsText: {instanceID: 0}
- correctLettersText: {instanceID: 0}
- gameEndedPanel: {instanceID: 0}
- replayButton: {instanceID: 0}
- userList: {instanceID: 0}
- minigame: {instanceID: 0}
- letterPrefab: {instanceID: 0}
- letterContainer: {instanceID: 0}
- wordImage: {instanceID: 0}
- timerText: {instanceID: 0}
- Scoreboard: {instanceID: 0}
- scoreboardEntry: {fileID: 9154151134820372555, guid: d4a3a228b08d61847acc6da35b44e52c, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,212 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class GameEndedPanel : MonoBehaviour
{
public UserList userList;
/// <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;
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>
/// Reference to the scoreboard entries container
/// </summary>
public Transform scoreboardEntriesContainer;
/// <summary>
/// The GameObjects representing the letters
/// </summary>
private List<GameObject> scoreboardEntries = new List<GameObject>();
/// <summary>
/// Reference to the ScoreboardEntry prefab
/// </summary>
public GameObject scoreboardEntry;
/// <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();
}
/// <summary>
/// Sets the scoreboard
/// </summary>
private void SetScoreBoard()
{
// Clean the previous scoreboard entries
for (int i = 0; i < scoreboardEntries.Count; i++)
{
Destroy(scoreboardEntries[i]);
}
scoreboardEntries.Clear();
// Instantiate new entries
// Get all scores from all users
List<Tuple<string, Score>> allScores = new List<Tuple<string, Score>>();
foreach (User user in userList.GetUsers())
{
// Get user's progress for this minigame
Progress progress = user.GetMinigameProgress(MinigameIndex.SPELLING_BEE);
if (progress != null)
{
// Add scores to dictionary
List<Score> scores = progress.Get<List<Score>>("highestScores");
foreach (Score score in scores)
{
allScores.Add(new Tuple<string, Score>(user.username, score));
}
}
}
// Sort allScores based on Score.scoreValue
allScores.Sort((a, b) => b.Item2.scoreValue.CompareTo(a.Item2.scoreValue));
// Instantiate scoreboard entries
int rank = 1;
foreach (Tuple<string, Score> tup in allScores.Take(10))
{
string username = tup.Item1;
Score score = tup.Item2;
GameObject entry = Instantiate(scoreboardEntry, scoreboardEntriesContainer);
scoreboardEntries.Add(entry);
// Set the player icon
entry.transform.Find("Image").GetComponent<Image>().sprite = userList.GetUserByUsername(username).avatar;
// Set the player name
entry.transform.Find("PlayerName").GetComponent<TMP_Text>().text = username;
// Set the score
entry.transform.Find("Score").GetComponent<TMP_Text>().text = score.scoreValue.ToString();
// Set the rank
entry.transform.Find("Rank").GetComponent<TMP_Text>().text = rank.ToString();
// Set the ago
// Convert the score.time to Datetime
DateTime time = DateTime.Parse(score.time);
DateTime currentTime = DateTime.Now;
TimeSpan diff = currentTime.Subtract(time);
string formatted;
if (diff.Days > 0)
{
formatted = $"{diff.Days}d ";
}
else if (diff.Hours > 0)
{
formatted = $"{diff.Hours}h ";
}
else if (diff.Minutes > 0)
{
formatted = $"{diff.Minutes}m ";
}
else
{
formatted = "now";
}
entry.transform.Find("Ago").GetComponent<TMP_Text>().text = formatted;
// Alternating colors looks nice
if (rank % 2 == 0)
{
Image image = entry.transform.GetComponent<Image>();
image.color = new Color(image.color.r, image.color.g, image.color.b, 0f);
}
// Make new score stand out
if (diff.TotalSeconds < 1)
{
Image image = entry.transform.GetComponent<Image>();
image.color = new Color(0, 229, 255, 233);
}
rank++;
}
}
}

View File

@@ -0,0 +1,637 @@
using DigitalRuby.Tween;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public partial class SpellingBeeController : AbstractMinigameController
{
/// <summary>
/// All of the words that can be used in this session
/// </summary>
//private string[] words;
private List<Learnable> words = new List<Learnable>();
/// <summary>
/// Where we currently are in the word
/// </summary>
private int letterIndex;
/// <summary>
/// Where we currently are in the word list
/// </summary>
private int wordIndex;
/// <summary>
/// The word that is currently being spelled
/// </summary>
private string currentWord;
/// <summary>
/// All of the available themes
/// </summary>
public ThemeList themeList;
/// <summary>
/// The theme we are currently using
/// </summary>
private Theme currentTheme;
/// <summary>
/// Current value of timer in seconds
/// </summary>
private float timerValue;
/// <summary>
/// List of learnables to get the threshold for the letters
/// </summary>
public Theme fingerspelling;
/// <summary>
/// Amount of seconds user gets per letter of the current word
/// Set to 1 for testing; should be increased later
/// </summary>
private const int secondsPerLetter = 5;
/// <summary>
/// Counter that keeps track of how many letters have been spelled correctly
/// </summary>
private int correctLetters;
/// <summary>
/// Counter that keeps track of how many letters have been spelled incorrectly
/// </summary>
private int incorrectLetters;
/// <summary>
/// Counter that keeps track of how many words have been spelled correctly
/// </summary>
private int spelledWords;
/// <summary>
/// Timer that keeps track of when the game was started
/// </summary>
private DateTime startTime;
/// <summary>
/// Letter prefab
/// </summary>
public GameObject letterPrefab;
/// <summary>
/// Reference to letter container
/// </summary>
public Transform letterContainer;
/// <summary>
/// The Image component for displaying the appropriate sprite
/// </summary>
public Image wordImage;
/// <summary>
/// Timer display
/// </summary>
public TMP_Text timerText;
/// <summary>
/// Bonus time display
/// </summary>
public GameObject bonusTimeText;
/// <summary>
/// Timer to display the bonus time
/// </summary>
private float bonusActiveRemaining = 0.0f;
/// <summary>
/// The GameObjects representing the letters
/// </summary>
private List<GameObject> letters = new List<GameObject>();
/// <summary>
/// Reference to the scoreboard
/// </summary>
public Transform Scoreboard;
/// <summary>
/// Reference to the feedback field
/// </summary>
public TMP_Text feedbackText;
/// <summary>
/// Reference to the progress bar image, so we can add fancy colors
/// </summary>
public Image feedbackProgressImage;
/// <summary>
/// Timer to keep track of how long a incorrect sign is performed
/// </summary>
protected DateTime timer;
/// <summary>
/// Current predicted sign
/// </summary>
protected string predictedSign = null;
/// <summary>
/// Previous incorrect sign, so we can keep track whether the user is wrong or the user is still changing signs
/// </summary>
protected string previousIncorrectSign = null;
/// <summary>
/// Reference to display the score
/// </summary>
public TMP_Text scoreDisplay;
/// <summary>
/// Reference to display the points lost/won
/// </summary>
public TMP_Text scoreBonus;
/// <summary>
/// Score obtained when spelling a letter
/// </summary>
private int correctLettersScore = 10;
/// <summary>
/// Score obtained when spelling the wrong letter :o
/// </summary>
private int incorrectLettersScore = -5;
/// <summary>
/// Set the AbstractMinigameController variable to inform it of the theme for the signPredictor
/// </summary>
protected override Theme signPredictorTheme
{
get { return fingerspelling; }
}
/// <summary>
/// Update is called once per frame
/// </summary>
public void Update()
{
if (gameIsActive)
{
timerValue -= Time.deltaTime;
if (bonusActiveRemaining <= 0.0 && bonusTimeText.activeSelf)
{
bonusTimeText.SetActive(false);
scoreBonus.text = "";
}
else
{
bonusActiveRemaining -= Time.deltaTime;
}
if (timerValue <= 0.0f)
{
timerValue = 0.0f;
//ActivateGameOver();
ActivateEnd(false);
}
int minutes = Mathf.FloorToInt(timerValue / 60.0f);
int seconds = Mathf.FloorToInt(timerValue % 60.0f);
timerText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
}
}
/// <summary>
/// Randomly shuffle the list of words
/// </summary>
public void ShuffleWords()
{
for (int i = words.Count - 1; i > 0; i--)
{
// Generate a random index between 0 and i (inclusive)
int j = UnityEngine.Random.Range(0, i + 1);
// Swap the values at indices i and j
(words[j], words[i]) = (words[i], words[j]);
}
}
/// <summary>
/// Calculate the score
/// </summary>
/// <returns>The calculated score</returns>
public override int CalculateScore()
{
return correctLetters * correctLettersScore + incorrectLetters * incorrectLettersScore;
}
/// <summary>
/// Delete all letter objects
/// </summary>
public void DeleteWord()
{
for (int i = 0; i < letters.Count; i++)
{
Destroy(letters[i]);
}
letters.Clear();
}
/// <summary>
/// Adds seconds to timer
/// </summary>
/// <param name="seconds"></param>
public void AddSeconds(int seconds)
{
timerValue += (float)seconds;
bonusTimeText.SetActive(true);
bonusActiveRemaining = 1.0f;
}
/// <summary>
/// Display the next letter
/// </summary>
/// <param name="successful">true if the letter was correctly signed, false otherwise</param>
public void NextLetter(bool successful)
{
if (!gameIsActive) { return; }
// Change color of current letter (skip spaces)
if (successful)
{
correctLetters++;
letters[letterIndex].GetComponent<Image>().color = new Color(0x8b / 255.0f, 0xd4 / 255.0f, 0x5e / 255.0f);
scoreDisplay.text = $"Score: {CalculateScore()}";
scoreBonus.text = $"+{correctLettersScore}";
scoreBonus.color = new Color(0x8b / 255.0f, 0xd4 / 255.0f, 0x5e / 255.0f);
}
else
{
incorrectLetters++;
letters[letterIndex].GetComponent<Image>().color = new Color(0xf5 / 255.0f, 0x49 / 255.0f, 0x3d / 255.0f);
scoreDisplay.text = $"Score: {CalculateScore()}";
scoreBonus.text = $"{incorrectLettersScore}";
scoreBonus.color = new Color(0xf5 / 255.0f, 0x49 / 255.0f, 0x3d / 255.0f);
}
do
{
letterIndex++;
} while (letterIndex < currentWord.Length && currentWord[letterIndex] == ' ');
// Change the color of the next letter or change to new word
if (letterIndex < currentWord.Length)
{
letters[letterIndex].GetComponent<Image>().color = new Color(0x9f / 255.0f, 0xe7 / 255.0f, 0xf5 / 255.0f);
}
else
{
StartCoroutine(Wait());
NextWord();
}
}
/// <summary>
/// Display next word in the series
/// </summary>
public void NextWord()
{
DeleteWord();
spelledWords++;
if (wordIndex < words.Count)
{
currentWord = words[wordIndex].name;
letterIndex = 0;
DisplayWord(currentWord);
wordIndex++;
}
else
{
//ActivateWin();
ActivateEnd(true);
}
}
/// <summary>
/// Displays the word that needs to be spelled
/// </summary>
/// <param name="word">The word to display</param>
public void DisplayWord(string word)
{
for (int i = 0; i < word.Length; i++)
{
// Create instance of prefab
GameObject instance = GameObject.Instantiate(letterPrefab, letterContainer);
letters.Add(instance);
// Dynamically load appearance
char c = Char.ToUpper(word[i]);
Image background = instance.GetComponent<Image>();
background.color = i == 0 ? new Color(0x9f / 255.0f, 0xe7 / 255.0f, 0xf5 / 255.0f) : Color.clear;
TMP_Text txt = instance.GetComponentInChildren<TMP_Text>();
txt.text = Char.ToString(c);
}
wordImage.sprite = words[wordIndex].image;
}
/// <summary>
/// wait for 2 seconds
/// </summary>
/// <returns></returns>
private IEnumerator Wait()
{
yield return new WaitForSecondsRealtime(2);
}
/// <summary>
/// Get the threshold for a given sign
/// </summary>
/// <param name="sign"></param>
/// <returns></returns>
private float GetTresholdPercentage(string sign)
{
Learnable letter = fingerspelling.learnables.Find(l => l.name == sign);
return letter.thresholdPercentage;
}
/*
/// <summary>
/// The updateFunction that is called when new probabilities become available
/// </summary>
/// <returns></returns>
protected override IEnumerator UpdateFeedback()
{
// Get current sign
string currentSign = GetSign();
// Get the predicted sign
if (signPredictor != null && signPredictor.learnableProbabilities != null &&
currentSign != null && signPredictor.learnableProbabilities.ContainsKey(currentSign) && gameIsActive)
{
float accCurrentSign = signPredictor.learnableProbabilities[currentSign];
float thresholdCurrentSign = GetTresholdPercentage(currentSign);
// Get highest predicted sign
string predictedSign = signPredictor.learnableProbabilities.Aggregate((a, b) => a.Value > b.Value ? a : b).Key;
float accPredictSign = signPredictor.learnableProbabilities[predictedSign];
float thresholdPredictedSign = GetTresholdPercentage(predictedSign);
if (feedbackText != null && feedbackProgressImage != null)
{
Color col;
if (accCurrentSign > thresholdCurrentSign)
{
feedbackText.text = "Goed";
col = new Color(0x8b / 255.0f, 0xd4 / 255.0f, 0x5e / 255.0f);
}
else if (accCurrentSign > 0.9 * thresholdCurrentSign)
{
feedbackText.text = "Bijna...";
col = new Color(0xf2 / 255.0f, 0x7f / 255.0f, 0x0c / 255.0f);
}
else if (accPredictSign > thresholdPredictedSign)
{
feedbackText.text = $"Verkeerde gebaar: '{predictedSign}'";
col = new Color(0xf5 / 255.0f, 0x49 / 255.0f, 0x3d / 255.0f);
accCurrentSign = 0.0f;
}
else
{
feedbackText.text = "Detecteren...";
col = new Color(0xf5 / 255.0f, 0x49 / 255.0f, 0x3d / 255.0f);
}
feedbackText.color = col;
feedbackProgressImage.color = col;
float oldValue = feedbackProgress.value;
// use an exponential scale
float newValue = Mathf.Exp(4 * (Mathf.Clamp(accCurrentSign / thresholdCurrentSign, 0.0f, 1.0f) - 1.0f));
feedbackProgress.gameObject.Tween("FeedbackUpdate", oldValue, newValue, 0.2f, TweenScaleFunctions.CubicEaseInOut, (t) =>
{
if (feedbackProgress != null)
{
feedbackProgress.value = t.CurrentValue;
}
});
}
if (accPredictSign > thresholdPredictedSign)
{
// Correct sign
if (predictedSign == currentSign)
{
yield return new WaitForSeconds(0.5f);
PredictSign(predictedSign);
timer = DateTime.Now;
predictedSign = null;
previousIncorrectSign = null;
}
// Incorrect sign
else
{
if (previousIncorrectSign != predictedSign)
{
timer = DateTime.Now;
previousIncorrectSign = predictedSign;
}
else if (DateTime.Now - timer > TimeSpan.FromSeconds(2.0f))
{
PredictSign(predictedSign);
timer = DateTime.Now;
predictedSign = null;
previousIncorrectSign = null;
}
}
}
}
else if (feedbackProgress != null)
{
feedbackProgress.value = 0.0f;
}
yield return null;
}
*/
/// <summary>
/// Function to get the current letter that needs to be signed
/// </summary>
/// <returns>the current letter that needs to be signed</returns>
public string GetSign()
{
if (letterIndex < currentWord.Length)
{
return currentWord[letterIndex].ToString().ToUpper();
}
return null;
}
/// <summary>
/// Function to confirm your prediction and check if it is correct.
/// </summary>
/// <param name="sign"></param>
public void PredictSign(string sign)
{
bool successful = sign.ToUpper() == currentWord[letterIndex].ToString().ToUpper();
if (successful)
{
AddSeconds(secondsPerLetter);
}
NextLetter(successful);
}
/// <summary>
/// The logic to process the signs sent by the signPredictor
/// </summary>
/// <param name="accuracy">The accuracy of the passed sign</param>
/// <param name="predictedSign">The name of the passed sign</param>
protected override void ProcessMostProbableSign(float accuracy, string predictedSign)
{
string currentSign = GetSign();
float accPredictSign = accuracy;
float accCurrentSign = signPredictor.learnableProbabilities[currentSign];
float thresholdCurrentSign = GetTresholdPercentage(currentSign);
float thresholdPredictedSign = GetTresholdPercentage(predictedSign);
// If there is a feedback-object, we wil change its appearance
if (feedbackText != null && feedbackProgressImage != null)
{
Color col;
if (accPredictSign > thresholdCurrentSign)
{
feedbackText.text = "Goed";
col = new Color(0x8b / 255.0f, 0xd4 / 255.0f, 0x5e / 255.0f);
}
else if (accCurrentSign > 0.9 * thresholdCurrentSign)
{
feedbackText.text = "Bijna...";
col = new Color(0xf2 / 255.0f, 0x7f / 255.0f, 0x0c / 255.0f);
}
else if (accPredictSign > thresholdPredictedSign)
{
feedbackText.text = $"Verkeerde gebaar: '{predictedSign}'";
col = new Color(0xf5 / 255.0f, 0x49 / 255.0f, 0x3d / 255.0f);
accCurrentSign = 0.0f;
}
else
{
feedbackText.text = "Detecteren...";
col = new Color(0xf5 / 255.0f, 0x49 / 255.0f, 0x3d / 255.0f);
}
feedbackText.color = col;
feedbackProgressImage.color = col;
float oldValue = feedbackProgress.value;
// use an exponential scale
float newValue = Mathf.Exp(4 * (Mathf.Clamp(accCurrentSign / thresholdCurrentSign, 0.0f, 1.0f) - 1.0f));
feedbackProgress.gameObject.Tween("FeedbackUpdate", oldValue, newValue, 0.2f, TweenScaleFunctions.CubicEaseInOut, (t) =>
{
if (feedbackProgress != null)
{
feedbackProgress.value = t.CurrentValue;
}
});
}
// The logic for the internal workings of the game
if (accPredictSign > thresholdPredictedSign)
{
// Correct sign, instantly pass it along
if (predictedSign == currentSign)
{
PredictSign(predictedSign);
timer = DateTime.Now;
predictedSign = null;
previousIncorrectSign = null;
}
// Incorrect sign, wait a bit before passing it along
else
{
if (previousIncorrectSign != predictedSign)
{
timer = DateTime.Now;
previousIncorrectSign = predictedSign;
}
else if (DateTime.Now - timer > TimeSpan.FromSeconds(2.0f))
{
PredictSign(predictedSign);
timer = DateTime.Now;
predictedSign = null;
previousIncorrectSign = null;
}
}
}
}
/// <summary>
/// The logic to set the scoreboard of spellingbee
/// </summary>
/// <param name="victory">SHows whether or not the player won</param>
protected override void SetScoreBoard(bool victory)
{
string resultTxt;
if (victory)
{
resultTxt = "GEWONNEN";
}
else
{
resultTxt = "VERLOREN";
}
// Save the scores and show the scoreboard
gameEndedPanel.GetComponent<SpellingBeeGameEndedPanel>().GenerateContent(
startTime: startTime,
totalWords: spelledWords,
correctLetters: correctLetters,
incorrectLetters: incorrectLetters,
result: resultTxt,
score: CalculateScore()
);
}
/// <summary>
/// The spellinbee-specific logic that needs to be called at the start of the game
/// </summary>
protected override void StartGameLogic()
{
correctLetters = 0;
incorrectLetters = 0;
words.Clear();
// We use -1 instead of 0 so SetNextWord can simply increment it each time
spelledWords = -1;
wordIndex = 0;
gameIsActive = true;
timerValue = 30.0f;
bonusActiveRemaining = 0.0f;
startTime = DateTime.Now;
gameEndedPanel.SetActive(false);
bonusTimeText.SetActive(false);
currentTheme = minigame.themeList.themes[minigame.themeList.currentThemeIndex];
//feedback.signPredictor.SetModel(currentTheme.modelIndex);
words.AddRange(currentTheme.learnables);
ShuffleWords();
NextWord();
scoreDisplay.text = $"Score: {CalculateScore()}";
scoreBonus.text = "";
}
/// <summary>
/// The spellingbee-specific logic that needs to be called at the end of a game
/// </summary>
/// <param name="victory"></param>
protected override void EndGameLogic(bool victory)
{
gameIsActive = false;
DeleteWord();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 44fbed5ae228de39b9f727def7578d06
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
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;
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();
}
}

View File

@@ -6,8 +6,10 @@
"GUID:1631ed2680c61245b8211d943c1639a8",
"GUID:3444c67d5a3a93e5a95a48906078c372",
"GUID:d0b6b39a21908f94fbbd9f2c196a9725",
"GUID:5c2b5ba89f9e74e418232e154bc5cc7a",
"GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25"
"GUID:58e104b97fb3752438ada2902a36dcbf",
"GUID:e83ddf9a537a96b4a804a16bb7872ec1",
"GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25",
"GUID:403dd94a93598934eb522dc36df43d7b"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -1,7 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using System.Collections;
using UnityEngine.TestTools;
public class BasicTests