Esempio n. 1
0
        public void FSM_Test()
        {
            //        Idle,               闲置
            //        Run,                跑
            //        Jump,               一段跳
            //        DoubleJump,         二段跳
            //        Die,                挂彩
            var fsm = new QFSMLite();

            // 创建状态
            var idleState       = "idle";
            var runState        = "run";
            var jumpState       = "jump";
            var doubleJumpState = "double_jump";
            var dieState        = "die";

            fsm.AddState(idleState);
            fsm.AddState(runState);
            fsm.AddState(jumpState);
            fsm.AddState(doubleJumpState);
            fsm.AddState(dieState);

            // 创建跳转
            var jumpCalled       = false;
            var doubleJumpCalled = false;
            var runCalledCount   = 0;

            // 添加跳转

            fsm.AddTranslation(runState, "touch_down", jumpState, (_) => { jumpCalled = true; });
            fsm.AddTranslation(jumpState, "touch_down", doubleJumpState, (_) => { doubleJumpCalled = true; });

            fsm.AddTranslation(jumpState, "land", runState, (_) => { runCalledCount++; });

            fsm.AddTranslation(doubleJumpState, "land", runState, (_) => { runCalledCount++; });

            // 初识状态是 runState
            fsm.Start(runState);

            Assert.AreSame(fsm.State, runState);

            // 点击屏幕,进行跳跃
            fsm.HandleEvent("touch_down");

            Assert.IsTrue(jumpCalled);
            Assert.AreSame(fsm.State, jumpState);

            // 点击屏幕,二段跳
            fsm.HandleEvent("touch_down");

            Assert.IsTrue(doubleJumpCalled);
            Assert.AreSame(fsm.State, doubleJumpState);

            // 着陆
            fsm.HandleEvent("land");

            Assert.AreEqual(runCalledCount, 1);
            Assert.AreSame(fsm.State, runState);
        }
Esempio n. 2
0
        public void FSMLiteTest_AddTranslation()
        {
            string str1 = "work->rest true";
            string str2 = "work->rest false";

            mFSMLite.AddState("work");
            mFSMLite.AddState("rest");

            mFSMLite.AddTranslation("work", "work->rest", "rest", delegate {
                str2 = "work->rest true";
            });

            mFSMLite.Start("work");

            mFSMLite.HandleEvent("work->rest");

            Assert.IsNotNull(mFSMLite);
            Assert.AreEqual(str1, str2);
        }
Esempio n. 3
0
 public void Perform(EagleFSMEvent eagleFSMEvent)
 {
     mEagleFSMLite.HandleEvent(eagleFSMEvent.ToString());
 }