Ejemplo n.º 1
0
    static void Main(string[] args)
    {
        BaseFSM.FSM <StatesID> fsm = new BaseFSM.FSM <StatesID>("Main");

        /*************/

        //Main
        SwitchState stateOne = new SwitchState(StatesID.ONE)
        {
            isStart = true
        };

        stateOne.DefaultExit()
        .AddExitTransition(fsm, StatesID.FOUR);
        stateOne.AddTestExit(() => condition)
        .AddExitTransition(fsm, StatesID.TWO);

        SwitchState stateTwo = new SwitchState(StatesID.TWO);

        stateTwo.DefaultExit()
        .AddExitTransition(fsm, StatesID.FOUR);
        stateTwo.AddTestExit(() => condition)
        .AddExitTransition(fsm, StatesID.THREE);

        StableState stateThree = new StableState(StatesID.THREE);

        stateThree.AddAction("DoA", (o) => !condition, (o) => System.Console.WriteLine("action a"))
        .AddExitTransition(fsm, StatesID.ONE);
        stateThree.AddAction("DoB", (o) => condition, (o) => System.Console.WriteLine("action b"))
        .AddExitTransition(fsm, StatesID.FOUR);

        StateWithFSM stateFour = new StateWithFSM(StatesID.FOUR);

        stateFour.SubFSMExit()
        .AddExitTransition(fsm, StatesID.THREE);

        /////////////

        BaseFSM.Cursor <StatesID> cursor = fsm.GetCursor();
        System.Console.WriteLine(cursor);

        fsm.Start();
        System.Console.WriteLine(cursor);

        if (cursor.curState.id == StatesID.THREE)
        {
            cursor.DoAction("DoA");
        }
        System.Console.WriteLine(cursor);

        if (cursor.curState.id == StatesID.SUB_ONE)
        {
            cursor.DoAction("DoSubA");
        }
        System.Console.WriteLine(cursor);
    }
Ejemplo n.º 2
0
 public override void Enter()
 {
     LoadFSM();
     subFsm.Start();
 }