示例#1
0
    public IEnumerator attribute_Test_rw_file_WithEnumeratorPasses()
    {
        UnityEngine.SceneManagement.SceneManager.LoadScene("Untitled");
        SetCharacter.istest = true;
        yield return(null);

        /// init GameObject
        GameObject hero = SetCharacter.hero;

        Assert.AreNotEqual(hero, null);
        hero.transform.position = new Vector3(12, 0, 15);
        hero.transform.rotation = Quaternion.identity;

        /// init script test
        yield return(null);

        attribute testcs = hero.GetComponent <attribute> ();

        Assert.IsTrue(testcs.ifAlive);

        /// test SaveAttributeInFile
        /// test ReadAttributeFromFile
        testcs.gold = 99999f;
        testcs.SaveAttributeInFile();
        testcs.gold = 0f;
        Assert.GreaterOrEqual(1e-5, Math.Abs(testcs.gold - 0f));
        testcs.ReadAttributeFromFile();
        Assert.GreaterOrEqual(1e-5, Math.Abs(testcs.gold - 99999f));

        /// test GetLevelOfPlayerFromFile
        /// test GetGoldOfPlayerFromFile
        /// test GetTypeOfPlayerFromFile
        /// test GetLevelOfGameFromFile
        testcs.Level     = 99999f;
        testcs.gold      = 99999f;
        testcs.ZhiYe     = "xx";
        testcs.level_num = 99999;
        testcs.SaveAttributeInFile();
        testcs.Level     = 0f;
        testcs.gold      = 0f;
        testcs.ZhiYe     = "000";
        testcs.level_num = 0;
        Assert.GreaterOrEqual(1e-5, Math.Abs(testcs.GetLevelOfPlayerFromFile() - 99999));
        Assert.GreaterOrEqual(1e-5, Math.Abs(testcs.GetGoldOfPlayerFromFile() - 99999));
        Assert.IsTrue("xx".Equals(testcs.GetTypeOfPlayerFromFile()));
        Assert.GreaterOrEqual(1e-5, Math.Abs(testcs.GetLevelOfGameFromFile() - 99999));

        /// init
        testcs.AttributeInit();
        /// cover
        testcs.SaveAttributeInFile();
        SetCharacter.istest = false;
    }
示例#2
0
    // Use this for initialization
    void Start()
    {
        /*
         * string testString = "\n\n\n";
         * byte[] byteString = Encoding.UTF8.GetBytes (strTest);
         * byte max = 0, min = 0x7f;
         */

        //int temp = 0;
        //Debug.Log (temp++);
        //Debug.Log (++temp);

        /*
         * for (int i = 0; i < testString.Length; i++)
         * {
         *      if (testString [i] == '\n')
         *              testString [i] = '@';
         *      /*
         *      if (byteString [i] < min)
         *              min = byteString [i];
         *      if (byteString [i] == 58)
         *              Debug.Log("Fail");
         *      Debug.Log (byteString [i]);
         */
        //}

        /*
         * for (int i = 0; i < byteString.Length; i++)
         * {
         *      if (byteString [i] > max)
         *              max = byteString [i];
         *      if (byteString [i] < min)
         *              min = byteString [i];
         *      if (byteString [i] == 64)
         *              Debug.Log("Fail");
         *      //Debug.Log (byteString [i]);
         * }
         * Debug.Log ("max:" + max.ToString ());
         * Debug.Log ("min:" + min.ToString ());
         * string str1 = player_attribute.Encrypt (strTest);
         * string str2 = player_attribute.Decrypt (str1);
         * Debug.Log (strTest);
         * Debug.Log (str1);
         * Debug.Log (str2);
         */
        //player_attribute.DecryptDES (player_attribute.EncryptDES (testString, player_attribute.Key), player_attribute.Key);

        //read the attribute of player
        //player_attribute.ReadPlayerAttribute ();


        //player_attribute.SaveAttributeInFile ();
        //if (player_attribute.level_num > 1)

        player_attribute.ReadPlayerAttribute();

        //player_attribute.SaveAttributeInFile ();

        /*
         * if (player_attribute.level_num == 1)
         *      player_attribute.SaveAttributeInFile (1);
         * if (player_attribute.level_num == 2)
         *      player_attribute.SaveAttributeInFile (2);
         * if (player_attribute.level_num == 3)
         *      player_attribute.SaveAttributeInFile (3);
         *
         */
        Debug.Log(player_attribute.level_num);
        GameLevelUI.transform.Find("Text").gameObject.GetComponent <Text>().text = player_attribute.level_num.ToString();

        /*
         *      Debug.Log (player_attribute.GetSaveTimeFromFile ());
         *
         *      Debug.Log (player_attribute.GetLevelOfGameFromFile ().ToString ());
         *      Debug.Log (player_attribute.GetLevelOfPlayerFromFile ().ToString ());
         *      Debug.Log (player_attribute.GetGoldOfPlayerFromFile ().ToString ());
         */
        //Debug.Log(player_attribute.GetAttributeFromFile ("gold"));
        //Debug.Log(player_attribute.GetAttributeFromFile ("Level",0));
        //Debug.Log(player_attribute.GetAttributeFromFile ("level_num"));



        //player_attribute.DecryptDES (player_attribute.EncryptDES ("HP_max", player_attribute.Key), player_attribute.Key);
        Boss.GetComponent <attribute>().Level = player_attribute.level_num;
        Boss.GetComponent <attribute> ().BossUpdate();
        try
        {
            int _charac = PlayerPrefs.GetInt("Character");
            Debug.Log(_charac.ToString() + " 11111 " + player_attribute.ZhiYe);
            if (!(player_attribute.IsInit))
            {
                _charac = player_attribute.ZhiYe == "warrior" ? 0 : 1;
            }
            Debug.Log(_charac.ToString() + " 22222 " + player_attribute.ZhiYe);
            player.GetComponent <attribute>().NiCheng = PlayerPrefs.GetString("player_name") == "" ? "FuWang" : PlayerPrefs.GetString("player_name");

            if (_charac == 1)
            {
                player.transform.Find("axe_armor").gameObject.SetActive(false);
                player.transform.Find("axe_base").gameObject.SetActive(false);
                player.transform.Find("axe_belt").gameObject.SetActive(false);
                player.transform.Find("axe_hair").gameObject.SetActive(false);
                player.transform.Find("root").gameObject.SetActive(false);

                player.transform.Find("crystal_maiden_arms").gameObject.SetActive(true);
                player.transform.Find("crystal_maiden_back").gameObject.SetActive(true);
                player.transform.Find("crystal_maiden_base").gameObject.SetActive(true);
                player.transform.Find("crystal_maiden_head").gameObject.SetActive(true);
                player.transform.Find("crystal_maiden_shoulder").gameObject.SetActive(true);
                player.transform.Find("crystal_maiden_shoulder_bow").gameObject.SetActive(true);
                player.transform.Find("Root_0").gameObject.SetActive(true);

                AvatarIcon.transform.Find("Head").gameObject.SetActive(false);
                AvatarIcon.transform.Find("Head2").gameObject.SetActive(true);

                player.GetComponent <Animator>().avatar = crystal;
                player.transform.Find("Attack_area").gameObject.SetActive(false);
                player.GetComponent <ThirdPersonUserControl>().attack_object = attack_crystal;
                player.GetComponent <attribute>().ZhiYe = "wizard";
                if (player_attribute.IsInit)
                {
                    player.GetComponent <attribute>().ATK       = 70;
                    player.GetComponent <attribute>().DEF       = 10;
                    player.GetComponent <attribute>().ATKGrowth = 6f;
                    player.GetComponent <attribute>().DEFGrowth = 2f;
                    player.GetComponent <attribute>().HPGrowth  = 8f;
                    player.GetComponent <attribute>().FireRate  = 0.8f;
                    player.GetComponent <ThirdPersonCharacter>().m_MoveSpeedMultiplier = 1.5f;
                    player_attribute.AttributeInit();
                    player_attribute.IsInit = false;
                }
            }
            if (_charac == 0)
            {
                player.transform.Find("axe_armor").gameObject.SetActive(true);
                player.transform.Find("axe_base").gameObject.SetActive(true);
                player.transform.Find("axe_belt").gameObject.SetActive(true);
                player.transform.Find("axe_hair").gameObject.SetActive(true);
                player.transform.Find("root").gameObject.SetActive(true);

                player.transform.Find("crystal_maiden_arms").gameObject.SetActive(false);
                player.transform.Find("crystal_maiden_back").gameObject.SetActive(false);
                player.transform.Find("crystal_maiden_base").gameObject.SetActive(false);
                player.transform.Find("crystal_maiden_head").gameObject.SetActive(false);
                player.transform.Find("crystal_maiden_shoulder").gameObject.SetActive(false);
                player.transform.Find("crystal_maiden_shoulder_bow").gameObject.SetActive(false);
                player.transform.Find("Root_0").gameObject.SetActive(false);

                AvatarIcon.transform.Find("Head").gameObject.SetActive(true);
                AvatarIcon.transform.Find("Head2").gameObject.SetActive(false);

                player.GetComponent <Animator>().avatar = axe;
                player.transform.Find("Attack_area").gameObject.SetActive(true);
                player.GetComponent <ThirdPersonUserControl>().attack_object = attack_axe;
                player.GetComponent <attribute>().ZhiYe = "warrior";
                if (player_attribute.IsInit)
                {
                    player.GetComponent <attribute>().ATK       = 45;
                    player.GetComponent <attribute>().DEF       = 35;
                    player.GetComponent <attribute>().ATKGrowth = 5f;
                    player.GetComponent <attribute>().DEFGrowth = 3f;
                    player.GetComponent <attribute>().HPGrowth  = 10f;
                    player.GetComponent <attribute>().FireRate  = 0.6f;
                    player.GetComponent <ThirdPersonCharacter>().m_MoveSpeedMultiplier = 1.5f;
                    player_attribute.AttributeInit();
                    player_attribute.IsInit = false;
                }
            }
            if (PlayerPrefs.GetString("player_name") == "exciting")
            {
                exciting = true;
            }
            if (player_attribute.level_num == 1 && (PlayerPrefs.GetString("player_name") == "fuhong" || PlayerPrefs.GetString("player_name") == "yehao" || PlayerPrefs.GetString("player_name") == "hongjie" || PlayerPrefs.GetString("player_name") == "zhiyuan" || PlayerPrefs.GetString("player_name") == "sicheng"))
            {
                player.GetComponent <attribute>().update_EXP(60 * player.GetComponent <attribute>().EXPForLevelUp);
                player.GetComponent <attribute>().update_gold(99999f);
            }
        }
        catch { }

        quad1.transform.position = new Vector3(0f, 0.02f, map_scale_z / 2);
        quad2.transform.position = new Vector3(map_scale_x / 2, 0.02f, 0f);
        quad3.transform.position = new Vector3(map_scale_x - 0f, 0.02f, map_scale_z / 2);
        quad4.transform.position = new Vector3(map_scale_x / 2, 0.02f, map_scale_z - 0f);

        quad1.transform.localScale = new Vector3(0f, map_scale_z, 1f);
        quad2.transform.localScale = new Vector3(0f, map_scale_x, 1f);
        quad3.transform.localScale = new Vector3(0f, map_scale_z, 1f);
        quad4.transform.localScale = new Vector3(0f, map_scale_x, 1f);
    }