void SaveLevelInfo(int worldIndex, float p_levelScore, float p_levelMaxScore)
    {
        float goldAmount = GM.GetGold() * PE.GetGoldMultiplier();

        FH.WriteGoldAmount(goldAmount.ToString());

        bool p_completed;

        if (m_score > GM.GetMedalValue(0) * maxScore)
        {
            p_completed = true;
        }
        else
        {
            p_completed = false;
        }

        string fileDirectory;

        fileDirectory = "/world_" + worldIndex.ToString() + "_data.txt";
        fileDirectory = Application.dataPath + fileDirectory;
        if (!File.Exists(fileDirectory)) // If the file is there
        {
            int index = Application.loadedLevel;
            for (int u = 0; u < 10; u++)
            {
                System.IO.File.WriteAllText(fileDirectory, "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n ");
            }
            var lines = File.ReadAllLines(fileDirectory);
            lines[index] = Convert.ToInt32(p_completed).ToString() + ':' + p_levelScore.ToString() + ':' + p_levelMaxScore.ToString();
            File.WriteAllLines(fileDirectory, lines);
        }
        else
        {
            int index = Application.loadedLevel;
            var lines = File.ReadAllLines(fileDirectory);
            lines[index] = Convert.ToInt32(p_completed).ToString() + ':' + p_levelScore.ToString() + ':' + p_levelMaxScore.ToString();
            File.WriteAllLines(fileDirectory, lines);
        }
    }
Esempio n. 2
0
    void DisplayPotionInfo(bool active, int index, bool isBought)
    {
        potion_info_BG.gameObject.SetActive(active);
        accept.gameObject.SetActive(active);
        decline.gameObject.SetActive(active);
        potion_info_Picture.gameObject.SetActive(active);
        potion_info_Picture.sprite = l_potionTypes[l_Inventory[index].m_potionType].GetComponent <SpriteRenderer>().sprite;

        for (int i = 0; i < 2; i++)
        {
            m_texts[i].enabled = active;
        }

        m_texts[0].text = "Cost: " + l_Inventory[index].m_goldCost.ToString();
        m_texts[1].text = l_Inventory[index].m_description;

        if (Input.GetMouseButton(0))
        {
            Ray toMouse     = Camera.main.ScreenPointToRay(Input.mousePosition);
            int layer_mask  = LayerMask.GetMask("button");
            int potion_mask = LayerMask.GetMask("potion");
            if (Physics2D.Raycast(toMouse.origin, toMouse.direction, 999f, layer_mask))
            {
                Transform obj = Physics2D.Raycast(toMouse.origin, toMouse.direction).transform;
                if (obj.name == "potion_accept")
                {
                    for (int i = 0; i < l_Inventory.Count; i++)
                    {
                        if (l_Inventory[i].m_obj.transform == selectedTransform && l_Inventory[i].m_unlocked)
                        {
                            if (m_gold >= l_Inventory[i].m_goldCost && !l_Inventory[i].m_bought)
                            {
                                m_gold = m_gold - l_Inventory[i].m_goldCost;
                                InvetoryPotion inv = new InvetoryPotion();
                                inv          = l_Inventory[i];
                                inv.m_bought = true;
                                SpriteRenderer sr = inv.m_obj.GetComponent <SpriteRenderer>();
                                sr.color = new Color(sr.color.r, sr.color.g, sr.color.b, 1.0f);
                                selectedTransformIndex = i;
                                l_Inventory[i]         = inv;

                                potionSelected    = false;
                                selectedTransform = null;
                                FH.WriteGoldAmount(m_gold.ToString());
                                FH.WriteInventory(i, 1, 1, l_Inventory[i].m_potionType, l_Inventory[i].m_goldCost, l_Inventory[i].m_originalPos);
                                break;
                            }
                            else if (m_gold < l_Inventory[i].m_goldCost)
                            {
                                Debug.Log("cant afford");
                                break;
                            }
                        }
                    }
                }
                else if (obj.name == "potion_decline")
                {
                    potionSelected    = false;
                    selectedTransform = null;
                }
            }
            if (Physics2D.Raycast(toMouse.origin, toMouse.direction, 999f, potion_mask))
            {
                Transform obj = Physics2D.Raycast(toMouse.origin, toMouse.direction).transform;
                for (int i = 0; i < l_Inventory.Count; i++)
                {
                    if (l_Inventory[i].m_obj == obj.gameObject && l_Inventory[i].m_unlocked && selectedTransform == null)
                    {
                        selectedTransformIndex = i;
                        ableToMove             = true;
                        selectedTransform      = obj;
                    }
                }
                if (obj == null)
                {
                    Debug.Log("null");
                    potionSelected         = false;
                    selectedTransform      = null;
                    selectedTransformIndex = 0;
                }
            }
        }
    }