Пример #1
0
    /**
     *	Unit test of the FindData function
     */
    void TestFindData()
    {
        print("TestFindData...");
        Dictionary <string, float> data;
        PlayerData newPlayer;

        CreateFile();

        //Empty file
        data = DataFileManager.FindData("Test", path);
        Assert.AreEqual(null, data, string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Data should not exist"));

        //Add a player
        newPlayer = new PlayerData("Test", 1, 2, 4, 4, 0, 0, 1, 0, 0);
        DataFileManager.AddNewPlayer(newPlayer, path);
        data = DataFileManager.FindData("Test", path);
        Assert.AreEqual(0.25f, data["platform7"], string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 0.25!"));

        //Add an other player
        newPlayer = new PlayerData("Test", 2, 1, 12, 3, 0, 1, 0, 0, 0);
        DataFileManager.AddNewPlayer(newPlayer, path);
        newPlayer = new PlayerData("Test2", 1, 2, 3, 4, 0, 0, 0, 1, 0);
        DataFileManager.AddNewPlayer(newPlayer, path);
        data = DataFileManager.FindData("Test", path);
        Assert.AreEqual(0.0625f, data["platform7"], string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>", (byte)(255), (byte)(0), (byte)(0), "...FAILED : Value should be 0.0625!"));

        DeleteFile();
    }
Пример #2
0
    /**
     *  Select the next platform depending of the part of the body
     */
    protected void AdaptProbabilities()
    {
        string playerName = PlayerPrefs.GetString("PlayerName");
        Dictionary <string, float> data = DataFileManager.FindData(playerName);

        if (data == null)
        {
            return;
        }
        float adjustment = 0.90f;

        foreach (KeyValuePair <string, float> entry in data)
        {
            if (entry.Value >= 0.5)
            {
                int index1 = -1;
                for (int i = 0; i < platformsList.Length; i++)
                {
                    if (platformsList[i].name == entry.Key)
                    {
                        index1 = i;
                        break;
                    }
                }
                if (index1 != -1)
                {
                    int index2 = -1;
                    for (int i = 0; i < platformsList.Length; i++)
                    {
                        if (platformsList[i].GetComponent <PrefabController>().myType == platformsList[index1].GetComponent <PrefabController>().myType&& platformsList[i].tag == "coinPlatform")
                        {
                            index2 = i;
                            break;
                        }
                    }
                    if (index2 != -1)
                    {
                        int diffWeight = System.Convert.ToInt32(platformsList[index1].GetComponent <PrefabController>().InitialSpawnWeight *(entry.Value * adjustment));
                        platformsList[index1].GetComponent <PrefabController>().Weight = platformsList[index1].GetComponent <PrefabController>().Weight - diffWeight;
                        platformsList[index2].GetComponent <PrefabController>().Weight = platformsList[index2].GetComponent <PrefabController>().Weight + diffWeight;
                    }
                }
            }
        }
    }