Beispiel #1
0
        public void ThrowsExceptionOnDuplicateStateAdded()
        {
            Game    game             = new Game();
            StateA  stateA           = new StateA();
            StateA1 stateA1          = new StateA1();
            StateA2 stateA2          = new StateA2();
            StateB  stateB           = new StateB();
            StateB1 stateB1          = new StateB1();
            StateB2 stateB2          = new StateB2();
            StateB2 stateB2Duplicate = new StateB2();

            Assert.Throws <DuplicateSubStateException>(() => {
                game.LoadSubState(stateA);
                game.LoadSubState(stateB);
                stateA.LoadSubState(stateA1);
                stateB.LoadSubState(stateB1);
                stateA1.LoadSubState(stateA2);
                stateB1.LoadSubState(stateB2);
                stateB1.LoadSubState(stateB2Duplicate);
            });
        }
Beispiel #2
0
        public void TransitionTriggerFromSubState()
        {
            Game    game    = new Game();
            StateA  stateA  = new StateA();
            StateA1 stateA1 = new StateA1();
            StateA2 stateA2 = new StateA2();
            StateB  stateB  = new StateB();
            StateB1 stateB1 = new StateB1();
            StateB2 stateB2 = new StateB2();

            int AtoB = 1;

            game.LoadSubState(stateA);
            game.LoadSubState(stateB);
            stateA.LoadSubState(stateA1);
            stateB.LoadSubState(stateB1);
            stateA1.LoadSubState(stateA2);
            stateB1.LoadSubState(stateB2);

            game.AddTransition(stateA, stateB, AtoB);

            game.EnterStateMachine();
            stateA2.SendTrigger(AtoB);

            Assert.AreEqual(10, callChain.Count);
            Assert.AreEqual("game_enter", callChain[0]);
            Assert.AreEqual("stateA_enter", callChain[1]);
            Assert.AreEqual("stateA1_enter", callChain[2]);
            Assert.AreEqual("stateA2_enter", callChain[3]);
            Assert.AreEqual("stateA2_exit", callChain[4]);
            Assert.AreEqual("stateA1_exit", callChain[5]);
            Assert.AreEqual("stateA_exit", callChain[6]);
            Assert.AreEqual("stateB_enter", callChain[7]);
            Assert.AreEqual("stateB1_enter", callChain[8]);
            Assert.AreEqual("stateB2_enter", callChain[9]);
        }