Exemplo n.º 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;
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (player.transform.position.x < 2 * quad1.transform.position.x ||
            player.transform.position.x > 2 * quad3.transform.position.x - map_scale_x ||
            player.transform.position.z < 2 * quad2.transform.position.z ||
            player.transform.position.z > 2 * quad4.transform.position.z - map_scale_z)
        {
            player.GetComponent <ThirdPersonUserControl>().StateIcon.transform.Find("Unsafe").gameObject.GetComponent <Image>().fillAmount = 1.0f;
            player.GetComponent <attribute>().update_HP(-DamagePerSecond * Time.deltaTime);
        }
        else
        {
            player.GetComponent <ThirdPersonUserControl>().StateIcon.transform.Find("Unsafe").gameObject.GetComponent <Image>().fillAmount = 0.0f;
        }
        if (exciting && player.GetComponent <attribute>().ifAlive)
        {
            player.GetComponent <ThirdPersonUserControl>().StateIcon.transform.Find("exciting").gameObject.GetComponent <Image>().fillAmount = 1.0f;
            player.GetComponent <attribute>().update_HP(1f * Time.deltaTime);
        }
        else
        {
            player.GetComponent <ThirdPersonUserControl>().StateIcon.transform.Find("exciting").gameObject.GetComponent <Image>().fillAmount = 0.0f;
        }
        if (WinFlag)
        {
            return;
        }

        if ((Boss.transform.position - player.transform.position).sqrMagnitude < 10000 && !WinFlag)
        {
            Boss_Slider.SetActive(true);
        }
        else
        {
            Boss_Slider.SetActive(false);
        }
        Boss.transform.Rotate(0, 0, 26 * Time.fixedDeltaTime);
        //Boss.transform.Find("Boss Partical").Rotate(0,0, 20 * Time.fixedDeltaTime);
        // Boss.transform.Find("Particle System").Rotate()



        if (timer > 0)
        {
            timer -= Time.fixedDeltaTime;
        }
        if (boss_transition_timer > 0)
        {
            boss_transition_timer -= Time.fixedDeltaTime;
            if (boss_transition_timer > 3)
            {
                Boss.transform.Find("Boss Partical").gameObject.SetActive(false);
                Boss.GetComponent <Collider>().enabled = false;
                Boss.GetComponent <MeshRenderer>().materials[0].color =
                    Color.Lerp(Boss.GetComponent <MeshRenderer>().material.color, new Color(Boss.GetComponent <MeshRenderer>().material.color.r, Boss.GetComponent <MeshRenderer>().material.color.g, Boss.GetComponent <MeshRenderer>().material.color.b, 0f), Time.fixedDeltaTime);
            }
            if (boss_transition_timer < 3)
            {
                //Boss.transform.position = SafeCenter + new Vector3(0f, 3.9f, 0f);
                if (!while_is_busy)
                {
                    while_is_busy = true;
                    Vector3 t = new Vector3(SafeCenter.x, 3.9f, SafeCenter.z);
                    while (gameobject_generate.IsCoincide(new GameObjectGenerate.GameObjectNode(t.x, t.y, t.z, boss_length, boss_width, 0)))
                    {
                        t = t + new Vector3(UnityEngine.Random.Range(-12f * boss_length, 12f * boss_length), 0, UnityEngine.Random.Range(-12f * boss_width, 12f * boss_width));
                    }
                    Boss.transform.position = t;
                }



                Boss.GetComponent <MeshRenderer>().materials[0].color =
                    Color.Lerp(Boss.GetComponent <MeshRenderer>().material.color, new Color(Boss.GetComponent <MeshRenderer>().material.color.r, Boss.GetComponent <MeshRenderer>().material.color.g, Boss.GetComponent <MeshRenderer>().material.color.b, 1f), Time.fixedDeltaTime);
            }
            if (boss_transition_timer < 0)
            {
                while_is_busy = false;
                Boss.transform.Find("Boss Partical").gameObject.SetActive(true);
                Boss.GetComponent <Collider>().enabled = true;
            }
        }
        if (Boss.GetComponent <attribute>().ifAlive == false)
        {
            WinFlag      = true;
            ui_text.text = "You Win";
            Boss_Slider.SetActive(false);
            //Boss.transform.Find("Boss Partical").gameObject.SetActive(false);
            //Boss.transform.Find("Died Partical").gameObject.SetActive(true);
            //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);

            player.GetComponent <attribute>().update_HP(player.GetComponent <attribute>().HP_max);
            //player_attribute.SavePlayerAttribute();
            player_attribute.SaveAttributeInFile();
            shop.transform.position = Boss.transform.position;
            shop.SetActive(true);
            GameLevelUI.transform.Find("Text").gameObject.GetComponent <Text>().text = (player_attribute.level_num + 1).ToString();
            //event when success

            //player_attribute.SavePlayerAttribute();

            return;
        }

        else
        {
            if (timer <= 0)
            {
                if (!IsWaiting)
                {
                    rounds++;
                    SafeCenter = new Vector3(UnityEngine.Random.Range(2 * quad1.transform.position.x, 2 * quad3.transform.position.x - map_scale_x),
                                             0,
                                             UnityEngine.Random.Range(2 * quad2.transform.position.z, 2 * quad4.transform.position.z - map_scale_z));
                    SafeScale *= 2;
                    float _totalframes = (Base_transfer_time + Additional_transfer_time / rounds) / Time.deltaTime;
                    DeltaQuad1 = (SafeCenter.x - 2 * quad1.transform.position.x) / _totalframes / scale_factor;
                    DeltaQuad2 = (SafeCenter.z - 2 * quad2.transform.position.z) / _totalframes / scale_factor;
                    DeltaQuad3 = (2 * quad3.transform.position.x - map_scale_x - SafeCenter.x) / _totalframes / scale_factor;
                    DeltaQuad4 = (2 * quad4.transform.position.z - map_scale_z - SafeCenter.z) / _totalframes / scale_factor;
                    timer      = Base_wait_time + Additional_wait_time / rounds;
                    Timer_max  = Base_wait_time + Additional_wait_time / rounds;
                    IsWaiting  = true;
                    TimerUI.transform.Find("StateBackground").gameObject.GetComponent <Image>().sprite = TimerUI_blue;
                    TimerUI.transform.Find("State").gameObject.GetComponent <Text>().text = "WAITING";
                    // Transition of Boss
                    boss_transition_timer = 6f;
                }
                else
                {
                    timer     = (Base_transfer_time + Additional_transfer_time / rounds);
                    Timer_max = (Base_transfer_time + Additional_transfer_time / rounds);
                    IsWaiting = false;
                    TimerUI.transform.Find("StateBackground").gameObject.GetComponent <Image>().sprite = TimerUI_red;
                    TimerUI.transform.Find("State").gameObject.GetComponent <Text>().text = "REDUCING";
                }
            }
            // TBD: else here?

            TimerUI.GetComponent <Slider>().value = timer / Timer_max;
            TimerUI.transform.Find("Fill Area").Find("Fill").gameObject.GetComponent <Image>().color = new Color(1 - timer / Timer_max, timer / Timer_max, 0);
            TimerUI.transform.Find("Handle Slide Area").Find("Handle").Find("Time").gameObject.GetComponent <Text>().text = ((int)timer + 1).ToString();
            if (!IsWaiting)
            {
                quad1.transform.position = quad1.transform.position + new Vector3(DeltaQuad1 / 2, 0f, 0f);
                quad2.transform.position = quad2.transform.position + new Vector3(0f, 0f, DeltaQuad2 / 2);
                quad3.transform.position = quad3.transform.position + new Vector3(-DeltaQuad3 / 2, 0f, 0f);
                quad4.transform.position = quad4.transform.position + new Vector3(0f, 0f, -DeltaQuad4 / 2);

                quad1.transform.localScale = quad1.transform.localScale + new Vector3(DeltaQuad1, 0f, 0f);
                quad2.transform.localScale = quad2.transform.localScale + new Vector3(DeltaQuad2, 0f, 0f);
                quad3.transform.localScale = quad3.transform.localScale + new Vector3(DeltaQuad3, 0f, 0f);
                quad4.transform.localScale = quad4.transform.localScale + new Vector3(DeltaQuad4, 0f, 0f);
            }
        }
    }