IEnumerator ShowCode(bool single, bool checkEquality, ArrayList codeToShow, Text textField) { float pause = 0.5f; string allLinesSolution = ""; int x = 0; foreach (string line in codeToShow) { Debug.Log("Number of rows to swap is " + levelController.Current.solutionSwap.Count); if (levelController.Current.solutionSwap.Count > 0) { string newLine = line; foreach (string swapLine in levelController.Current.solutionSwap) { string[] patterns = swapLine.Split(':'); Debug.Log("replace " + patterns[0] + " with " + patterns[1]); newLine = newLine.Replace(patterns[0], patterns[1]); } allLinesSolution += newLine + "\n"; } else { allLinesSolution += line + "\n"; } if (!single) { yield return(new WaitForSeconds(pause)); } textField.text = allLinesSolution; // if the lines match, give gold. if (x < allCode.Count && line == allCode[x].ToString()) { TotalGold.GetComponent <Text>().text = (int.Parse(TotalGold.GetComponent <Text>().text) + 25).ToString(); } x++; } }
IEnumerator showStars(int numStars) { float pause = 0.85f; yield return(new WaitForSeconds(pause)); // get current # of stars earned and show it here int totalStars = PlayerPrefs.GetInt("totalStars"); TotalStars.GetComponent <Text>().text = "" + totalStars; float tempGold = 0; float starGold = 100; switch (numStars) { case 1: Star1Fill.SetActive(true); tempGold = float.Parse(TotalGold.GetComponent <Text>().text) + starGold * .25f; PlayerPrefs.SetInt("totalGold", (int)tempGold); TotalGold.GetComponent <Text>().text = tempGold.ToString("N0"); break; case 2: Star1Fill.SetActive(true); tempGold = float.Parse(TotalGold.GetComponent <Text>().text) + starGold * .25f; PlayerPrefs.SetInt("totalGold", (int)tempGold); TotalGold.GetComponent <Text>().text = tempGold.ToString("N0"); yield return(new WaitForSeconds(pause)); Star2Fill.SetActive(true); tempGold = float.Parse(TotalGold.GetComponent <Text>().text) + starGold * .6f; PlayerPrefs.SetInt("totalGold", (int)tempGold); TotalGold.GetComponent <Text>().text = tempGold.ToString("N0"); break; case 3: Star1Fill.SetActive(true); tempGold = float.Parse(TotalGold.GetComponent <Text>().text) + starGold * .25f; PlayerPrefs.SetInt("totalGold", (int)tempGold); TotalGold.GetComponent <Text>().text = tempGold.ToString("N0"); yield return(new WaitForSeconds(pause)); Star2Fill.SetActive(true); tempGold = float.Parse(TotalGold.GetComponent <Text>().text) + starGold * .6f; PlayerPrefs.SetInt("totalGold", (int)tempGold); TotalGold.GetComponent <Text>().text = tempGold.ToString("N0"); yield return(new WaitForSeconds(pause)); Star3Fill.SetActive(true); Star1Fill.SetActive(true); tempGold = float.Parse(TotalGold.GetComponent <Text>().text) + starGold; PlayerPrefs.SetInt("totalGold", (int)tempGold); TotalGold.GetComponent <Text>().text = tempGold.ToString("N0"); break; default: break; } Text textPlayer = textCodePlayer.GetComponent <Text>(); StartCoroutine(ShowCode(false, false, allCode, textPlayer)); yield return(new WaitForSeconds(pause * allCode.Count)); Text textCode = textCodeSolution.GetComponent <Text>(); StartCoroutine(ShowCode(false, true, levelController.Current.solutionCode, textCode)); }