// Populates the info panel with the word, its definition... private void PopulateInfoPanel(GameObject panel, Utility.Word wordInfo) { Text[] texts = panel.GetComponentsInChildren <Text>(); Text wordTxt = texts[0]; Text translationTxt = texts[1]; Text defintionTxt = texts[2]; wordTxt.text = Utility.ToUpperOnFirstLetter(wordInfo.name); translationTxt.text = Utility.ToUpperOnFirstLetter(wordInfo.translation); defintionTxt.text = wordInfo.definition; string wordLanguage = wordInfo.language.ToString().ToLower(); string translationLanguage = ""; if (wordLanguage.Equals("fr")) { translationLanguage = "en"; } else if (wordLanguage.Equals("en")) { translationLanguage = "fr"; } Button[] buttons = panel.GetComponentsInChildren <Button>(); Button wordBtn = buttons[0]; Button translationBtn = buttons[1]; wordBtn.onClick.AddListener(() => SpeakWord(wordInfo.name + "_" + wordLanguage)); translationBtn.onClick.AddListener(() => SpeakWord(wordInfo.translation + "_" + translationLanguage)); }
// Words public Utility.Word VerifyWord(string input) { input = input.ToUpper(); currentWordUI.text = Utility.GetWordColoring(currentWord.name.ToUpper(), input); // If the user's input matches exactly the enemy's word if (currentWord.name.ToUpper() == input) { target.SendMessage("Hit", realTransform); Utility.Word tmp = currentWord; // Update the word straight away if (getCurrentLife() > 1) { words.Pop(); UpdateCurrentWord(); } return(tmp); } // The player's input matches at least the beginning of this word if (currentWord.name.ToUpper().StartsWith(input)) { // Thus it isn't accounted as an error or typo Enemy.correctInput = true; } return(null); }
public void UpdateCurrentWord() { if (words != null) { currentWord = words.Peek(); currentWordUI.text = currentWord.name.ToUpper(); } }
public void AddWord(Utility.Word word) { word.language = Glossary.language; word.translation = Utility.GetWordTranslation(type, word); if (!words.Contains(word)) { words.Push(word); maxLife += 1; currentLife += 1; } }
// Checks if the current word corresponds to one of the enemies' words private void CheckWords() { Utility.Word word = null; // Just for initialisation Enemy.Type type = Enemy.Type.SPIDER; Enemy.correctInput = false; bool fullMatch = false; foreach (GameObject e in gameManagerScript.GetEnemies()) { if ((word = e.GetComponentInChildren <Enemy>().VerifyWord(GetCurrentText())) != null) { type = e.GetComponentInChildren <Enemy>().GetCreatureType(); } if (word != null) { correctWords.Add(word); fullMatch = true; gameManagerScript.nbCorrectWords++; // stats } } // We made a typo if none of the enemies words start with our input if (!Enemy.correctInput && !fullMatch && Input.inputString[0] != '\b') { Camera.main.SendMessage("Typo"); // We count it as an error only if the last input wasn't one if (lastInput) { GameManager.instance.nbErrors++; } } // At least one hit if (fullMatch) { SetCurrentText(""); lastInput = true; } else { lastInput = Enemy.correctInput; } }