Example #1
0
    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++;
        }
    }
Example #2
0
    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));
    }
Example #3
0
        public async System.Threading.Tasks.Task <bool> BuyAsync(InventoryItemsModel items, int typecase, string ChoItem, bool test = false)
        {
            foreach (ItemModel item in Characters.Characters)
            {
                if (ChoItem == item.item)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", "Already have this Character", "Close");

                    return(false);
                }
            }

            int CurrentGold = CurrentGold = Int32.Parse(UserModel.CheckForstring(items.Localfile, "Gold:"));
            int Price       = 0;
            int TotalGold;

            if (typecase == 0)
            {
                Price = WeaponInfoModel.ObtainWeaponValue(ChoItem);
            }
            else if (typecase == 1)
            {
                Price = ItemInfoModel.ObtainItemValue(ChoItem);
            }
            else
            {
                Price = 50;
            }
            TotalGold = CurrentGold - Price;
            if (CurrentGold - Price >= 0)
            {
                if (typecase == 0)
                {
                    UserModel.AddOntoLine("Weapons:", ChoItem + ",", items.Localfile);
                    try
                    {
                        items.Invfile.Object.Weapons += ChoItem + ",";
                    }catch { }
                    Weapon.Rebuild();
                }
                else if (typecase == 1)
                {
                    UserModel.AddOntoLine("Items:", ChoItem + ",", items.Localfile);
                    try
                    {
                        items.Invfile.Object.Items += ChoItem + ",";
                    }catch { }
                    Inv.Rebuild();
                }
                else
                {
                    UserModel.AddOntoLine("Characters:", ChoItem + ",", items.Localfile);
                    try
                    {
                        items.Invfile.Object.Characters += ChoItem + ",";
                    }
                    catch { }
                    Characters.Rebuild();
                }
                UserModel.Rewrite("Gold:", TotalGold.ToString(), items.Localfile); //Rewrite the gold values
                try
                {
                    items.Invfile.Object.Gold = TotalGold.ToString();
                    await items.UpdateInv();
                }
                catch { }
                Gold = UserModel.CheckForstring(items.Localfile, "Gold:");
                if (!test)
                {
                    await Application.Current.MainPage.DisplayAlert("Success", string.Format("You bought a {0}.", ChoItem), "Close");
                }
                return(true);
            }
            else
            {
                int remainder = CurrentGold - Price;
                remainder = remainder * -1;
                if (!test)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", string.Format("You need {0} more gold to purchase this item", remainder.ToString()), "Close");
                }
                return(false);
            }
        }