Example #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);
    }
Example #2
0
    public override void LoadFSM()
    {
        BaseFSM.FSM <StatesID> subFsm = new BaseFSM.FSM <StatesID>("Sub");
        subFsm.OnFinish += (x, y) => { System.Console.WriteLine("*** subFSM onFinish()"); };

        SetSubFSM(subFsm);

        StableState stateSubOne = new StableState(StatesID.SUB_ONE)
        {
            isStart = true
        };

        stateSubOne.AddAction("DoSubA", (o) => true, (o) => System.Console.WriteLine("sub action a"))
        .AddExitTransition(subFsm, StatesID.SUB_TWO);

        SwitchState stateSubTwo = new SwitchState(StatesID.SUB_TWO)
        {
            isFinish = true
        };

        subFsm.AddState(stateSubTwo);
    }