예제 #1
0
    void WupengStateupdate()
    {
        switch (wupengcurrentState)
        {
        case WupengState.WupengState_eat:
        {
            currentTime += Time.deltaTime;
            if (currentTime > 3.0f)
            {
                Wupeng.Energy      = 100.0f;
                wupengcurrentState = WupengState.WupengState_hit;
                currentTime        = 0.0f;
                Debug.Log("wupeng开始打豆豆啦");
            }
        }
        break;

        case WupengState.WupengState_hit:
        {
            currentTime += Time.deltaTime;
            if (currentTime > 10.0f)
            {
                Wupeng.Energy      = 0.0f;
                wupengcurrentState = WupengState.WupengState_sleep;
                currentTime        = 0.0f;
                Debug.Log("wupeng开始睡觉啦");
            }
        }
        break;

        case WupengState.WupengState_sleep:
        {
            currentTime += Time.deltaTime;

            if (currentTime > 5.0f)
            {
                ZZStateupdate();
                wupengcurrentState = WupengState.WupengState_eat;
                currentTime        = 0.0f;
                Debug.Log("wupeng开始吃饭啦");
            }
        }
        break;
        }
    }
예제 #2
0
    void PrintQuestion1to7()
    {
        switch (currentWupengState)

        {
        case WupengState.WupengState_Eating:
        {
            wupeng.Energy       = 0;
            wupeng.currentTime += Time.deltaTime;
            //在wupeng不睡觉的时候敲鼓,mengmeng每秒钟可敲4下鼓,
            //当敲第偶数下鼓的时候,能让wupeng的攻击力加成,加成效果在wupeng睡觉的时候消失。将mengmeng的功能嵌入第3题的状态机中。
            mengmeng.currentTime += Time.deltaTime;
            int countSecondsofMengmeng = 0;
            if (mengmeng.currentTime > 0.0f)
            {
                countSecondsofMengmeng++;
                if (countSecondsofMengmeng % 2 == 0)
                {
                    wupeng.Attack += mengmeng.AddAttack;
                }
            }


            if (wupeng.currentTime > 3.0f)
            {
                currentWupengState = WupengState.WupengState_Hitting;
                wupeng.currentTime = 0.0f;
                Debug.Log("Wupeng begin to hit doudou");
            }
        }
        break;

        case WupengState.WupengState_Hitting:
        {
            wupeng.Energy = 100 + 2 * mengmeng.AddAttack;                            //前面状态机里的加成要怎么加在第二个状态机的初始值里呢?我用自己算的加上了
            doudou.Life   = 1000;
            //mengmeng在这里加成攻击
            mengmeng.currentTime += Time.deltaTime;
            int countSecondsofMengmeng = 0;
            if (mengmeng.currentTime > 0.0f)
            {
                countSecondsofMengmeng++;
                if (countSecondsofMengmeng % 2 == 0)
                {
                    wupeng.Attack += mengmeng.AddAttack;
                }
            }

            int countSecondsofwupeng = 0;
            if (wupeng.currentTime > 3.0f && wupeng.Energy > 0 && doudou.Life > 0)
            {
                countSecondsofwupeng++;
                doudou.Life   -= wupeng.Attack * countSecondsofwupeng;
                wupeng.Energy -= 10 * countSecondsofwupeng;
            }

            if (wupeng.Energy <= 0)
            {
                currentWupengState = WupengState.WupengState_Sleeping;
                wupeng.currentTime = 0.0f;
                Debug.Log("Wupeng begin to sleep");
            }
        }
        break;

        case WupengState.WupengState_Sleeping:
            //5.Zz会在wupeng睡觉的时候为豆豆补充生命,zz为豆豆补充血量时的过程是这样的:
            //准备医疗工具1秒,为豆豆补血2秒,拆除医疗工具1秒。
            //请使用状态机实现此过程(将代码嵌入第3题的状态机中)
        {
            switch (currentZzState)
            //在zz准备工具和治疗的时候为zz加油,wuwu每秒钟能喊出3次加油,每次都能让zz回复能力加成
            //加成效果在zz治疗结束后消失 。将wuwu的功能嵌入第3题的状态机中。
            {
            case ZzState.ZzState_prepare:
            {
                zz.currentTime += Time.deltaTime;
                if (zz.currentTime > 1.0f)
                {
                    currentZzState = ZzState.ZzState_healing;
                    zz.currentTime = 0.0f;
                    Debug.Log("zz is adding blood");
                }
            }
            break;

            case ZzState.ZzState_healing:
            {
                zz.currentTime += Time.deltaTime;
                int counssecondsofZZ = 0;
                if (zz.currentTime > 0.0f)
                {
                    counssecondsofZZ++;
                    doudou.Life += (3 * wuwu.Cureplus + zz.CureLife) * counssecondsofZZ;
                }

                if (zz.currentTime > 2.0f)
                {
                    currentZzState = ZzState.ZzState_remove;
                    zz.currentTime = 0.0f;
                    Debug.Log("zz is removing tools");
                }
            }
            break;

            case ZzState.ZzState_remove:
            {
                if (zz.currentTime > 1.0f)
                {
                    currentZzState = ZzState.ZzState_prepare;
                    zz.currentTime = 0.0f;
                    Debug.Log("zz is preparing");
                }
            }
            break;
            }


            if (wupeng.currentTime > 5.0f)
            {
                currentWupengState = WupengState.WupengState_Eating;
                Debug.Log("Wupeng begin to eat");
            }
        }

        break;
        }
    }