From a63898b242a9ab23232a709db1418a3e4958057a Mon Sep 17 00:00:00 2001 From: Krishna Date: Sat, 16 Jul 2022 03:11:12 -0400 Subject: [PATCH 1/7] got anagram showing for final score --- .../Scripts/Dictionaries/DictionaryObject.cs | 25 +++++++++++++++++++ .../Dictionaries/DictionaryObject.cs.meta | 3 ++- Assets/Scripts/Word.cs | 7 ++++++ Assets/Scripts/WordEvaluator.cs | 5 ++++ Assets/Scripts/WordEvaluator.cs.meta | 3 ++- 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Dictionaries/DictionaryObject.cs b/Assets/Scripts/Dictionaries/DictionaryObject.cs index e7a443b..03c5cf1 100644 --- a/Assets/Scripts/Dictionaries/DictionaryObject.cs +++ b/Assets/Scripts/Dictionaries/DictionaryObject.cs @@ -11,6 +11,7 @@ public class DictionaryObject : ScriptableObject //List with each word sorted in alphabetical order - for matching anagrams private List fullListWithSortedChars; [SerializeField] private bool isWordCheck = false; + private Dictionary> Anagrams; private void OnEnable() { @@ -21,6 +22,7 @@ public void GenerateDictionaries() { string allWords = wordList.text; fullList = new List(); + Anagrams = new Dictionary>(); if (isWordCheck) { @@ -28,7 +30,15 @@ public void GenerateDictionaries() fullListWithSortedChars = new List(); foreach (string word in allWords.Split("\n"[0])) { + string anagram = GetWordWithSortedChars(word.Trim()); fullList.Add(word.Trim()); + if(Anagrams.ContainsKey(anagram)){ + + Anagrams[anagram].Add(word.Trim()); + } + else{ + Anagrams.Add(anagram,new List{word.Trim()}); + } fullListWithSortedChars.Add(GetWordWithSortedChars(word.Trim())); } } @@ -36,7 +46,15 @@ public void GenerateDictionaries() { foreach (string word in allWords.Split("\n"[0])) { + string anagram = GetWordWithSortedChars(word.Trim()); fullList.Add(word.Trim()); + if(Anagrams.ContainsKey(anagram)){ + + Anagrams[anagram].Add(word.Trim()); + } + else{ + Anagrams.Add(anagram,new List{word.Trim()}); + } fullListWithSortedChars.Add(GetWordWithSortedChars(word.Trim())); } } @@ -69,4 +87,11 @@ public string GetWordWithSortedChars(string input) System.Array.Sort(characters); return new string(characters); } + public string getAnagram(string input){ + char[] characters = input.ToCharArray(); + System.Array.Sort(characters); + string anagram = new string(characters); + List anagramWords = Anagrams.GetValueOrDefault(anagram, new List{""}); + return anagramWords[0]; + } } diff --git a/Assets/Scripts/Dictionaries/DictionaryObject.cs.meta b/Assets/Scripts/Dictionaries/DictionaryObject.cs.meta index a0146e6..715ff53 100644 --- a/Assets/Scripts/Dictionaries/DictionaryObject.cs.meta +++ b/Assets/Scripts/Dictionaries/DictionaryObject.cs.meta @@ -3,7 +3,8 @@ guid: 5c847a091c5c85342aaefe3ea15b6da2 MonoImporter: externalObjects: {} serializedVersion: 2 - defaultReferences: [] + defaultReferences: + - wordList: {fileID: 4900000, guid: 9d5b95b3bb625954987ae99c85010d57, type: 3} executionOrder: 0 icon: {instanceID: 0} userData: diff --git a/Assets/Scripts/Word.cs b/Assets/Scripts/Word.cs index 13d8879..82430c3 100644 --- a/Assets/Scripts/Word.cs +++ b/Assets/Scripts/Word.cs @@ -309,4 +309,11 @@ public void setMultiplier(int multi) { multiplier = multi; } + + public void setWord(string newWord){ + word = newWord; + } + public string getWord(){ + return word; + } } diff --git a/Assets/Scripts/WordEvaluator.cs b/Assets/Scripts/WordEvaluator.cs index ec50a7d..3c4292c 100644 --- a/Assets/Scripts/WordEvaluator.cs +++ b/Assets/Scripts/WordEvaluator.cs @@ -7,6 +7,7 @@ public class WordEvaluator : MonoBehaviour [SerializeField] private DictionaryObject dictionaries; private Hashtable letterValues; + private Word word1; void Awake() { @@ -43,6 +44,10 @@ public bool IsValidWord(string word) { //if anagram powerup is activated check if word matches if(Anagram.isActivated()){ + word1 = GameObject.Find("Word").GetComponent(); + Debug.Log("isValidWord " + word1.getWord()); + Debug.Log("anagram is " + dictionaries.getAnagram(word)); + word1.setWord(dictionaries.getAnagram(word)); return dictionaries.VerifyWordAnagram(word); } return dictionaries.VerifyWord(word); diff --git a/Assets/Scripts/WordEvaluator.cs.meta b/Assets/Scripts/WordEvaluator.cs.meta index 2416540..50616c7 100644 --- a/Assets/Scripts/WordEvaluator.cs.meta +++ b/Assets/Scripts/WordEvaluator.cs.meta @@ -3,7 +3,8 @@ guid: 19acefb944f5173428a0bc249c60cb66 MonoImporter: externalObjects: {} serializedVersion: 2 - defaultReferences: [] + defaultReferences: + - dictionaries: {fileID: 11400000, guid: ac5a4e937cb790b49b98d3fa6336db62, type: 2} executionOrder: 0 icon: {instanceID: 0} userData: From dbc579a616149c391f635d73c7eb8d421154c7da Mon Sep 17 00:00:00 2001 From: Krishna Date: Sat, 16 Jul 2022 23:40:30 -0400 Subject: [PATCH 2/7] added changeWord method --- Assets/Scripts/Word.cs | 11 +++++++++++ Assets/Scripts/Word.cs.meta | 13 ++++++++++++- Assets/Scripts/WordEvaluator.cs | 6 +++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Word.cs b/Assets/Scripts/Word.cs index 82430c3..d6ac44e 100644 --- a/Assets/Scripts/Word.cs +++ b/Assets/Scripts/Word.cs @@ -316,4 +316,15 @@ public void setWord(string newWord){ public string getWord(){ return word; } + public void changeWord(string newWord){ + word = newWord; + letters.Clear(); + currentLetterBox = 0; + foreach(char c in newWord){ + LetterClass newLetter = new LetterClass(); + newLetter.setLetter(c); + sprites[currentLetterBox].sprite = newLetter.image; + currentLetterBox++; + } + } } diff --git a/Assets/Scripts/Word.cs.meta b/Assets/Scripts/Word.cs.meta index f4af191..0f73573 100644 --- a/Assets/Scripts/Word.cs.meta +++ b/Assets/Scripts/Word.cs.meta @@ -3,7 +3,18 @@ guid: afb8356c32890634d9fab4e7f9ade398 MonoImporter: externalObjects: {} serializedVersion: 2 - defaultReferences: [] + defaultReferences: + - evaluator: {instanceID: 0} + - defaultSprite: {instanceID: 0} + - letterArray: {fileID: 11400000, guid: ef5719dd68ea5664f9107c00c3aeb3a5, type: 2} + - timer: {instanceID: 0} + - scoreManager: {instanceID: 0} + - arrows: {instanceID: 0} + - analyticsManager: {instanceID: 0} + - addScoreAmountLeft: {instanceID: 0} + - addScoreAmountRight: {instanceID: 0} + - wordSubmitSound: {instanceID: 0} + - wordClearSound: {instanceID: 0} executionOrder: 0 icon: {instanceID: 0} userData: diff --git a/Assets/Scripts/WordEvaluator.cs b/Assets/Scripts/WordEvaluator.cs index 3c4292c..5a14548 100644 --- a/Assets/Scripts/WordEvaluator.cs +++ b/Assets/Scripts/WordEvaluator.cs @@ -47,7 +47,11 @@ public bool IsValidWord(string word) word1 = GameObject.Find("Word").GetComponent(); Debug.Log("isValidWord " + word1.getWord()); Debug.Log("anagram is " + dictionaries.getAnagram(word)); - word1.setWord(dictionaries.getAnagram(word)); + // word1.setWord(dictionaries.getAnagram(word)); + if(dictionaries.VerifyWordAnagram(word)){ + word1.changeWord(dictionaries.getAnagram(word)); + } + return dictionaries.VerifyWordAnagram(word); } return dictionaries.VerifyWord(word); From c6bfa375988f32f80647d3bc598fef33dcdd71d5 Mon Sep 17 00:00:00 2001 From: Krishna Date: Sat, 16 Jul 2022 23:53:36 -0400 Subject: [PATCH 3/7] added letter object array to Word.cs --- Assets/Scripts/Word.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Word.cs b/Assets/Scripts/Word.cs index d6ac44e..e9b34c7 100644 --- a/Assets/Scripts/Word.cs +++ b/Assets/Scripts/Word.cs @@ -10,6 +10,7 @@ public class Word : MonoBehaviour [SerializeField] private WordEvaluator evaluator; [SerializeField] private Sprite defaultSprite; + [SerializeField] LetterObjectArray letterArray; [SerializeField] public List sprites = new List(); @@ -321,8 +322,7 @@ public void changeWord(string newWord){ letters.Clear(); currentLetterBox = 0; foreach(char c in newWord){ - LetterClass newLetter = new LetterClass(); - newLetter.setLetter(c); + LetterClass newLetter = letterArray.GetLetter(c - 'a' + 1); sprites[currentLetterBox].sprite = newLetter.image; currentLetterBox++; } From fcf948629a9f3e70a37f0dc58b8156c1218102c9 Mon Sep 17 00:00:00 2001 From: Krishna Date: Sun, 17 Jul 2022 18:57:25 -0400 Subject: [PATCH 4/7] anagram fully works --- Assets/Scripts/Word.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Word.cs b/Assets/Scripts/Word.cs index e9b34c7..b475fab 100644 --- a/Assets/Scripts/Word.cs +++ b/Assets/Scripts/Word.cs @@ -319,9 +319,13 @@ public string getWord(){ } public void changeWord(string newWord){ word = newWord; + string newWordLower = newWord.ToLower(); letters.Clear(); currentLetterBox = 0; - foreach(char c in newWord){ + foreach(char c in newWordLower){ + Debug.Log("char of anagram is " + c); + int index = c - 'a' + 1; + Debug.Log(index); LetterClass newLetter = letterArray.GetLetter(c - 'a' + 1); sprites[currentLetterBox].sprite = newLetter.image; currentLetterBox++; From d886d11f22ed9a46825bbe193b1050d44e3a3230 Mon Sep 17 00:00:00 2001 From: Krishna Date: Sun, 17 Jul 2022 23:12:53 -0400 Subject: [PATCH 5/7] deactivate's anagram after word submit --- Assets/Scripts/Word.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Word.cs b/Assets/Scripts/Word.cs index b475fab..a18686c 100644 --- a/Assets/Scripts/Word.cs +++ b/Assets/Scripts/Word.cs @@ -190,7 +190,11 @@ private IEnumerator sidebarBounce(float bounceRate) public int submitWord(string wallSide) { // Check validity and get word score // If valid, clear list - + if(Anagram.isActivated()){ + Anagram.reset(); + Shop_Purchase.deActiatePowerUpUI("Anagram"); + Debug.Log("Anagram reset"); + } totalSubmissions++; totalWordLength += word.Length; From edbf1d38ae02eb491fc3ba971741e5f931587f72 Mon Sep 17 00:00:00 2001 From: Krishna Date: Sun, 17 Jul 2022 23:52:29 -0400 Subject: [PATCH 6/7] fixed typo in activatePowerupUI --- Assets/Scripts/PlayerController.cs | 12 ++++++------ Assets/Scripts/UI/Shop_Purchase.cs | 18 +++++++++--------- Assets/Scripts/Word.cs | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 430a37b..877e44d 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -322,7 +322,7 @@ void Update() // activate shop item power up in this code block Debug.Log("player uses item number 1 - Stop Time"); StartCoroutine(StopTime()); - Shop_Purchase.actiatePowerUpUI("PauseTime"); + Shop_Purchase.activatePowerUpUI("PauseTime"); CurrencyUtils.displayQuantityDynamic("1","Text_PauseTime_Qty","x: "); } else @@ -339,7 +339,7 @@ void Update() { Debug.Log("player uses item number 2"); lives++; - Shop_Purchase.actiatePowerUpUI("ExtraLife"); + Shop_Purchase.activatePowerUpUI("ExtraLife"); CurrencyUtils.displayQuantityDynamic("2","Text_ExtraLife_Qty","x: "); } } @@ -354,7 +354,7 @@ void Update() // TwoX temp_twoX = new TwoX(); TwoX temp_twoX = ScriptableObject.CreateInstance(); temp_twoX.Activate(); - Shop_Purchase.actiatePowerUpUI("ScoreMultiplier"); + Shop_Purchase.activatePowerUpUI("ScoreMultiplier"); CurrencyUtils.displayQuantityDynamic("3","Text_ScoreMultiplier_Qty","x: "); } } @@ -366,7 +366,7 @@ void Update() if (CurrencyUtils.useShopItem("4")) { Anagram.Activate(); - Shop_Purchase.actiatePowerUpUI("Anagram"); + Shop_Purchase.activatePowerUpUI("Anagram"); Debug.Log("player uses item number 4"); CurrencyUtils.displayQuantityDynamic("4","Text_Anagram_Qty","x: "); @@ -382,7 +382,7 @@ void Update() // timer.StopTimer() StartCoroutine(StopTime()); // timer.StartTimer(); - Shop_Purchase.actiatePowerUpUI("PauseTime"); + Shop_Purchase.activatePowerUpUI("PauseTime"); Debug.Log("player uses item number 5"); } @@ -441,7 +441,7 @@ public IEnumerator StopTime() if (!timer.isTimerRunning()) { timer.StartTimer(); } - Shop_Purchase.deActiatePowerUpUI("PauseTime"); + Shop_Purchase.deactivatePowerUpUI("PauseTime"); } private void InitiateBounce() diff --git a/Assets/Scripts/UI/Shop_Purchase.cs b/Assets/Scripts/UI/Shop_Purchase.cs index c5bb6a2..da7b2eb 100644 --- a/Assets/Scripts/UI/Shop_Purchase.cs +++ b/Assets/Scripts/UI/Shop_Purchase.cs @@ -43,17 +43,17 @@ public void displayCurrency(){ CurrencyUtils.displayQuantity("4"); } - public static void actiatePowerUpUI(String powerupName) { + public static void activatePowerUpUI(String powerupName) { Color color = new Color(0, 128, 0); - actiatePowerUpUIWithColor(powerupName,color); + activatePowerUpUIWithColor(powerupName,color); } - public static void deActiatePowerUpUI(String powerupName) { + public static void deactivatePowerUpUI(String powerupName) { Color color = new Color(242, 140, 128); - actiatePowerUpUIWithColor(powerupName,color); + activatePowerUpUIWithColor(powerupName,color); } - public static void actiatePowerUpUIWithColor(String powerupName, Color newColor) { + public static void activatePowerUpUIWithColor(String powerupName, Color newColor) { GameObject inputFieldGo = GameObject.Find("Button_" + powerupName); Button inputFieldCo2 = inputFieldGo.GetComponent